|
1 | | --- load msp.lua |
2 | | -assert(loadScript("/SCRIPTS/BF/msp_sp.lua"))() |
3 | | - |
4 | 1 | SetupPages = { |
5 | 2 | { |
6 | 3 | title = "PIDs", |
@@ -72,103 +69,7 @@ MenuBox = { x=1, y=10, w=100, x_offset=36, h_line=10, h_offset=3 } |
72 | 69 | SaveBox = { x=20, y=12, w=100, x_offset=4, h=30, h_offset=5 } |
73 | 70 | NoTelem = { 36, 55, "No Telemetry", BLINK } |
74 | 71 |
|
75 | | --- --------------------------------------- |
76 | | --- BACKGROUND PROCESS |
77 | | --- --------------------------------------- |
78 | | - |
79 | | -local INTERVAL = 100 -- 100 = 1 second, 200 = 2 seconds, ... |
80 | | -local MSP_SET_RTC = 246 |
81 | | -local MSP_TX_INFO = 186 |
82 | | -local sensorName = "Tmp1" -- T1 is never 0 in Betaflight |
83 | | - |
84 | | -local lastRunTS |
85 | | -local oldSensorValue |
86 | | -local sensorId |
87 | | -local mspMsgQueued = false |
88 | | - |
89 | | -local function getTelemetryId(name) |
90 | | - local field = getFieldInfo(name) |
91 | | - if field then |
92 | | - return field['id'] |
93 | | - else |
94 | | - return -1 |
95 | | - end |
96 | | -end |
97 | | - |
98 | | -local function init() |
99 | | - sensorId = getTelemetryId(sensorName) |
100 | | - oldSensorValue = 0 |
101 | | - lastRunTS = 0 |
102 | | -end |
103 | | - |
104 | | -local function run_bg() |
105 | | - |
106 | | - -- run in intervals |
107 | | - if lastRunTS == 0 or lastRunTS + INTERVAL < getTime() then |
108 | | - |
109 | | - mspMsgQueued = false |
110 | | - |
111 | | - -- ------------------------------------ |
112 | | - -- SYNC DATE AND TIME |
113 | | - -- ------------------------------------ |
114 | | - |
115 | | - -- get sensor value |
116 | | - local newSensorValue = getValue(sensorId) |
117 | | - |
118 | | - if type(newSensorValue) == "number" then |
119 | | - |
120 | | - -- Send datetime when the telemetry connection is available |
121 | | - -- assuming when sensor value higher than 0 there is an telemetry connection |
122 | | - -- only send datetime one time after telemetry connection became available |
123 | | - -- or when connection is restored after e.g. lipo refresh |
124 | | - if oldSensorValue == 0 and newSensorValue > 0 then |
125 | | - local now = getDateTime() |
126 | | - local year = now.year; |
127 | | - |
128 | | - values = {} |
129 | | - values[1] = bit32.band(year, 0xFF) |
130 | | - year = bit32.rshift(year, 8) |
131 | | - values[2] = bit32.band(year, 0xFF) |
132 | | - values[3] = now.mon |
133 | | - values[4] = now.day |
134 | | - values[5] = now.hour |
135 | | - values[6] = now.min |
136 | | - values[7] = now.sec |
137 | | - |
138 | | - -- send msp message |
139 | | - mspSendRequest(MSP_SET_RTC, values) |
140 | | - mspMsgQueued = true |
141 | | - end |
142 | | - |
143 | | - oldSensorValue = newSensorValue |
144 | | - end |
145 | | - |
146 | | - |
147 | | - -- ------------------------------------ |
148 | | - -- SEND RSSI VALUE |
149 | | - -- ------------------------------------ |
150 | | - |
151 | | - if mspMsgQueued == false then |
152 | | - local rssi, alarm_low, alarm_crit = getRSSI() |
153 | | - values = {} |
154 | | - values[1] = rssi |
155 | | - |
156 | | - -- send msp message |
157 | | - mspSendRequest(MSP_TX_INFO, values) |
158 | | - mspMsgQueued = true |
159 | | - end |
160 | | - |
161 | | - lastRunTS = getTime() |
162 | | - end |
163 | | - |
164 | | - -- process queue |
165 | | - mspProcessTxQ() |
166 | | - |
167 | | -end |
168 | | - |
169 | | --- |
170 | | --- END |
171 | | --- |
172 | | - |
173 | 72 | local run_ui = assert(loadScript("/SCRIPTS/BF/ui.lua"))() |
174 | | -return { init=init, run=run_ui, background=run_bg } |
| 73 | +local background = assert(loadScript("/SCRIPTS/BF/background.lua"))() |
| 74 | + |
| 75 | +return { init=background.init, run=run_ui, background=background.run_bg } |
0 commit comments