Skip to content

Commit

Permalink
Do not download VTX table prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
atomgomba committed Jan 23, 2024
1 parent 8c3dcd3 commit 571dfd5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
3 changes: 0 additions & 3 deletions src/SCRIPTS/BF/CONFIRM/vtx_tables.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
local template = assert(loadScript(radio.template))()
local margin = template.margin
local indent = template.indent
local lineSpacing = template.lineSpacing
local tableSpacing = template.tableSpacing
local sp = template.listSpacing.field
local yMinLim = radio.yMinLimit
local x = margin
local y = yMinLim - lineSpacing
Expand Down
11 changes: 11 additions & 0 deletions src/SCRIPTS/BF/PAGES/INIT/vtx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local function precondition()
local hasVtxTable = loadScript("VTX_TABLES/"..mcuId..".lua")
collectgarbage()
if hasVtxTable then
return nil
else
return "CONFIRM/vtx_tables.lua"
end
end

return precondition()
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/PAGES/vtx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local fields = {}

local vtx_tables
if apiVersion >= 1.42 then
vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"))()
vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"), "No VTX table!")()
else
vtx_tables = assert(loadScript("VTX_TABLES/vtx_defaults.lua"))()
end
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/features_info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 isVtxRead = false

local lastRunTS = 0
local INTERVAL = 100
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local PageFiles = {}

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

if apiVersion >= 1.16 then
Expand Down
19 changes: 17 additions & 2 deletions src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,23 @@ local function run_ui(event)
end
end
if not Page then
Page = assert(loadScript("PAGES/"..PageFiles[currentPage].script))()
collectgarbage()
local function selectPage(page)
Page = assert(loadScript("PAGES/"..page))()
collectgarbage()
end

local selectedPage = PageFiles[currentPage]
if selectedPage.init then
local initScript = assert(loadScript(selectedPage.init), "Missing init script")()
collectgarbage()
if initScript then
confirm(initScript)
else
selectPage(selectedPage.script)
end
else
selectPage(selectedPage.script)
end
end
if not Page.values and pageState == pageStatus.display then
requestPage()
Expand Down
27 changes: 1 addition & 26 deletions src/SCRIPTS/BF/ui_init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
local apiVersionReceived = false
local vtxTablesReceived = false
local mcuIdReceived = false
local boardInfoReceived = false
local featuresReceived = false
local getApiVersion, getVtxTables, getMCUId, getBoardInfo, getFeaturesInfo
local getApiVersion, getMCUId, getBoardInfo, getFeaturesInfo
local returnTable = { f = nil, t = "" }

local function init()
Expand All @@ -23,30 +22,6 @@ local function init()
mcuIdReceived = getMCUId.f()
if mcuIdReceived then
getMCUId = 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")
if f and f() then
boardInfoReceived = true
f = nil
end
collectgarbage()
end
elseif not vtxTablesReceived and apiVersion >= 1.42 then
getVtxTables = getVtxTables or assert(loadScript("vtx_tables.lua"))()
returnTable.t = getVtxTables.t
vtxTablesReceived = getVtxTables.f()
if vtxTablesReceived then
getVtxTables = nil
collectgarbage()
end
elseif not boardInfoReceived and apiVersion >= 1.44 then
Expand Down

0 comments on commit 571dfd5

Please sign in to comment.