Skip to content

Hide VTX menu when feature is unavailable #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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