Skip to content

Commit dd80021

Browse files
authored
Merge pull request #159 from mikeller/change_rtc_setting_to_ticks
Change setting of RTC to use ticks.
2 parents ab2ca8f + c463f69 commit dd80021

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/SCRIPTS/BF/background.lua

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,35 @@ local function run_bg()
4040
-- assuming when sensor value higher than 0 there is an telemetry connection
4141
-- only send datetime one time after telemetry connection became available
4242
-- or when connection is restored after e.g. lipo refresh
43-
local now = getDateTime()
44-
local year = now.year;
4543

46-
values = {}
47-
values[1] = bit32.band(year, 0xFF)
48-
year = bit32.rshift(year, 8)
49-
values[2] = bit32.band(year, 0xFF)
50-
values[3] = now.mon
51-
values[4] = now.day
52-
values[5] = now.hour
53-
values[6] = now.min
54-
values[7] = now.sec
44+
if API_VERSION < 1.041 then
45+
-- format: year (16) / month (8) / day (8) / hour (8) / min (8) / sec (8)
46+
local now = getDateTime()
47+
local year = now.year;
48+
49+
values = {}
50+
values[1] = bit32.band(year, 0xFF)
51+
year = bit32.rshift(year, 8)
52+
values[2] = bit32.band(year, 0xFF)
53+
values[3] = now.mon
54+
values[4] = now.day
55+
values[5] = now.hour
56+
values[6] = now.min
57+
values[7] = now.sec
58+
else
59+
-- format: seconds after the epoch (32) / milliseconds (16)
60+
local now = getRtcTime()
61+
62+
values = {}
63+
64+
for i = 1, 4 do
65+
values[i] = bit32.band(now, 0xFF)
66+
now = bit32.rshift(now, 8)
67+
end
68+
69+
values[5] = 0 -- we don't have milliseconds
70+
values[6] = 0
71+
end
5572

5673
-- send msp message
5774
protocol.mspWrite(MSP_SET_RTC, values)

src/SCRIPTS/TELEMETRY/bf.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
SCRIPT_HOME = "/SCRIPTS/BF"
22

3+
-- Change this to match the API version of the firmware you are using
4+
-- (you can have multiple copies of this script with different values
5+
-- for API_VERSION, and select different versions for different models
6+
-- on your TX)
7+
-- Version mapping:
8+
-- 1.041: Betaflight 4.0 and newer
9+
-- <1.041: Betaflight 3.5 and older
10+
API_VERSION = 1.040
11+
312
protocol = assert(loadScript(SCRIPT_HOME.."/protocols.lua"))()
413
radio = assert(loadScript(SCRIPT_HOME.."/radios.lua"))()
514

0 commit comments

Comments
 (0)