From b7b5a9753f67a0b49bfea415fcefef9459b5c7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=96Raphael=20Hunziker?= Date: Wed, 26 Aug 2026 17:40:42 +0200 Subject: [PATCH] Store 20 bind phrases and scroll the history list The history was capped at 5 entries, and the cap was on the stored data rather than the display: adding a sixth phrase silently dropped the oldest one from history.txt. Anyone managing a larger fleet loses phrases that are still in use and has to retype them. Show the history through a scrolling window of History.PAGE (5) rows so the on-screen footprint no longer depends on how much is stored, which is what forced the low cap in the first place. With that decoupled, raise the stored limit to 20. Up/Down buttons move the window a page at a time and are only shown when the history is longer than one page. A label shows the current position. Co-Authored-By: Claude Opus 5 --- src/SCRIPTS/TOOLS/elrs-bind/main.lua | 77 ++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/SCRIPTS/TOOLS/elrs-bind/main.lua b/src/SCRIPTS/TOOLS/elrs-bind/main.lua index 65214c7..eab5b05 100644 --- a/src/SCRIPTS/TOOLS/elrs-bind/main.lua +++ b/src/SCRIPTS/TOOLS/elrs-bind/main.lua @@ -42,11 +42,15 @@ function Defer.poll() end local History = { - MAX = 5, + MAX = 20, + PAGE = 5, FNAME = "history.txt", vals = {}, } +-- Index of the first history entry shown; scrolls in steps of History.PAGE +local histOffset = 0 + function History.add(s) if s == nil or s == "" then return @@ -65,6 +69,9 @@ function History.add(s) table.remove(History.vals) end + -- a new entry goes to the top of the list, make sure it is on screen + histOffset = 0 + History.save() end @@ -276,18 +283,45 @@ local function sendBindRx() end local rebuildUi + +-- Keep the scroll window inside the bounds of the current history +local function history_clampOffset() + local maxOffset = #History.vals - History.PAGE + if maxOffset < 0 then + maxOffset = 0 + end + if histOffset > maxOffset then + histOffset = maxOffset + end + if histOffset < 0 then + histOffset = 0 + end +end + local function history_text(id) - return History.vals[id] + return History.vals[id + histOffset] end local function history_visible(id) return history_text(id) ~= nil end local function history_press(id) - bindPhrase = History.vals[id] + bindPhrase = History.vals[id + histOffset] rebuildUi() end local function history_remove(id) - History.remove(id) + History.remove(id + histOffset) + history_clampOffset() +end +local function history_scroll(delta) + histOffset = histOffset + delta + history_clampOffset() +end +local function history_position() + local last = histOffset + History.PAGE + if last > #History.vals then + last = #History.vals + end + return string.format("%d-%d / %d", histOffset + 1, last, #History.vals) end rebuildUi = function() @@ -425,7 +459,7 @@ rebuildUi = function() w = lvgl.PERCENT_SIZE + 100, align = CENTER, }) - for i = 1, History.MAX do + for i = 1, History.PAGE do local row = histSection:box({ w = lvgl.PERCENT_SIZE + 100, flexFlow = lvgl.FLOW_ROW, @@ -453,6 +487,39 @@ rebuildUi = function() end, }) end + + -- Scroll controls, only shown when the history is longer than one page + local navRow = histSection:box({ + w = lvgl.PERCENT_SIZE + 100, + flexFlow = lvgl.FLOW_ROW, + flexPad = lvgl.PAD_SMALL, + visible = function() + return #History.vals > History.PAGE + end, + }) + navRow:button({ + text = "Up", + press = function() + return history_scroll(-History.PAGE) + end, + active = function() + return histOffset > 0 + end, + }) + navRow:button({ + text = "Down", + press = function() + return history_scroll(History.PAGE) + end, + active = function() + return histOffset + History.PAGE < #History.vals + end, + }) + navRow:label({ + text = function() + return history_position() + end, + }) end local function init()