Skip to content

Commit 10d7f30

Browse files
committed
show device status text while a COMMAND parameter executes
LVGL command popup now renders the live info string the device sends on each CMD_QUERY poll, via a getInfo getter passed into CommandPage (keeps the page decoupled from Protocol). Add a multi-step progress command to the CRSF simulator so the polling status updates can be tested.
1 parent 72b91c2 commit 10d7f30

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

src/SCRIPTS/CRSFSimulator/csrfsimulator.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ local txDevice = {
547547
status = CRSF.CMD_IDLE,
548548
timeout = 50,
549549
info = "",
550+
-- Emits a different status string on each CMD_QUERY poll so the UI can be
551+
-- checked for live status updates while a command is executing.
552+
progress = { "Binding...", "Waiting for RX...", "RX found", "Saving..." },
550553
},
551554

552555
-- Editable string field
@@ -1025,10 +1028,17 @@ local function handleCommandWrite(device, param, newStatus)
10251028
-- Go straight to executing (matches real ELRS firmware behavior:
10261029
-- most commands skip confirmation and execute immediately)
10271030
state.status = CRSF.CMD_EXECUTING
1028-
state.info = "Executing..."
10291031
if param.persistent then
1032+
state.info = "Executing..."
10301033
state.queriesRemaining = nil -- runs until cancelled (e.g., WiFi)
1034+
elseif param.progress then
1035+
-- Step through the status strings, one per CMD_QUERY poll, so the
1036+
-- updated info text from the device can be observed in the UI.
1037+
state.progressIndex = 1
1038+
state.info = param.progress[1]
1039+
state.queriesRemaining = #param.progress
10311040
else
1041+
state.info = "Executing..."
10321042
state.queriesRemaining = COMMAND_EXECUTE_POLLS
10331043
end
10341044
end
@@ -1043,6 +1053,10 @@ local function handleCommandWrite(device, param, newStatus)
10431053
if state.queriesRemaining <= 0 then
10441054
state.status = CRSF.CMD_IDLE
10451055
state.info = "Complete"
1056+
elseif param.progress then
1057+
-- Advance to the next status string for this poll.
1058+
state.progressIndex = (state.progressIndex or 1) + 1
1059+
state.info = param.progress[state.progressIndex] or state.info
10461060
end
10471061
end
10481062
end

src/SCRIPTS/TOOLS/ExpressLRS/ui/lvgl.lua

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ local function createSpinner(parent)
191191
})
192192
end
193193

194-
function CommandPage.showConfirm(name, info, onConfirm, onCancel)
194+
function CommandPage.showConfirm(name, getInfo, onConfirm, onCancel)
195195
lvgl.clear()
196196
local pg = lvgl.page({
197197
title = "ExpressLRS",
@@ -226,7 +226,8 @@ function CommandPage.showConfirm(name, info, onConfirm, onCancel)
226226
w = lvgl.PERCENT_SIZE + 100,
227227
align = CENTER,
228228
color = COLOR_THEME_DISABLED,
229-
text = info or "",
229+
-- Prompt supplied by the caller as a getter so it refreshes each frame
230+
text = getInfo,
230231
},
231232
{
232233
type = lvgl.RECTANGLE,
@@ -261,7 +262,7 @@ function CommandPage.showConfirm(name, info, onConfirm, onCancel)
261262
return pg
262263
end
263264

264-
function CommandPage.showExecuting(title, onCancel)
265+
function CommandPage.showExecuting(title, getInfo, onCancel)
265266
lvgl.clear()
266267
local pg = lvgl.page({
267268
title = "ExpressLRS",
@@ -287,6 +288,21 @@ function CommandPage.showExecuting(title, onCancel)
287288
})
288289
createSpinner(container)
289290
container:build({
291+
{
292+
type = lvgl.RECTANGLE,
293+
w = lvgl.PERCENT_SIZE + 100,
294+
h = lvgl.PAD_LARGE,
295+
thickness = 0,
296+
},
297+
{
298+
-- Live status text the device sends back while the command runs.
299+
-- Supplied by the caller as a getter so each CMD_QUERY poll response is shown.
300+
type = lvgl.LABEL,
301+
w = lvgl.PERCENT_SIZE + 100,
302+
align = CENTER,
303+
font = BOLD,
304+
text = getInfo,
305+
},
290306
{
291307
type = lvgl.RECTANGLE,
292308
w = lvgl.PERCENT_SIZE + 100,
@@ -538,15 +554,20 @@ local function handleCommandPopup()
538554
UI.invalidate()
539555
elseif Protocol.fieldPopup.status == Protocol.CRSF.CMD_ASKCONFIRM then
540556
if not UI.commandDialog or Protocol.fieldPopup.lastStatus ~= Protocol.CRSF.CMD_ASKCONFIRM then
541-
UI.commandDialog = CommandPage.showConfirm(Protocol.fieldPopup.name, Protocol.fieldPopup.info, function()
557+
local field = Protocol.fieldPopup
558+
UI.commandDialog = CommandPage.showConfirm(field.name, function()
559+
return field.info or ""
560+
end, function()
542561
Protocol.commandConfirm()
543562
end, onCommandCancel)
544563
end
545564
Protocol.fieldPopup.lastStatus = Protocol.fieldPopup.status
546565
elseif Protocol.fieldPopup.status == Protocol.CRSF.CMD_EXECUTING then
547566
if not UI.commandDialog or Protocol.fieldPopup.lastStatus ~= Protocol.CRSF.CMD_EXECUTING then
548-
UI.commandDialog =
549-
CommandPage.showExecuting(Protocol.fieldPopup.name or Protocol.fieldPopup.info, onCommandCancel)
567+
local field = Protocol.fieldPopup
568+
UI.commandDialog = CommandPage.showExecuting(field.name, function()
569+
return field.info or ""
570+
end, onCommandCancel)
550571
end
551572
Protocol.fieldPopup.lastStatus = Protocol.fieldPopup.status
552573
end

0 commit comments

Comments
 (0)