Skip to content

Commit

Permalink
Merge pull request #480 from atomgomba/hide-vtx-menu
Browse files Browse the repository at this point in the history
Hide VTX menu when feature is unavailable
  • Loading branch information
haslinghuis authored Oct 19, 2023
2 parents b5a9948 + 47f9efb commit 70f5e47
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/SCRIPTS/BF/features.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local features = {
vtx = true,
}

return features
20 changes: 19 additions & 1 deletion src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ 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 @@ -296,7 +314,7 @@ local function run_ui(event)
return 0
end
init = nil
PageFiles = assert(loadScript("pages.lua"))()
PageFiles = filterAvailablePages(assert(loadScript("pages.lua"))())
invalidatePages()
uiState = prevUiState or uiStatus.mainMenu
prevUiState = nil
Expand Down
13 changes: 9 additions & 4 deletions src/SCRIPTS/BF/ui_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ local function init()
mcuIdReceived = getMCUId.f()
if mcuIdReceived then
getMCUId = nil
local f = loadScript("VTX_TABLES/"..mcuId..".lua")
if f and f() then
vtxTablesReceived = true
f = nil
local f = loadScript("VTX_TABLES/" .. mcuId .. ".lua")
if f then
local table = f()
if table then
vtxTablesReceived = true
features.vtx = 0 < table.frequenciesPerBand
f = nil
table = nil
end
end
collectgarbage()
f = loadScript("BOARD_INFO/"..mcuId..".lua")
Expand Down
2 changes: 2 additions & 0 deletions src/SCRIPTS/BF/vtx_tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ local function processMspReply(cmd, payload, err)
vtxTableAvailable = true
vtxFrequencyTableReceived = true
vtxPowerTableReceived = true
features.vtx = false
return
end
vtxConfigReceived = true
vtxTableAvailable = payload[12] ~= 0
features.vtx = vtxTableAvailable
vtxTableConfig.bands = payload[13]
vtxTableConfig.channels = payload[14]
vtxTableConfig.powerLevels = payload[15]
Expand Down
1 change: 1 addition & 0 deletions src/SCRIPTS/TOOLS/bf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if scriptsCompiled then
radio = assert(loadScript("radios.lua"))().msp
assert(loadScript(protocol.mspTransport))()
assert(loadScript("MSP/common.lua"))()
features = assert(loadScript("features.lua"))()
run = assert(loadScript("ui.lua"))()
else
run = assert(loadScript("COMPILE/compile.lua"))()
Expand Down

0 comments on commit 70f5e47

Please sign in to comment.