Skip to content

Commit 54d5898

Browse files
authored
Merge pull request #54 from betaflight/fix_time_sending_after_reboot
Fixed sending of time after flight controller reboot.
2 parents 2375ad8 + a72b136 commit 54d5898

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

common/background.lua

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local MSP_TX_INFO = 186
77
local sensorName = "Tmp1" -- T1 is never 0 in Betaflight
88

99
local lastRunTS
10-
local oldSensorValue
10+
local timeIsSet = false
1111
local sensorId
1212
local mspMsgQueued = false
1313

@@ -22,7 +22,6 @@ end
2222

2323
local function init()
2424
sensorId = getTelemetryId(sensorName)
25-
oldSensorValue = 0
2625
lastRunTS = 0
2726
end
2827

@@ -39,32 +38,31 @@ local function run_bg()
3938
-- get sensor value
4039
local newSensorValue = getValue(sensorId)
4140

42-
if type(newSensorValue) == "number" then
43-
41+
if not timeIsSet and type(newSensorValue) == "number" and newSensorValue > 0 then
4442
-- Send datetime when the telemetry connection is available
4543
-- assuming when sensor value higher than 0 there is an telemetry connection
4644
-- only send datetime one time after telemetry connection became available
4745
-- or when connection is restored after e.g. lipo refresh
48-
if oldSensorValue == 0 and newSensorValue > 0 then
49-
local now = getDateTime()
50-
local year = now.year;
51-
52-
values = {}
53-
values[1] = bit32.band(year, 0xFF)
54-
year = bit32.rshift(year, 8)
55-
values[2] = bit32.band(year, 0xFF)
56-
values[3] = now.mon
57-
values[4] = now.day
58-
values[5] = now.hour
59-
values[6] = now.min
60-
values[7] = now.sec
61-
62-
-- send msp message
63-
mspSendRequest(MSP_SET_RTC, values)
64-
mspMsgQueued = true
65-
end
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+
59+
-- send msp message
60+
mspSendRequest(MSP_SET_RTC, values)
61+
mspMsgQueued = true
6662

67-
oldSensorValue = newSensorValue
63+
timeIsSet = true
64+
else
65+
timeIsSet = false
6866
end
6967

7068

@@ -74,7 +72,8 @@ local function run_bg()
7472

7573
if mspMsgQueued == false then
7674
local rssi, alarm_low, alarm_crit = getRSSI()
77-
rssi = rssi * 3 -- scaling of [0, 85] (empirical) DBm value to [0, 255]
75+
-- Scale the [0, 85] (empirical) RSSI values to [0, 255]
76+
rssi = rssi * 3
7877
if rssi > 255 then
7978
rssi = 255
8079
end

0 commit comments

Comments
 (0)