Skip to content

Commit 7cf8fbf

Browse files
committed
Reverted time synchronisation to previous working implementation.
1 parent 07a280b commit 7cf8fbf

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/SCRIPTS/BF/background.lua

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ local MSP_SET_RTC = 246
33
local MSP_TX_INFO = 186
44

55
local lastRunTS
6+
local sensorId = -1
67
local timeIsSet = false
78
local mspMsgQueued = false
89

9-
local function modelActive()
10-
local telemId = (getFieldInfo(protocol.stateSensor)['id'] or -1)
11-
local sensorValue = getValue(telemId)
10+
local function getSensorValue()
11+
if sensorId == -1 then
12+
sensorId = getFieldInfo(protocol.stateSensor)['id'] or -1
13+
end
14+
return getValue(sensorId)
15+
end
16+
17+
local function modelActive(sensorValue)
1218
return type(sensorValue) == "number" and sensorValue > 0
1319
end
1420

@@ -24,7 +30,9 @@ local function run_bg()
2430
-- ------------------------------------
2531
-- SYNC DATE AND TIME
2632
-- ------------------------------------
27-
if not timeIsSet and modelActive() then
33+
local sensorValue = getSensorValue()
34+
35+
if not timeIsSet and modelActive(sensorValue) then
2836
-- Send datetime when the telemetry connection is available
2937
-- assuming when sensor value higher than 0 there is an telemetry connection
3038
-- only send datetime one time after telemetry connection became available
@@ -47,7 +55,7 @@ local function run_bg()
4755
mspMsgQueued = true
4856

4957
timeIsSet = true
50-
elseif not modelActive() then
58+
elseif not modelActive(sensorValue) then
5159
timeIsSet = false
5260
end
5361

0 commit comments

Comments
 (0)