Skip to content

Commit fba4e6d

Browse files
committed
Made version configurable in main script.
1 parent c4a891a commit fba4e6d

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

src/SCRIPTS/BF/background.lua

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,33 @@ local function run_bg()
4141
-- only send datetime one time after telemetry connection became available
4242
-- or when connection is restored after e.g. lipo refresh
4343

44-
--[[ Uncomment for firmware versions before 4.0:
45-
local now = getDateTime()
46-
local year = now.year;
47-
48-
values = {}
49-
values[1] = bit32.band(year, 0xFF)
50-
year = bit32.rshift(year, 8)
51-
values[2] = bit32.band(year, 0xFF)
52-
values[3] = now.mon
53-
values[4] = now.day
54-
values[5] = now.hour
55-
values[6] = now.min
56-
values[7] = now.sec
57-
]]
58-
59-
--[[ Uncomment for firmware versions 4.0 and up:]]
60-
local now = getRtcTime()
61-
62-
values = {}
63-
values[1] = bit32.band(now, 0xFF)
64-
now = bit32.rshift(now, 8)
65-
values[2] = bit32.band(now, 0xFF)
66-
now = bit32.rshift(now, 8)
67-
values[3] = bit32.band(now, 0xFF)
68-
now = bit32.rshift(now, 8)
69-
values[4] = bit32.band(now, 0xFF)
70-
values[5] = 0 -- we don't have milliseconds
71-
values[6] = 0
44+
if API_VERSION < 1.041 then
45+
local now = getDateTime()
46+
local year = now.year;
47+
48+
values = {}
49+
values[1] = bit32.band(year, 0xFF)
50+
year = bit32.rshift(year, 8)
51+
values[2] = bit32.band(year, 0xFF)
52+
values[3] = now.mon
53+
values[4] = now.day
54+
values[5] = now.hour
55+
values[6] = now.min
56+
values[7] = now.sec
57+
else
58+
local now = getRtcTime()
59+
60+
values = {}
61+
values[1] = bit32.band(now, 0xFF)
62+
now = bit32.rshift(now, 8)
63+
values[2] = bit32.band(now, 0xFF)
64+
now = bit32.rshift(now, 8)
65+
values[3] = bit32.band(now, 0xFF)
66+
now = bit32.rshift(now, 8)
67+
values[4] = bit32.band(now, 0xFF)
68+
values[5] = 0 -- we don't have milliseconds
69+
values[6] = 0
70+
end
7271

7372
-- send msp message
7473
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.041
11+
312
protocol = assert(loadScript(SCRIPT_HOME.."/protocols.lua"))()
413
radio = assert(loadScript(SCRIPT_HOME.."/radios.lua"))()
514

0 commit comments

Comments
 (0)