Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 569e409

Browse files
Merge pull request #495 from atomgomba/hide-gps-if-unavailable
Hide GPS settings if unavailable
2 parents 9e7c375 + 571dfd5 commit 569e409

File tree

8 files changed

+98
-58
lines changed

8 files changed

+98
-58
lines changed

‎src/SCRIPTS/BF/CONFIRM/vtx_tables.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
local template = assert(loadScript(radio.template))()
22
local margin = template.margin
3-
local indent = template.indent
43
local lineSpacing = template.lineSpacing
5-
local tableSpacing = template.tableSpacing
6-
local sp = template.listSpacing.field
74
local yMinLim = radio.yMinLimit
85
local x = margin
96
local y = yMinLim - lineSpacing

‎src/SCRIPTS/BF/PAGES/INIT/vtx.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local function precondition()
2+
local hasVtxTable = loadScript("VTX_TABLES/"..mcuId..".lua")
3+
collectgarbage()
4+
if hasVtxTable then
5+
return nil
6+
else
7+
return "CONFIRM/vtx_tables.lua"
8+
end
9+
end
10+
11+
return precondition()

‎src/SCRIPTS/BF/PAGES/vtx.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
local template = assert(loadScript(radio.template))()
22
local margin = template.margin
3-
local indent = template.indent
43
local lineSpacing = template.lineSpacing
5-
local tableSpacing = template.tableSpacing
64
local sp = template.listSpacing.field
75
local yMinLim = radio.yMinLimit
86
local x = margin
@@ -13,7 +11,7 @@ local fields = {}
1311

1412
local vtx_tables
1513
if apiVersion >= 1.42 then
16-
vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"))()
14+
vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"), "No VTX table!")()
1715
else
1816
vtx_tables = assert(loadScript("VTX_TABLES/vtx_defaults.lua"))()
1917
end

‎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 = false
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local PageFiles = {}
22

3-
if apiVersion >= 1.36 then
4-
PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua" }
3+
if apiVersion >= 1.36 andfeatures.vtxthen
4+
PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua", init="PAGES/INIT/vtx.lua" }
55
end
66

77
if apiVersion >= 1.16 then
@@ -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 andfeatures.gpsthen
5252
PageFiles[#PageFiles + 1] = { title = "GPS Rescue", script = "rescue.lua" }
5353
end
5454

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

‎src/SCRIPTS/BF/ui.lua

Lines changed: 18 additions & 21 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
@@ -403,8 +385,23 @@ local function run_ui(event)
403385
end
404386
end
405387
if not Page then
406-
Page = assert(loadScript("PAGES/"..PageFiles[currentPage].script))()
407-
collectgarbage()
388+
local function selectPage(page)
389+
Page = assert(loadScript("PAGES/"..page))()
390+
collectgarbage()
391+
end
392+
393+
local selectedPage = PageFiles[currentPage]
394+
if selectedPage.init then
395+
local initScript = assert(loadScript(selectedPage.init), "Missing init script")()
396+
collectgarbage()
397+
if initScript then
398+
confirm(initScript)
399+
else
400+
selectPage(selectedPage.script)
401+
end
402+
else
403+
selectPage(selectedPage.script)
404+
end
408405
end
409406
if not Page.values and pageState == pageStatus.display then
410407
requestPage()

‎src/SCRIPTS/BF/ui_init.lua

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
local apiVersionReceived = false
2-
local vtxTablesReceived = false
32
local mcuIdReceived = false
43
local boardInfoReceived = false
5-
local getApiVersion, getVtxTables, getMCUId, getBoardInfo
4+
local featuresReceived = false
5+
local getApiVersion, getMCUId, getBoardInfo, getFeaturesInfo
66
local returnTable = { f = nil, t = "" }
77

88
local function init()
@@ -22,30 +22,6 @@ local function init()
2222
mcuIdReceived = getMCUId.f()
2323
if mcuIdReceived then
2424
getMCUId = nil
25-
local f = loadScript("VTX_TABLES/" .. mcuId .. ".lua")
26-
if f then
27-
local table = f()
28-
if table then
29-
vtxTablesReceived = true
30-
features.vtx = 0 < table.frequenciesPerBand
31-
f = nil
32-
table = nil
33-
end
34-
end
35-
collectgarbage()
36-
f = loadScript("BOARD_INFO/"..mcuId..".lua")
37-
if f and f() then
38-
boardInfoReceived = true
39-
f = nil
40-
end
41-
collectgarbage()
42-
end
43-
elseif not vtxTablesReceived and apiVersion >= 1.42 then
44-
getVtxTables = getVtxTables or assert(loadScript("vtx_tables.lua"))()
45-
returnTable.t = getVtxTables.t
46-
vtxTablesReceived = getVtxTables.f()
47-
if vtxTablesReceived then
48-
getVtxTables = nil
4925
collectgarbage()
5026
end
5127
elseif not boardInfoReceived and apiVersion >= 1.44 then
@@ -56,10 +32,18 @@ local function init()
5632
getBoardInfo = nil
5733
collectgarbage()
5834
end
35+
elseif not featuresReceived and apiVersion >= 1.41 then
36+
getFeaturesInfo = getFeaturesInfo or assert(loadScript("features_info.lua"))()
37+
returnTable.t = getFeaturesInfo.t
38+
featuresReceived = getFeaturesInfo.f()
39+
if featuresReceived then
40+
getFeaturesInfo = nil
41+
collectgarbage()
42+
end
5943
else
6044
return true
6145
end
62-
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived
46+
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceivedandfeaturesReceived
6347
end
6448

6549
returnTable.f = init

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /