Skip to content

Commit

Permalink
Hide GPS settings if unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
atomgomba committed Jan 14, 2024
1 parent 9e7c375 commit 94680e3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/SCRIPTS/BF/features.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local features = {
vtx = true,
gps = true,
}

return features
52 changes: 52 additions & 0 deletions src/SCRIPTS/BF/features_info.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local MSP_GPS_CONFIG = 135
local MSP_VTX_CONFIG = 88

local isGpsRead = false
local isVtxRead = true -- Checking VTX is done in `vtx_tables.lua`

local lastRunTS = 0
local INTERVAL = 100

local returnTable = {
f = nil,
t = "",
}

local function processMspReply(cmd, payload, err)
local isOkay = not err
if cmd == MSP_GPS_CONFIG then
isGpsRead = true
local providerSet = payload[1] ~= 0
features.gps = isOkay and providerSet
elseif cmd == MSP_VTX_CONFIG then
isVtxRead = true
local vtxTableAvailable = payload[12] ~= 0
features.vtx = isOkay and vtxTableAvailable
end
end

local function updateFeatures()
if lastRunTS + INTERVAL < getTime() then
lastRunTS = getTime()
local cmd
if not isGpsRead then
cmd = MSP_GPS_CONFIG
returnTable.t = "Checking GPS..."
elseif not isVtxRead then
cmd = MSP_VTX_CONFIG
returnTable.t = "Checking VTX..."
end
if cmd then
protocol.mspRead(cmd)
else
return true
end
end
mspProcessTxQ()
processMspReply(mspPollReply())
return false
end

returnTable.f = updateFeatures

return returnTable
6 changes: 3 additions & 3 deletions src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local PageFiles = {}

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

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

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

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

Expand Down
20 changes: 1 addition & 19 deletions src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ local function confirm(page)
collectgarbage()
end

local function filterAvailablePages(pageFiles)
local newPageFiles = pageFiles

local function skipPage(script)
local currentPageFiles = {}
for i = 1, #newPageFiles do
if newPageFiles[i].script ~= script then
currentPageFiles[#currentPageFiles + 1] = newPageFiles[i]
end
end
newPageFiles = currentPageFiles
end

if not features.vtx then skipPage("vtx.lua") end

return newPageFiles
end

local function createPopupMenu()
popupMenuActive = 1
popupMenu = {}
Expand Down Expand Up @@ -314,7 +296,7 @@ local function run_ui(event)
return 0
end
init = nil
PageFiles = filterAvailablePages(assert(loadScript("pages.lua"))())
PageFiles = assert(loadScript("pages.lua"))()
invalidatePages()
uiState = prevUiState or uiStatus.mainMenu
prevUiState = nil
Expand Down
13 changes: 11 additions & 2 deletions src/SCRIPTS/BF/ui_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ local apiVersionReceived = false
local vtxTablesReceived = false
local mcuIdReceived = false
local boardInfoReceived = false
local getApiVersion, getVtxTables, getMCUId, getBoardInfo
local featuresReceived = false
local getApiVersion, getVtxTables, getMCUId, getBoardInfo, getFeaturesInfo
local returnTable = { f = nil, t = "" }

local function init()
Expand Down Expand Up @@ -56,10 +57,18 @@ local function init()
getBoardInfo = nil
collectgarbage()
end
elseif not featuresReceived and apiVersion >= 1.41 then
getFeaturesInfo = getFeaturesInfo or assert(loadScript("features_info.lua"))()
returnTable.t = getFeaturesInfo.t
featuresReceived = getFeaturesInfo.f()
if featuresReceived then
getFeaturesInfo = nil
collectgarbage()
end
else
return true
end
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived and featuresReceived
end

returnTable.f = init
Expand Down

0 comments on commit 94680e3

Please sign in to comment.