diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index dbf60c75..7d7fe79d 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -17,10 +17,10 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Code Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Fetch build artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.7 - name: List assets run: ls -al Assets @@ -28,12 +28,12 @@ jobs: - name: Attach assets to release run: | set -x - assets=() + ASSETS=() for asset in Assets/*.zip; do - assets+=("-a" "$asset") + ASSETS+=("$asset") echo "$asset" done - tag_name="${GITHUB_REF##*/}" - hub release edit "${assets[@]}" -m "" "$tag_name" + TAG_NAME="${GITHUB_REF##*/}" + gh release upload "${TAG_NAME}" "${ASSETS[@]}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e10e5e56..b9c9b0f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Code Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Lua run: sudo apt-get -y install lua5.2 @@ -31,7 +31,7 @@ jobs: run: make release - name: Publish build artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4.3.0 with: name: Assets path: ./release/*.zip diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f2116b87..c60f4255 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -32,10 +32,10 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Code Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Fetch build artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.7 - name: Select release notes id: notes diff --git a/README.md b/README.md index 2464a147..67a520b6 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,14 @@ ## Requirements - Betaflight - As a best practice, it is recommended to use the most recent stable release of Betaflight to obtain the best possible results; -- Telemetry - Telemetry has to be enabled and supported by the TX / RX for the scripts to be able to communicate with the flight controller; +- Telemetry - Telemetry has to be enabled in Betaflight Receiver tab and supported by the TX / RX for the scripts to be able to communicate with the flight controller; - OpenTX - 2.3.12 or newer; - EdgeTX - 2.4.0 or newer; - ExpressLRS - 2.0.1 or newer; - TBS Crossfire/Tracer TX / RX - v2.11 or newer; - FrSky TX / RX with support for SmartPort - While most receivers with SmartPort support work fine, it is recommended to update the receiver to the most recent firmware version to correct any known bugs in telemetry. -- ImmersionRC Ghost - Latest firmware. +- ImmersionRC Ghost RX module - Latest firmware and module set to RF Mode "Race250" - see (Ghost receiver manual pg 36-38) (Other RF Modes have issues or do not have telemetry to allow Betaflight LUA to work). +- Baud rate - Set to 400K in EdgeTX/OpenTX for Crossfire, Tracer, ExpressLRS. ## Installing @@ -53,6 +54,8 @@ Depending on the size of the vtx tables and the telemetry protocol used, downloa ![Download VTX tables](docs/assets/images/download_vtx_tables.gif) +Please note that if the "VTX" feature wasn't included in your Betaflight firmware build, the downloading of the VTX tables will be skipped and the VTX menu item won't be available. The initial setup of the VTX/VTX tables must be done using the [Configurator](https://github.com/betaflight/betaflight-configurator). + ### Betaflight CMS **!! IMPORTANT: TBS Crossfire/Tracer only !!** diff --git a/src/SCRIPTS/BF/CONFIRM/pwm.lua b/src/SCRIPTS/BF/CONFIRM/pwm.lua new file mode 100644 index 00000000..f2c90233 --- /dev/null +++ b/src/SCRIPTS/BF/CONFIRM/pwm.lua @@ -0,0 +1,21 @@ +local template = assert(loadScript(radio.template))() +local margin = template.margin +local lineSpacing = template.lineSpacing +local yMinLim = radio.yMinLimit +local x = margin +local y = yMinLim - lineSpacing +local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end } +local labels = {} +local fields = {} + +labels[#labels + 1] = { t = "Download Board Info? Press", x = x, y = inc.y(lineSpacing) } +labels[#labels + 1] = { t = "[ENTER] to download, or", x = x, y = inc.y(lineSpacing) } +labels[#labels + 1] = { t = "[EXIT] to cancel.", x = x, y = inc.y(lineSpacing) } +fields[#fields + 1] = { x = x, y = inc.y(lineSpacing), value = "", ro = true } + +return { + title = "Board Info", + labels = labels, + fields = fields, + init = assert(loadScript("board_info.lua"))(), +} diff --git a/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua b/src/SCRIPTS/BF/CONFIRM/vtx_tables.lua index 5d51e617..f619fda5 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/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/INIT/pwm.lua b/src/SCRIPTS/BF/PAGES/INIT/pwm.lua new file mode 100644 index 00000000..34232f85 --- /dev/null +++ b/src/SCRIPTS/BF/PAGES/INIT/pwm.lua @@ -0,0 +1,15 @@ +local function precondition() + if apiVersion < 1.44 then + -- BOARD_INFO is unavailable below 1.44 + return nil + end + local hasBoardInfo = loadScript("BOARD_INFO/"..mcuId..".lua") + collectgarbage() + if hasBoardInfo then + return nil + else + return "CONFIRM/pwm.lua" + end +end + +return precondition() diff --git a/src/SCRIPTS/BF/PAGES/INIT/vtx.lua b/src/SCRIPTS/BF/PAGES/INIT/vtx.lua new file mode 100644 index 00000000..ac5dbe33 --- /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/battery.lua b/src/SCRIPTS/BF/PAGES/battery.lua new file mode 100644 index 00000000..43a08f1f --- /dev/null +++ b/src/SCRIPTS/BF/PAGES/battery.lua @@ -0,0 +1,31 @@ +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 +local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end } +local labels = {} +local fields = {} + +labels[#labels + 1] = { t = "Voltage Settings", x = x, y = inc.y(lineSpacing) } +fields[#fields + 1] = { t = "Minimum Cell", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 500, vals = { 8, 9 }, scale = 100 } +fields[#fields + 1] = { t = "Maximum Cell", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 500, vals = { 10, 11 }, scale = 100 } +fields[#fields + 1] = { t = "Warning Cell", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 500, vals = { 12, 13 }, scale = 100 } + +labels[#labels + 1] = { t = "Capacity Settings", x = x, y = inc.y(lineSpacing) } +fields[#fields + 1] = { t = "Battery Capacity", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, mult = 25, max = 20000, vals = { 4, 5 } } + +return { + read = 32, -- MSP_BATTERY_CONFIG + write = 33, -- MSP_SET_BATTERY_CONFIG + title = "Battery", + reboot = false, + eepromWrite = true, + minBytes = 13, + labels = labels, + fields = fields +} diff --git a/src/SCRIPTS/BF/PAGES/pid_advanced.lua b/src/SCRIPTS/BF/PAGES/pid_advanced.lua index 16d54cf6..5be23f12 100644 --- a/src/SCRIPTS/BF/PAGES/pid_advanced.lua +++ b/src/SCRIPTS/BF/PAGES/pid_advanced.lua @@ -11,6 +11,14 @@ local inc = { x = function(val) x = x + val return x end, y = function(val) y = local labels = {} local fields = {} +if apiVersion >= 1.31 then + labels[#labels + 1] = { t = "Angle/Horizon", x = x, y = inc.y(lineSpacing) } + fields[#fields + 1] = { t = "Angle Limit", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 10, max = 90, vals = { 18 } } + if apiVersion < 1.36 then + fields[#fields + 1] = { t = "Stick Sensitivity", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 10, max = 200, vals = { 19 } } + end +end + if apiVersion >= 1.40 then labels[#labels + 1] = { t = "Acro Trainer", x = x, y = inc.y(lineSpacing) } fields[#fields + 1] = { t = "Angle Limit", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 20, max = 80, vals = { 32 } } diff --git a/src/SCRIPTS/BF/PAGES/pos_osd.lua b/src/SCRIPTS/BF/PAGES/pos_osd.lua index 3417ac2f..2e5c2628 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/PAGES/vtx.lua b/src/SCRIPTS/BF/PAGES/vtx.lua index e2a978e0..7c61da3d 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 @@ -13,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/TEMPLATES/480x320.lua b/src/SCRIPTS/BF/TEMPLATES/480x320.lua new file mode 100644 index 00000000..cf01908c --- /dev/null +++ b/src/SCRIPTS/BF/TEMPLATES/480x320.lua @@ -0,0 +1,7 @@ +return { + margin = 5, + indent = 15, + lineSpacing = 22, + listSpacing = { line = 20, field = 170 }, + tableSpacing = { row = 25, col = 60, header = 20 }, +} 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/features.lua b/src/SCRIPTS/BF/features.lua new file mode 100644 index 00000000..c76251cf --- /dev/null +++ b/src/SCRIPTS/BF/features.lua @@ -0,0 +1,8 @@ +local features = { + 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 new file mode 100644 index 00000000..5fe599bd --- /dev/null +++ b/src/SCRIPTS/BF/features_info.lua @@ -0,0 +1,102 @@ +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_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 + elseif cmd == MSP_VTX_CONFIG then + 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 + +local function updateFeatures() + if lastRunTS + INTERVAL < getTime() then + lastRunTS = getTime() + local cmd + 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 and not isInFlight then + protocol.mspRead(cmd) + isInFlight = true + end + end + mspProcessTxQ() + processMspReply(mspPollReply()) + return isGpsRead and isVtxRead and isOsdSDRead +end + +returnTable.f = updateFeatures + +return returnTable 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/pages.lua b/src/SCRIPTS/BF/pages.lua index d1f1e017..4deddf51 100644 --- a/src/SCRIPTS/BF/pages.lua +++ b/src/SCRIPTS/BF/pages.lua @@ -1,7 +1,7 @@ local PageFiles = {} -if apiVersion >= 1.36 then - PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua" } +if apiVersion >= 1.36 and features.vtx then + PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua", init = "PAGES/INIT/vtx.lua" } end if apiVersion >= 1.16 then @@ -37,7 +37,11 @@ if apiVersion >= 1.42 then end if apiVersion >= 1.16 then - PageFiles[#PageFiles + 1] = { title = "System / Motor", script = "pwm.lua" } + PageFiles[#PageFiles + 1] = { title = "System / Motor", script = "pwm.lua", init = "PAGES/INIT/pwm.lua" } +end + +if apiVersion >= 1.41 then + PageFiles[#PageFiles + 1] = { title = "Battery", script = "battery.lua" } end if apiVersion >= 1.16 then @@ -48,11 +52,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 @@ -60,7 +64,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 diff --git a/src/SCRIPTS/BF/radios.lua b/src/SCRIPTS/BF/radios.lua index 13eecaa8..b6d5e22a 100644 --- a/src/SCRIPTS/BF/radios.lua +++ b/src/SCRIPTS/BF/radios.lua @@ -109,7 +109,35 @@ local supportedRadios = } }, }, - ["320x480"] = + ["480x320"] = + { + msp = { + template = "TEMPLATES/480x320.lua", + highRes = true, + MenuBox = { x=120, y=100, w=200, x_offset=68, h_line=20, h_offset=6 }, + SaveBox = { x=120, y=100, w=180, x_offset=12, h=60, h_offset=12 }, + NoTelem = { 192, LCD_H - 28, "No Telemetry", (TEXT_COLOR or 0) + INVERS + BLINK }, + textSize = 0, + yMinLimit = 35, + yMaxLimit = 280, + }, + cms = { + rows = 9, + cols = 32, + pixelsPerRow = 24, + pixelsPerChar = 14, + xIndent = 14, + yOffset = 32, + textSize = MIDSIZE, + refresh = { + event = EVT_VIRTUAL_ENTER, + text = "Refresh: [ENT]", + top = 1, + left = 300, + } + }, + }, + ["320x480"] = { msp = { template = "TEMPLATES/320x480.lua", 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..df45bba1 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -94,9 +94,12 @@ local function createPopupMenu() if apiVersion >= 1.42 then popupMenu[#popupMenu + 1] = { t = "vtx tables", f = function() confirm("CONFIRM/vtx_tables.lua") end } end + if apiVersion >= 1.44 then + popupMenu[#popupMenu + 1] = { t = "board info", f = function() confirm("CONFIRM/pwm.lua") end } + end end -local function processMspReply(cmd,rx_buf) +local function processMspReply(cmd,rx_buf,err) if not Page or not rx_buf then elseif cmd == Page.write then if Page.eepromWrite then @@ -109,6 +112,9 @@ local function processMspReply(cmd,rx_buf) 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 @@ -382,8 +388,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 29ca80ec..c00f0351 100644 --- a/src/SCRIPTS/BF/ui_init.lua +++ b/src/SCRIPTS/BF/ui_init.lua @@ -1,8 +1,7 @@ local apiVersionReceived = false -local vtxTablesReceived = false local mcuIdReceived = false -local boardInfoReceived = false -local getApiVersion, getVtxTables, getMCUId, getBoardInfo +local featuresReceived = false +local getApiVersion, getMCUId, getFeaturesInfo local returnTable = { f = nil, t = "" } local function init() @@ -22,39 +21,20 @@ 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 - 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 - getBoardInfo = getBoardInfo or assert(loadScript("board_info.lua"))() - returnTable.t = getBoardInfo.t - boardInfoReceived = getBoardInfo.f() - if boardInfoReceived then - getBoardInfo = nil + 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 mcuId and featuresReceived end returnTable.f = init diff --git a/src/SCRIPTS/BF/vtx_tables.lua b/src/SCRIPTS/BF/vtx_tables.lua index 2efa8942..13f05265 100644 --- a/src/SCRIPTS/BF/vtx_tables.lua +++ b/src/SCRIPTS/BF/vtx_tables.lua @@ -11,17 +11,30 @@ local requestedBand = 1 local requestedPowerLevel = 1 local vtxTableConfig = {} local frequencyTable = {} -local frequenciesPerBand = 0 local bandTable = {} 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 + -- 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 + 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] diff --git a/src/SCRIPTS/TOOLS/bf.lua b/src/SCRIPTS/TOOLS/bf.lua index 3c4ee8b1..2b42f18b 100644 --- a/src/SCRIPTS/TOOLS/bf.lua +++ b/src/SCRIPTS/TOOLS/bf.lua @@ -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"))()