From 61e8f4c6cd0584fbab69e207b05cdd0599c98fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiripolszky=20K=C3=A1roly?= Date: Wed, 24 Jan 2024 19:17:54 +0100 Subject: [PATCH] Hide OSD (SD) settings --- src/SCRIPTS/BF/PAGES/pos_osd.lua | 6 ++-- src/SCRIPTS/BF/features.lua | 6 ++-- src/SCRIPTS/BF/features_info.lua | 62 ++++++++++++++++++++++++++++---- src/SCRIPTS/BF/pages.lua | 2 +- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/SCRIPTS/BF/PAGES/pos_osd.lua b/src/SCRIPTS/BF/PAGES/pos_osd.lua index 3417ac2..2e5c262 100644 --- a/src/SCRIPTS/BF/PAGES/pos_osd.lua +++ b/src/SCRIPTS/BF/PAGES/pos_osd.lua @@ -1,9 +1,7 @@ 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 @@ -133,12 +131,12 @@ return { self.values[3] = bit32.rshift(combineValue, 8) return self.values end, - checkProfile = function(self, value, profileFirst, profileSecond, profileThird) + checkProfile = function(_, value, profileFirst, profileSecond, profileThird) local profiles = profileFirst + bit32.lshift(profileSecond, 1) + bit32.lshift(profileThird, 2) local output = bit32.replace(value, profiles, 11, 3) return output end, - splitVal = function(self, inputFirstVal, inputSecondVal) + splitVal = function(_, inputFirstVal, inputSecondVal) local inputVal = inputFirstVal + bit32.lshift(inputSecondVal, 8) local profiles = bit32.extract(inputVal, 11, 3) local fieldPos = bit32.extract(inputVal, 0, 11) diff --git a/src/SCRIPTS/BF/features.lua b/src/SCRIPTS/BF/features.lua index 383252a..c76251c 100644 --- a/src/SCRIPTS/BF/features.lua +++ b/src/SCRIPTS/BF/features.lua @@ -1,6 +1,8 @@ local features = { - vtx = true, - gps = true, + vtx = true, + gps = true, + osdSD = true, + blackbox = true, } return features diff --git a/src/SCRIPTS/BF/features_info.lua b/src/SCRIPTS/BF/features_info.lua index d37e21d..5fe599b 100644 --- a/src/SCRIPTS/BF/features_info.lua +++ b/src/SCRIPTS/BF/features_info.lua @@ -1,20 +1,61 @@ local MSP_GPS_CONFIG = 135 local MSP_VTX_CONFIG = 88 +local MSP_OSD_CONFIG = 84 + +local MSP_BUILD_INFO = 5 + +local BUILD_OPTION_GPS = 16412 +local BUILD_OPTION_VTX = 16421 +local BUILD_OPTION_OSD_SD = 16416 local isGpsRead = false local isVtxRead = false +local isOsdSDRead = false local lastRunTS = 0 local INTERVAL = 100 +local isInFlight = false local returnTable = { f = nil, t = "", } +local function processBuildInfoReply(payload) + local headLength = 26 -- DATE(11) + TIME(8) + REVISION(7) + local optionsLength = #payload - headLength + if (optionsLength <= 0) or ((optionsLength % 2) ~= 0) then + return -- invalid payload + end + + features.gps = false + features.vtx = false + features.osdSD = false + for i = headLength + 1, #payload, 2 do + local byte1 = bit32.lshift(payload[i], 0) + local byte2 = bit32.lshift(payload[i + 1], 8) + local word = bit32.bor(byte1, byte2) + if word == BUILD_OPTION_GPS then + features.gps = true + elseif word == BUILD_OPTION_VTX then + features.vtx = true + elseif word == BUILD_OPTION_OSD_SD then + features.osdSD = true + end + end +end + local function processMspReply(cmd, payload, err) + isInFlight = false local isOkay = not err - if cmd == MSP_GPS_CONFIG then + if cmd == MSP_BUILD_INFO then + isGpsRead = true + isVtxRead = true + isOsdSDRead = true + if isOkay then + processBuildInfoReply(payload) + end + elseif cmd == MSP_GPS_CONFIG then isGpsRead = true local providerSet = payload[1] ~= 0 features.gps = isOkay and providerSet @@ -22,6 +63,10 @@ local function processMspReply(cmd, payload, err) isVtxRead = true local vtxTableAvailable = payload[12] ~= 0 features.vtx = isOkay and vtxTableAvailable + elseif cmd == MSP_OSD_CONFIG then + isOsdSDRead = true + local osdSDAvailable = payload[1] ~= 0 + features.osdSD = isOkay and osdSDAvailable end end @@ -29,22 +74,27 @@ local function updateFeatures() if lastRunTS + INTERVAL < getTime() then lastRunTS = getTime() local cmd - if not isGpsRead then + if apiVersion >= 1.46 then + cmd = MSP_BUILD_INFO + returnTable.t = "Checking options..." + elseif not isGpsRead then cmd = MSP_GPS_CONFIG returnTable.t = "Checking GPS..." elseif not isVtxRead then cmd = MSP_VTX_CONFIG returnTable.t = "Checking VTX..." + elseif not isOsdSDRead then + cmd = MSP_OSD_CONFIG + returnTable.t = "Checking OSD (SD)..." end - if cmd then + if cmd and not isInFlight then protocol.mspRead(cmd) - else - return true + isInFlight = true end end mspProcessTxQ() processMspReply(mspPollReply()) - return false + return isGpsRead and isVtxRead and isOsdSDRead end returnTable.f = updateFeatures diff --git a/src/SCRIPTS/BF/pages.lua b/src/SCRIPTS/BF/pages.lua index 9e5fd8d..9763e1c 100644 --- a/src/SCRIPTS/BF/pages.lua +++ b/src/SCRIPTS/BF/pages.lua @@ -60,7 +60,7 @@ if apiVersion >= 1.16 then PageFiles[#PageFiles + 1] = { title = "Trim Accelerometer", script = "acc_trim.lua" } end -if apiVersion >= 1.45 then +if apiVersion >= 1.45 and features.osdSD then PageFiles[#PageFiles + 1] = { title = "OSD Elements", script = "pos_osd.lua" } end