From 8c3dcd33d70297b460e07e0c9c3f202599ac51c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiripolszky=20K=C3=A1roly?= Date: Sun, 14 Jan 2024 13:02:39 +0100 Subject: [PATCH 1/2] Hide GPS settings if unavailable --- src/SCRIPTS/BF/PAGES/vtx.lua | 2 -- src/SCRIPTS/BF/features.lua | 1 + src/SCRIPTS/BF/features_info.lua | 52 ++++++++++++++++++++++++++++++++ src/SCRIPTS/BF/pages.lua | 6 ++-- src/SCRIPTS/BF/ui.lua | 20 +----------- src/SCRIPTS/BF/ui_init.lua | 13 ++++++-- 6 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 src/SCRIPTS/BF/features_info.lua diff --git a/src/SCRIPTS/BF/PAGES/vtx.lua b/src/SCRIPTS/BF/PAGES/vtx.lua index e2a978e..0e002b4 100644 --- a/src/SCRIPTS/BF/PAGES/vtx.lua +++ b/src/SCRIPTS/BF/PAGES/vtx.lua @@ -1,8 +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 diff --git a/src/SCRIPTS/BF/features.lua b/src/SCRIPTS/BF/features.lua index d56d8ff..383252a 100644 --- a/src/SCRIPTS/BF/features.lua +++ b/src/SCRIPTS/BF/features.lua @@ -1,5 +1,6 @@ local features = { vtx = true, + gps = true, } return features diff --git a/src/SCRIPTS/BF/features_info.lua b/src/SCRIPTS/BF/features_info.lua new file mode 100644 index 0000000..bb28ecf --- /dev/null +++ b/src/SCRIPTS/BF/features_info.lua @@ -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 diff --git a/src/SCRIPTS/BF/pages.lua b/src/SCRIPTS/BF/pages.lua index d1f1e01..979b733 100644 --- a/src/SCRIPTS/BF/pages.lua +++ b/src/SCRIPTS/BF/pages.lua @@ -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 @@ -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 diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index 1dd1161..fee070e 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -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 = {} @@ -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 diff --git a/src/SCRIPTS/BF/ui_init.lua b/src/SCRIPTS/BF/ui_init.lua index 1c624c8..939307f 100644 --- a/src/SCRIPTS/BF/ui_init.lua +++ b/src/SCRIPTS/BF/ui_init.lua @@ -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() @@ -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 From 571dfd52ec1b5f45ae42db9877952c4362dce8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiripolszky=20K=C3=A1roly?= Date: Tue, 23 Jan 2024 18:05:48 +0100 Subject: [PATCH 2/2] Do not download VTX table prematurely --- src/SCRIPTS/BF/CONFIRM/vtx_tables.lua | 3 --- src/SCRIPTS/BF/PAGES/INIT/vtx.lua | 11 +++++++++++ src/SCRIPTS/BF/PAGES/vtx.lua | 2 +- src/SCRIPTS/BF/features_info.lua | 2 +- src/SCRIPTS/BF/pages.lua | 2 +- src/SCRIPTS/BF/ui.lua | 19 +++++++++++++++++-- src/SCRIPTS/BF/ui_init.lua | 27 +-------------------------- 7 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 src/SCRIPTS/BF/PAGES/INIT/vtx.lua diff --git a/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua b/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua index 5d51e61..f619fda 100644 --- a/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua +++ b/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua @@ -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 diff --git a/src/SCRIPTS/BF/PAGES/INIT/vtx.lua b/src/SCRIPTS/BF/PAGES/INIT/vtx.lua new file mode 100644 index 0000000..ac5dbe3 --- /dev/null +++ b/src/SCRIPTS/BF/PAGES/INIT/vtx.lua @@ -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() diff --git a/src/SCRIPTS/BF/PAGES/vtx.lua b/src/SCRIPTS/BF/PAGES/vtx.lua index 0e002b4..7c61da3 100644 --- a/src/SCRIPTS/BF/PAGES/vtx.lua +++ b/src/SCRIPTS/BF/PAGES/vtx.lua @@ -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 diff --git a/src/SCRIPTS/BF/features_info.lua b/src/SCRIPTS/BF/features_info.lua index bb28ecf..d37e21d 100644 --- a/src/SCRIPTS/BF/features_info.lua +++ b/src/SCRIPTS/BF/features_info.lua @@ -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 diff --git a/src/SCRIPTS/BF/pages.lua b/src/SCRIPTS/BF/pages.lua index 979b733..63c4b23 100644 --- a/src/SCRIPTS/BF/pages.lua +++ b/src/SCRIPTS/BF/pages.lua @@ -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 diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index fee070e..f849223 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -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() diff --git a/src/SCRIPTS/BF/ui_init.lua b/src/SCRIPTS/BF/ui_init.lua index 939307f..89d2a9b 100644 --- a/src/SCRIPTS/BF/ui_init.lua +++ b/src/SCRIPTS/BF/ui_init.lua @@ -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() @@ -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