Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The tools build on the shared `SCRIPTS/ELRS/` library, which the widgets use too
|--------|---------|
| `SCRIPTS/ELRS/crsf.lua` | CRSF constants, telemetry transport (`pop`/`drain`/`push`), module detection, derived link state (`hasTelemetry`, refreshed as a drain empties the queue), stateless frame decoders (`decodeDeviceInfo`, `decodeElrsStatus`, `isElrsV1Frame`) |
| `SCRIPTS/ELRS/crsf_params.lua` | Opt-in parameter codec: `PARAMETER_SETTINGS_ENTRY` chunk reassembly over a caller-owned rx table and per-type decode, plus encoders that return `PARAMETER_READ`/`WRITE`, command-step and suppress-critical-errors frames for the caller to push. Loaded by the tool and VTX Admin |
| `SCRIPTS/ELRS/crsf_session.lua` | Opt-in stateful parameter client (`CRSFSession.new`, multi-instance): field store, load queue and retry scheduler, paced write queue, command state machine (one step in flight, retried when the radio's single output slot refuses it), and optional device discovery, link status and unsupported-firmware detection (ELRS 1.x, or a TX below 3.5.4). Loaded by the tool and VTX Admin |
| `SCRIPTS/ELRS/crsf_session.lua` | Opt-in stateful parameter client (`CRSFSession.new`, multi-instance): field store, load queue and retry scheduler, paced write queue, command state machine (one step in flight, retried when the radio's single output slot refuses it), a re-read of the folder one level above a write or finished command when the user returns to it (`reloadFolderIfStale`), and optional device discovery, link status and unsupported-firmware detection (ELRS 1.x, or a TX below 3.5.4). Loaded by the tool and VTX Admin |
| `SCRIPTS/ELRS/msp.lua` | Opt-in MSP-over-CRSF codec: stateless encoders returning `(frameType, payload)` for `MSP_REQ`/`MSP_WRITE` and decoders for single-frame v1 `MSP_RESP`, plus the ELRS `RXTX_CONFIG` UID/phrase helpers. Loaded only by the bind tool |
| `SCRIPTS/ELRS/defer.lua` | Single-slot `setTimeout`/`poll` timer; scheduling replaces the pending callback, which is what cancels a stale retry when a new action starts. Loaded only by the bind tool |
| `SCRIPTS/ELRS/ui/lcd/text_edit.lua` | BW text editor replicating the firmware's `editName()` model-name semantics (rotary cycles the char, ENTER advances, long ENTER toggles case or commits on a space). Loaded only by the bind tool's BW UI. `ui/<display>/` is the library's home for shared UI components (single-consumer feature UI lives with its feature, e.g. `vtx/lcd/`), mirroring the tools' own `ui/` split |
Expand Down
21 changes: 20 additions & 1 deletion src/SCRIPTS/CRSFSimulator/csrfsimulator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ local rxDevice = {
serialNo = CRSF.ELRS_SERIAL_ID,
hwVer = 0,
swVer = 0x00040100, -- 4.1.0
fieldCount = 26,
fieldCount = 29,
params = {
{
id = 1,
Expand Down Expand Up @@ -708,6 +708,25 @@ local rxDevice = {
end
end,
},
-- COMMAND that changes a value one folder up (ExpressLRS #3727)
{ id = 27, parent = 19, type = CRSF.INFO, name = "Status", value = "!Level cal." },
{ id = 28, parent = 19, type = CRSF.FOLDER, name = "IMU Calibration" },
{
id = 29,
parent = 28,
type = CRSF.COMMAND,
name = "Level Calibration",
status = CRSF.CMD_IDLE,
timeout = 200,
info = "",
progress = { "Calibrating..." },
onComplete = function(device, findParam)
local s = findParam(device, 27)
if s then
s.value = "Running"
end
end,
},

{
id = 22,
Expand Down
53 changes: 38 additions & 15 deletions src/SCRIPTS/ELRS/crsf_session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function CRSFSession.new(opts)
_refreshLeft = 0,
_refreshAttempts = 0,

_staleFolder = nil, -- folder above the last change; 0 is root

_hadTelemetry = false,
_preloadArmed = nil,
_preloading = nil,
Expand Down Expand Up @@ -384,6 +386,7 @@ function CRSFSession:reloadAll()
self._nextReadAt = 0
self._preloadArmed = self._preload
self._preloading = nil
self._staleFolder = nil
params.resetChunks(self.rx)
end

Expand Down Expand Up @@ -439,6 +442,19 @@ function CRSFSession:preloadAll()
end
end

--- Re-reads the folder's values if a change below left them stale;
--- folderId nil means root.
function CRSFSession:reloadFolderIfStale(folderId)
if self._staleFolder ~= (folderId or 0) then
return
end
self._staleFolder = nil
self:_queueValueFields(folderId)
local settled = self._lastWriteAt + WRITE_SETTLE
self._nextReadAt = getTime() < settled and settled or 0
params.resetChunks(self.rx)
end

--- One-off re-read after delay ticks, attempts default 3; not for polling.
function CRSFSession:refreshField(fieldId, delay, attempts)
self._refreshId = fieldId
Expand All @@ -452,28 +468,35 @@ end
-- Writing
-- ============================================================================

-- Parent name may embed values; siblings can hide or change options
function CRSFSession:_reloadRelated(field)
if field.parent and self._fields[field.parent] then
self._fields[field.parent].nameStale = true
self._loadQueue[#self._loadQueue + 1] = field.parent
end

-- parent nil means root.
function CRSFSession:_queueValueFields(parent, exceptId)
for fieldId = self.fieldsCount, 1, -1 do
local sibling = self._fields[fieldId]
if sibling and fieldId ~= field.id and sibling.parent == field.parent then
local siblingType = sibling.type or 99
local child = self._fields[fieldId]
if child and fieldId ~= exceptId and child.parent == parent then
local childType = child.type or 99
if
siblingType < crsf.CONST.FIELD_FOLDER
or siblingType == crsf.CONST.FIELD_INFO
or siblingType == crsf.CONST.FIELD_COMMAND
childType < crsf.CONST.FIELD_FOLDER
or childType == crsf.CONST.FIELD_INFO
or childType == crsf.CONST.FIELD_COMMAND
then
sibling.dirty = true
sibling.reloading = true
child.dirty = true
child.reloading = true
self._loadQueue[#self._loadQueue + 1] = fieldId
end
end
end
end

-- Parent name may embed values; siblings can hide or change options
function CRSFSession:_reloadRelated(field)
local parent = field.parent and self._fields[field.parent]
if parent then
parent.nameStale = true
self._loadQueue[#self._loadQueue + 1] = field.parent
self._staleFolder = parent.parent or 0
end

self:_queueValueFields(field.parent, field.id)

field.dirty = true
field.reloading = true
Expand Down
6 changes: 5 additions & 1 deletion src/SCRIPTS/TOOLS/ExpressLRS/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ function App.enterFolder(folderId, folderName, viewState)
end

function App.goBack()
return Navigation.goBack()
local entry = Navigation.goBack()
if entry and entry.type == Navigation.TYPE_FOLDER then
session:reloadFolderIfStale(Navigation.getCurrent())
end
return entry
end

function App.reloadAtRoot()
Expand Down
Loading