File tree Expand file tree Collapse file tree 2 files changed +37
-11
lines changed Expand file tree Collapse file tree 2 files changed +37
-11
lines changed Original file line number Diff line number Diff line change @@ -40,18 +40,35 @@ local function run_bg()
40
40
-- assuming when sensor value higher than 0 there is an telemetry connection
41
41
-- only send datetime one time after telemetry connection became available
42
42
-- or when connection is restored after e.g. lipo refresh
43
- local now = getDateTime ()
44
- local year = now .year ;
45
43
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
55
72
56
73
-- send msp message
57
74
protocol .mspWrite (MSP_SET_RTC , values )
Original file line number Diff line number Diff line change 1
1
SCRIPT_HOME = " /SCRIPTS/BF"
2
2
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
+
3
12
protocol = assert (loadScript (SCRIPT_HOME .. " /protocols.lua" ))()
4
13
radio = assert (loadScript (SCRIPT_HOME .. " /radios.lua" ))()
5
14
You can’t perform that action at this time.
0 commit comments