From e2597af37aa0a3ee24c97acdcc12ea00f2f1c94e Mon Sep 17 00:00:00 2001 From: Hans Christian Olaussen <41271048+klutvott123@users.noreply.github.com> Date: Sun, 12 Mar 2023 20:29:27 +0100 Subject: [PATCH 1/3] Skip vtx tables download if not available --- src/SCRIPTS/BF/MSP/common.lua | 9 +++------ src/SCRIPTS/BF/PAGES/vtx.lua | 5 +++-- src/SCRIPTS/BF/acc_cal.lua | 4 ++-- src/SCRIPTS/BF/api_version.lua | 4 ++-- src/SCRIPTS/BF/board_info.lua | 4 ++-- src/SCRIPTS/BF/mcu_id.lua | 4 ++-- src/SCRIPTS/BF/rssi.lua | 4 ++-- src/SCRIPTS/BF/rtc.lua | 4 ++-- src/SCRIPTS/BF/ui.lua | 4 ++-- src/SCRIPTS/BF/vtx_tables.lua | 9 +++++++-- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/SCRIPTS/BF/MSP/common.lua b/src/SCRIPTS/BF/MSP/common.lua index dc20f9bd..467c1ce1 100644 --- a/src/SCRIPTS/BF/MSP/common.lua +++ b/src/SCRIPTS/BF/MSP/common.lua @@ -6,6 +6,7 @@ local MSP_STARTFLAG = bit32.lshift(1,4) local mspSeq = 0 local mspRemoteSeq = 0 local mspRxBuf = {} +local mspRxError = false local mspRxSize = 0 local mspRxCRC = 0 local mspRxReq = 0 @@ -65,17 +66,13 @@ end function mspReceivedReply(payload) local idx = 1 local status = payload[idx] - local err = bit32.btest(status, 0x80) local version = bit32.rshift(bit32.band(status, 0x60), 5) local start = bit32.btest(status, 0x10) local seq = bit32.band(status, 0x0F) idx = idx + 1 - if err then - mspStarted = false - return nil - end if start then mspRxBuf = {} + mspRxError = bit32.btest(status, 0x80) mspRxSize = payload[idx] mspRxReq = mspLastReq idx = idx + 1 @@ -117,7 +114,7 @@ function mspPollReply() return nil elseif mspReceivedReply(mspData) then mspLastReq = 0 - return mspRxReq, mspRxBuf + return mspRxReq, mspRxBuf, mspRxError end end end diff --git a/src/SCRIPTS/BF/PAGES/vtx.lua b/src/SCRIPTS/BF/PAGES/vtx.lua index e2a978e0..b40e9125 100644 --- a/src/SCRIPTS/BF/PAGES/vtx.lua +++ b/src/SCRIPTS/BF/PAGES/vtx.lua @@ -12,8 +12,9 @@ local labels = {} local fields = {} local vtx_tables -if apiVersion >= 1.42 then - vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"))() +local f = loadScript("VTX_TABLES/"..mcuId..".lua") +if apiVersion >= 1.42 and f then + vtx_tables = f() else vtx_tables = assert(loadScript("VTX_TABLES/vtx_defaults.lua"))() end diff --git a/src/SCRIPTS/BF/acc_cal.lua b/src/SCRIPTS/BF/acc_cal.lua index 582d459c..0ebfc17b 100644 --- a/src/SCRIPTS/BF/acc_cal.lua +++ b/src/SCRIPTS/BF/acc_cal.lua @@ -3,8 +3,8 @@ local accCalibrated = false local lastRunTS = 0 local INTERVAL = 500 -local function processMspReply(cmd,rx_buf) - if cmd == MSP_ACC_CALIBRATION then +local function processMspReply(cmd,rx_buf,err) + if cmd == MSP_ACC_CALIBRATION and not err then accCalibrated = true end end diff --git a/src/SCRIPTS/BF/api_version.lua b/src/SCRIPTS/BF/api_version.lua index c80efb3d..5bcb4c2b 100644 --- a/src/SCRIPTS/BF/api_version.lua +++ b/src/SCRIPTS/BF/api_version.lua @@ -4,8 +4,8 @@ local apiVersionReceived = false local lastRunTS = 0 local INTERVAL = 50 -local function processMspReply(cmd,rx_buf) - if cmd == MSP_API_VERSION and #rx_buf >= 3 then +local function processMspReply(cmd,rx_buf,err) + if cmd == MSP_API_VERSION and #rx_buf >= 3 and not err then apiVersion = rx_buf[2] + rx_buf[3] / 100 apiVersionReceived = true end diff --git a/src/SCRIPTS/BF/board_info.lua b/src/SCRIPTS/BF/board_info.lua index 10efbe40..2ba3ec1c 100644 --- a/src/SCRIPTS/BF/board_info.lua +++ b/src/SCRIPTS/BF/board_info.lua @@ -20,8 +20,8 @@ local i2cRegisteredDeviceCount = 0 local lastRunTS = 0 local INTERVAL = 100 -local function processMspReply(cmd, payload) - if cmd == MSP_BOARD_INFO then +local function processMspReply(cmd, payload, err) + if cmd == MSP_BOARD_INFO and not err then local length local i = 1 length = 4 diff --git a/src/SCRIPTS/BF/mcu_id.lua b/src/SCRIPTS/BF/mcu_id.lua index 26d1e2ba..f3c84387 100644 --- a/src/SCRIPTS/BF/mcu_id.lua +++ b/src/SCRIPTS/BF/mcu_id.lua @@ -5,8 +5,8 @@ local MCUIdReceived = false local lastRunTS = 0 local INTERVAL = 100 -local function processMspReply(cmd, payload) - if cmd == MSP_UID then +local function processMspReply(cmd, payload, err) + if cmd == MSP_UID and not err then local i = 1 local id = "" for j = 1, 3 do diff --git a/src/SCRIPTS/BF/rssi.lua b/src/SCRIPTS/BF/rssi.lua index 401e7103..dc31dd03 100644 --- a/src/SCRIPTS/BF/rssi.lua +++ b/src/SCRIPTS/BF/rssi.lua @@ -9,8 +9,8 @@ local rssiSource = RSSI_SOURCE_NONE local lastRunTS = 0 local INTERVAL = 50 -local function processMspReply(cmd,rx_buf) - if cmd == MSP_TX_INFO and #rx_buf >= 1 then +local function processMspReply(cmd,rx_buf,err) + if cmd == MSP_TX_INFO and #rx_buf >= 1 and not err then rssiSource = rx_buf[1] rssiSourceReceived = true end diff --git a/src/SCRIPTS/BF/rtc.lua b/src/SCRIPTS/BF/rtc.lua index 148a2fd3..f0cd3306 100644 --- a/src/SCRIPTS/BF/rtc.lua +++ b/src/SCRIPTS/BF/rtc.lua @@ -4,8 +4,8 @@ local timeIsSet = false local lastRunTS = 0 local INTERVAL = 50 -local function processMspReply(cmd,rx_buf) - if cmd == MSP_SET_RTC then +local function processMspReply(cmd,rx_buf,err) + if cmd == MSP_SET_RTC and not err then timeIsSet = true end end diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index 23f5bb9f..8a3722ce 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -96,8 +96,8 @@ local function createPopupMenu() end end -local function processMspReply(cmd,rx_buf) - if not Page or not rx_buf then +local function processMspReply(cmd,rx_buf,err) + if not Page or not rx_buf or err then elseif cmd == Page.write then if Page.eepromWrite then eepromWrite() diff --git a/src/SCRIPTS/BF/vtx_tables.lua b/src/SCRIPTS/BF/vtx_tables.lua index 2efa8942..1340af8f 100644 --- a/src/SCRIPTS/BF/vtx_tables.lua +++ b/src/SCRIPTS/BF/vtx_tables.lua @@ -2,6 +2,7 @@ local MSP_VTX_CONFIG = 88 local MSP_VTXTABLE_BAND = 137 local MSP_VTXTABLE_POWERLEVEL = 138 +local vtxAvailable = true local vtxTableAvailable = false local vtxConfigReceived = false local vtxFrequencyTableReceived = false @@ -18,8 +19,12 @@ local powerTable = {} local lastRunTS = 0 local INTERVAL = 100 -local function processMspReply(cmd, payload) +local function processMspReply(cmd, payload, err) if cmd == MSP_VTX_CONFIG then + if err then + vtxAvailable = false + return + end vtxConfigReceived = true vtxTableAvailable = payload[12] ~= 0 vtxTableConfig.bands = payload[13] @@ -113,7 +118,7 @@ local function getVtxTables() end mspProcessTxQ() processMspReply(mspPollReply()) - return vtxTablesReceived + return vtxTablesReceived or not vtxAvailable end return { f = getVtxTables, t = "Downloading VTX tables" } From 3ea553eda0d04e3a15745705824aaf8abc294a84 Mon Sep 17 00:00:00 2001 From: Hans Christian Olaussen <41271048+klutvott123@users.noreply.github.com> Date: Sun, 12 Mar 2023 21:55:58 +0100 Subject: [PATCH 2/3] Display message if page not available --- src/SCRIPTS/BF/ui.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index 8a3722ce..fee070ea 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -97,7 +97,7 @@ local function createPopupMenu() end local function processMspReply(cmd,rx_buf,err) - if not Page or not rx_buf or err then + if not Page or not rx_buf then elseif cmd == Page.write then if Page.eepromWrite then eepromWrite() @@ -109,6 +109,9 @@ local function processMspReply(cmd,rx_buf,err) rebootFc() end invalidatePages() + elseif cmd == Page.read and err then + Page.fields = { { x = 6, y = radio.yMinLimit, value = "", ro = true } } + Page.labels = { { x = 6, y = radio.yMinLimit, t = "N/A" } } elseif cmd == Page.read and #rx_buf > 0 then Page.values = rx_buf for i=1,#Page.fields do From 61d302980967f05f3e8a4957dfc45c859559cdf0 Mon Sep 17 00:00:00 2001 From: Hans Christian Olaussen <41271048+klutvott123@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:08:18 +0100 Subject: [PATCH 3/3] Create empty vtx table if not available --- src/SCRIPTS/BF/PAGES/vtx.lua | 5 ++--- src/SCRIPTS/BF/vtx_tables.lua | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/SCRIPTS/BF/PAGES/vtx.lua b/src/SCRIPTS/BF/PAGES/vtx.lua index b40e9125..e2a978e0 100644 --- a/src/SCRIPTS/BF/PAGES/vtx.lua +++ b/src/SCRIPTS/BF/PAGES/vtx.lua @@ -12,9 +12,8 @@ local labels = {} local fields = {} local vtx_tables -local f = loadScript("VTX_TABLES/"..mcuId..".lua") -if apiVersion >= 1.42 and f then - vtx_tables = f() +if apiVersion >= 1.42 then + vtx_tables = assert(loadScript("VTX_TABLES/"..mcuId..".lua"))() else vtx_tables = assert(loadScript("VTX_TABLES/vtx_defaults.lua"))() end diff --git a/src/SCRIPTS/BF/vtx_tables.lua b/src/SCRIPTS/BF/vtx_tables.lua index 1340af8f..d7edbba6 100644 --- a/src/SCRIPTS/BF/vtx_tables.lua +++ b/src/SCRIPTS/BF/vtx_tables.lua @@ -2,7 +2,6 @@ local MSP_VTX_CONFIG = 88 local MSP_VTXTABLE_BAND = 137 local MSP_VTXTABLE_POWERLEVEL = 138 -local vtxAvailable = true local vtxTableAvailable = false local vtxConfigReceived = false local vtxFrequencyTableReceived = false @@ -12,7 +11,6 @@ local requestedBand = 1 local requestedPowerLevel = 1 local vtxTableConfig = {} local frequencyTable = {} -local frequenciesPerBand = 0 local bandTable = {} local powerTable = {} @@ -22,7 +20,15 @@ local INTERVAL = 100 local function processMspReply(cmd, payload, err) if cmd == MSP_VTX_CONFIG then if err then - vtxAvailable = false + -- Vtx not available. Create empty vtx table to skip future download attempts + frequencyTable[1] = {} + vtxTableConfig.channels = 0 + bandTable = { [0] = "U", "1" } + powerTable = { "LV0" } + vtxConfigReceived = true + vtxTableAvailable = true + vtxFrequencyTableReceived = true + vtxPowerTableReceived = true return end vtxConfigReceived = true @@ -118,7 +124,7 @@ local function getVtxTables() end mspProcessTxQ() processMspReply(mspPollReply()) - return vtxTablesReceived or not vtxAvailable + return vtxTablesReceived end return { f = getVtxTables, t = "Downloading VTX tables" }