File tree 1 file changed +13
-5
lines changed
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,18 @@ local MSP_SET_RTC = 246
3
3
local MSP_TX_INFO = 186
4
4
5
5
local lastRunTS
6
+ local sensorId = - 1
6
7
local timeIsSet = false
7
8
local mspMsgQueued = false
8
9
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 )
12
18
return type (sensorValue ) == " number" and sensorValue > 0
13
19
end
14
20
@@ -24,7 +30,9 @@ local function run_bg()
24
30
-- ------------------------------------
25
31
-- SYNC DATE AND TIME
26
32
-- ------------------------------------
27
- if not timeIsSet and modelActive () then
33
+ local sensorValue = getSensorValue ()
34
+
35
+ if not timeIsSet and modelActive (sensorValue ) then
28
36
-- Send datetime when the telemetry connection is available
29
37
-- assuming when sensor value higher than 0 there is an telemetry connection
30
38
-- only send datetime one time after telemetry connection became available
@@ -47,7 +55,7 @@ local function run_bg()
47
55
mspMsgQueued = true
48
56
49
57
timeIsSet = true
50
- elseif not modelActive () then
58
+ elseif not modelActive (sensorValue ) then
51
59
timeIsSet = false
52
60
end
53
61
You can’t perform that action at this time.
0 commit comments