Skip to content

Commit 94680e3

Browse files
committed
Hide GPS settings if unavailable
1 parent 9e7c375 commit 94680e3

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

src/SCRIPTS/BF/features.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local features = {
22
vtx = true,
3+
gps = true,
34
}
45

56
return features

src/SCRIPTS/BF/features_info.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local MSP_GPS_CONFIG = 135
2+
local MSP_VTX_CONFIG = 88
3+
4+
local isGpsRead = false
5+
local isVtxRead = true -- Checking VTX is done in `vtx_tables.lua`
6+
7+
local lastRunTS = 0
8+
local INTERVAL = 100
9+
10+
local returnTable = {
11+
f = nil,
12+
t = "",
13+
}
14+
15+
local function processMspReply(cmd, payload, err)
16+
local isOkay = not err
17+
if cmd == MSP_GPS_CONFIG then
18+
isGpsRead = true
19+
local providerSet = payload[1] ~= 0
20+
features.gps = isOkay and providerSet
21+
elseif cmd == MSP_VTX_CONFIG then
22+
isVtxRead = true
23+
local vtxTableAvailable = payload[12] ~= 0
24+
features.vtx = isOkay and vtxTableAvailable
25+
end
26+
end
27+
28+
local function updateFeatures()
29+
if lastRunTS + INTERVAL < getTime() then
30+
lastRunTS = getTime()
31+
local cmd
32+
if not isGpsRead then
33+
cmd = MSP_GPS_CONFIG
34+
returnTable.t = "Checking GPS..."
35+
elseif not isVtxRead then
36+
cmd = MSP_VTX_CONFIG
37+
returnTable.t = "Checking VTX..."
38+
end
39+
if cmd then
40+
protocol.mspRead(cmd)
41+
else
42+
return true
43+
end
44+
end
45+
mspProcessTxQ()
46+
processMspReply(mspPollReply())
47+
return false
48+
end
49+
50+
returnTable.f = updateFeatures
51+
52+
return returnTable

src/SCRIPTS/BF/pages.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local PageFiles = {}
22

3-
if apiVersion >= 1.36 then
3+
if apiVersion >= 1.36 and features.vtx then
44
PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua" }
55
end
66

@@ -48,11 +48,11 @@ if apiVersion >= 1.16 then
4848
PageFiles[#PageFiles + 1] = { title = "Failsafe", script = "failsafe.lua" }
4949
end
5050

51-
if apiVersion >= 1.41 then
51+
if apiVersion >= 1.41 and features.gps then
5252
PageFiles[#PageFiles + 1] = { title = "GPS Rescue", script = "rescue.lua" }
5353
end
5454

55-
if apiVersion >= 1.41 then
55+
if apiVersion >= 1.41 and features.gps then
5656
PageFiles[#PageFiles + 1] = { title = "GPS PIDs", script = "gpspids.lua" }
5757
end
5858

src/SCRIPTS/BF/ui.lua

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,6 @@ local function confirm(page)
8282
collectgarbage()
8383
end
8484

85-
local function filterAvailablePages(pageFiles)
86-
local newPageFiles = pageFiles
87-
88-
local function skipPage(script)
89-
local currentPageFiles = {}
90-
for i = 1, #newPageFiles do
91-
if newPageFiles[i].script ~= script then
92-
currentPageFiles[#currentPageFiles + 1] = newPageFiles[i]
93-
end
94-
end
95-
newPageFiles = currentPageFiles
96-
end
97-
98-
if not features.vtx then skipPage("vtx.lua") end
99-
100-
return newPageFiles
101-
end
102-
10385
local function createPopupMenu()
10486
popupMenuActive = 1
10587
popupMenu = {}
@@ -314,7 +296,7 @@ local function run_ui(event)
314296
return 0
315297
end
316298
init = nil
317-
PageFiles = filterAvailablePages(assert(loadScript("pages.lua"))())
299+
PageFiles = assert(loadScript("pages.lua"))()
318300
invalidatePages()
319301
uiState = prevUiState or uiStatus.mainMenu
320302
prevUiState = nil

src/SCRIPTS/BF/ui_init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ local apiVersionReceived = false
22
local vtxTablesReceived = false
33
local mcuIdReceived = false
44
local boardInfoReceived = false
5-
local getApiVersion, getVtxTables, getMCUId, getBoardInfo
5+
local featuresReceived = false
6+
local getApiVersion, getVtxTables, getMCUId, getBoardInfo, getFeaturesInfo
67
local returnTable = { f = nil, t = "" }
78

89
local function init()
@@ -56,10 +57,18 @@ local function init()
5657
getBoardInfo = nil
5758
collectgarbage()
5859
end
60+
elseif not featuresReceived and apiVersion >= 1.41 then
61+
getFeaturesInfo = getFeaturesInfo or assert(loadScript("features_info.lua"))()
62+
returnTable.t = getFeaturesInfo.t
63+
featuresReceived = getFeaturesInfo.f()
64+
if featuresReceived then
65+
getFeaturesInfo = nil
66+
collectgarbage()
67+
end
5968
else
6069
return true
6170
end
62-
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived
71+
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived and featuresReceived
6372
end
6473

6574
returnTable.f = init

0 commit comments

Comments
 (0)