Skip to content

Commit 4660df2

Browse files
committed
Send RSSI value via SmartPort
1 parent 318cf0a commit 4660df2

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed

X7.lua

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- load msp.lua
2+
assert(loadScript("/SCRIPTS/BF/msp_sp.lua"))()
3+
14
SetupPages = {
25
{
36
title = "PIDs",
@@ -69,5 +72,103 @@ MenuBox = { x=1, y=10, w=100, x_offset=36, h_line=10, h_offset=3 }
6972
SaveBox = { x=20, y=12, w=100, x_offset=4, h=30, h_offset=5 }
7073
NoTelem = { 36, 55, "No Telemetry", BLINK }
7174

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 = "VFAS"
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+
72173
local run_ui = assert(loadScript("/SCRIPTS/BF/ui.lua"))()
73-
return {run=run_ui}
174+
return { init=init, run=run_ui, background=run_bg }

X9.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ NoTelem = { 70, 55, "No Telemetry", BLINK }
7979

8080
local INTERVAL = 100 -- 100 = 1 second, 200 = 2 seconds, ...
8181
local MSP_SET_RTC = 246
82+
local MSP_TX_INFO = 186
8283
local sensorName = "VFAS"
8384

8485
local lastRunTS
8586
local oldSensorValue
8687
local sensorId
88+
local mspMsgQueued = false
8789

8890
local function getTelemetryId(name)
8991
local field = getFieldInfo(name)
@@ -105,6 +107,12 @@ local function run_bg()
105107
-- run in intervals
106108
if lastRunTS == 0 or lastRunTS + INTERVAL < getTime() then
107109

110+
mspMsgQueued = false
111+
112+
-- ------------------------------------
113+
-- SYNC DATE AND TIME
114+
-- ------------------------------------
115+
108116
-- get sensor value
109117
local newSensorValue = getValue(sensorId)
110118

@@ -128,13 +136,29 @@ local function run_bg()
128136
values[6] = now.min
129137
values[7] = now.sec
130138

131-
-- send info
139+
-- send msp message
132140
mspSendRequest(MSP_SET_RTC, values)
141+
mspMsgQueued = true
133142
end
134143

135144
oldSensorValue = newSensorValue
136145
end
137146

147+
148+
-- ------------------------------------
149+
-- SEND RSSI VALUE
150+
-- ------------------------------------
151+
152+
if mspMsgQueued == false then
153+
local rssi, alarm_low, alarm_crit = getRSSI()
154+
values = {}
155+
values[1] = rssi
156+
157+
-- send msp message
158+
mspSendRequest(MSP_TX_INFO, values)
159+
mspMsgQueued = true
160+
end
161+
138162
lastRunTS = getTime()
139163
end
140164

0 commit comments

Comments
 (0)