From b604cd8830c8dba100b1e109135534a5133bfda8 Mon Sep 17 00:00:00 2001 From: Jesper Frickmann Date: Thu, 24 Nov 2022 02:19:09 -0500 Subject: [PATCH] SoarETX for 2.8 (#88) * Workaround for the bug sending EVT_VIRTUAL_ENTER_LONG to Lua during scrolling in ETX 2.8 * Adjustment to different space character width in ETX 2.8 * Moved battery check to main, because of bug in ETX not running top bar widget background() when another widget is fullscreen. * It seems like it is using a stale sensor ID after model change, so update sensor ID before every read --- sdcard/c480x272/WIDGETS/LibGUI/libgui.lua | 8 +++- sdcard/c480x272/WIDGETS/SoarETX/1/battery.lua | 45 +----------------- sdcard/c480x272/WIDGETS/SoarETX/1/f3k.lua | 12 ++--- sdcard/c480x272/WIDGETS/SoarETX/main.lua | 46 ++++++++++++++++++- 4 files changed, 58 insertions(+), 53 deletions(-) diff --git a/sdcard/c480x272/WIDGETS/LibGUI/libgui.lua b/sdcard/c480x272/WIDGETS/LibGUI/libgui.lua index 945bb134..b42c069a 100644 --- a/sdcard/c480x272/WIDGETS/LibGUI/libgui.lua +++ b/sdcard/c480x272/WIDGETS/LibGUI/libgui.lua @@ -2,8 +2,8 @@ -- The dynamically loadable part of the shared Lua GUI library. -- -- -- -- Author: Jesper Frickmann -- --- Date: 2022-05-05 -- --- Version: 1.0.1 -- +-- Date: 2022-11-20 -- +-- Version: 1.0.2 -- -- -- -- Copyright (C) EdgeTX -- -- -- @@ -292,6 +292,10 @@ function lib.newGUI() event = EVT_TOUCH_TAP end end + -- ETX 2.8 rc 4 bug fix + if scrolling and event == EVT_VIRTUAL_ENTER_LONG then + return + end -- If we put a finger down on a menu item and immediately slide, then we can scroll if event == EVT_TOUCH_SLIDE then if not scrolling then diff --git a/sdcard/c480x272/WIDGETS/SoarETX/1/battery.lua b/sdcard/c480x272/WIDGETS/SoarETX/1/battery.lua index 824beb36..3c0a15b4 100644 --- a/sdcard/c480x272/WIDGETS/SoarETX/1/battery.lua +++ b/sdcard/c480x272/WIDGETS/SoarETX/1/battery.lua @@ -2,8 +2,8 @@ -- SoarETX, loadable component -- -- -- -- Author: Jesper Frickmann -- --- Date: 2022-02-17 -- --- Version: 1.0.0 -- +-- Date: 2022-11-21 -- +-- Version: 1.0.1 -- -- -- -- Copyright (C) EdgeTX -- -- -- @@ -21,48 +21,7 @@ local widget, soarGlobals = ... --- Battery variables -local rxBatSrc -local rxBatNxtWarn = 0 - -local function getWarningLevel() - return 0.1 * (soarGlobals.getParameter(soarGlobals.batteryParameter) + 100) -end - -function widget.background() - local now = getTime() - - -- Receiver battery - if not rxBatSrc then - rxBatSrc = getFieldInfo("Cels") - if not rxBatSrc then rxBatSrc = getFieldInfo("RxBt") end - if not rxBatSrc then rxBatSrc = getFieldInfo("A1") end - if not rxBatSrc then rxBatSrc = getFieldInfo("A2") end - end - - if rxBatSrc then - soarGlobals.battery = getValue(rxBatSrc.id) - - if type(soarGlobals.battery) == "table" then - for i = 2, #soarGlobals.battery do - soarGlobals.battery[1] = math.min(soarGlobals.battery[1], soarGlobals.battery[i]) - end - soarGlobals.battery = soarGlobals.battery[1] - end - end - - -- Warn about low receiver battery or Rx off - if now > rxBatNxtWarn and soarGlobals.battery > 0 and soarGlobals.battery < getWarningLevel() then - playHaptic(200, 0, 1) - playFile("lowbat.wav") - playNumber(10 * soarGlobals.battery + 0.5, 1, PREC1) - rxBatNxtWarn = now + 2000 - end -end -- background() - function widget.refresh(event, touchState) - widget.background() - if event then lcd.exitFullScreen() end diff --git a/sdcard/c480x272/WIDGETS/SoarETX/1/f3k.lua b/sdcard/c480x272/WIDGETS/SoarETX/1/f3k.lua index e431bc0d..5aa83672 100644 --- a/sdcard/c480x272/WIDGETS/SoarETX/1/f3k.lua +++ b/sdcard/c480x272/WIDGETS/SoarETX/1/f3k.lua @@ -2,8 +2,8 @@ -- SoarETX F3K score keeper, loadable component -- -- -- -- Author: Jesper Frickmann -- --- Date: 2022-03-08 -- --- Version: 1.0.0 -- +-- Date: 2022-11-20 -- +-- Version: 1.0.1 -- -- -- -- Copyright (C) EdgeTX -- -- -- @@ -631,7 +631,7 @@ function libGUI.widgetRefresh() for i = 1, taskScores do lcd.drawText(COL1, y, string.format("%i.", i), colors.primary1 + DBLSIZE) if i > #scores then - lcd.drawText(COL2, y, " - - -", colors.primary1 + DBLSIZE) + lcd.drawText(COL2, y, "- - -", colors.primary1 + DBLSIZE) else lcd.drawTimer(COL2, y, scores[i], colors.primary1 + DBLSIZE) end @@ -918,14 +918,14 @@ do -- Setup score keeper screen for F3K and Practice tasks local s = screenTask.timer(LEFT + 40, y, 60, HEIGHT, 0, nil) s.disabled = true - s.value = " - - -" + s.value = "- - -" screenTask.scores[i] = s -- Modify timer's draw function to insert score value local draw = s.draw function s.draw(idx) if i > #scores then - screenTask.scores[i].value = " - - -" + screenTask.scores[i].value = "- - -" else screenTask.scores[i].value = scores[i] end @@ -1124,7 +1124,7 @@ do -- Setup score browser screen lcd.drawText(x, y, j .. ".") if j > #record.scores then - lcd.drawText(x + 18, y, " - - -") + lcd.drawText(x + 18, y, "- - -") elseif record.unitStr == "s" then lcd.drawTimer(x + 18, y, record.scores[j]) else diff --git a/sdcard/c480x272/WIDGETS/SoarETX/main.lua b/sdcard/c480x272/WIDGETS/SoarETX/main.lua index 6df8b1fa..f1006570 100644 --- a/sdcard/c480x272/WIDGETS/SoarETX/main.lua +++ b/sdcard/c480x272/WIDGETS/SoarETX/main.lua @@ -2,8 +2,8 @@ -- SoarETX widget -- -- -- -- Author: Jesper Frickmann -- --- Date: 2022-02-08 -- --- Version: 1.0.0 -- +-- Date: 2022-11-22 -- +-- Version: 1.0.1 -- -- -- -- Copyright (C) EdgeTX -- -- -- @@ -23,8 +23,48 @@ local options = { { "Version", VALUE, 1, 1, 99 }, { "FileName", STRING, "" } } + local soarGlobals +-- Battery - moved here from battery.lua because of bugs in ETX not calling background() on topbar widgets +local rxBatNxtWarn = 0 +local rxBatNxtCheck = 0 + +function rxBatCheck() + local now = getTime() + + if now < rxBatNxtCheck then + return + end + + rxBatNxtCheck = now + 100 + + local rxBatSrc = getFieldInfo("Cels") + if not rxBatSrc then rxBatSrc = getFieldInfo("RxBt") end + if not rxBatSrc then rxBatSrc = getFieldInfo("A1") end + if not rxBatSrc then rxBatSrc = getFieldInfo("A2") end + + if rxBatSrc then + soarGlobals.battery = getValue(rxBatSrc.id) + + if type(soarGlobals.battery) == "table" then + for i = 2, #soarGlobals.battery do + soarGlobals.battery[1] = math.min(soarGlobals.battery[1], soarGlobals.battery[i]) + end + soarGlobals.battery = soarGlobals.battery[1] + end + end + + -- Warn about low receiver battery + local rxBatMin = 0.1 * (soarGlobals.getParameter(soarGlobals.batteryParameter) + 100) + if now > rxBatNxtWarn and soarGlobals.battery > 0 and soarGlobals.battery < rxBatMin then + playHaptic(200, 0, 1) + playFile("lowbat.wav") + playNumber(10 * soarGlobals.battery + 0.5, 1, PREC1) + rxBatNxtWarn = now + 2000 + end +end -- rxBatCheck() + -- Load a Lua component dynamically based on option values local function Load(widget) local chunk, errMsg = loadScript(soarGlobals.path .. widget.options.Version .. "/" .. widget.options.FileName .. ".lua") @@ -109,6 +149,8 @@ local function refresh(widget, event, touchState) end local function background(widget) + rxBatCheck() + if widget.background then widget.background() end