Skip to content

Fix immediate command polling when the device sends timeout 0 - #33

Merged
jurgelenas merged 1 commit into
unified-lua-lspfrom
command-timeout-zero
Oct 2, 2026
Merged

jurgelenas merged 1 commit into
unified-lua-lspfrom
command-timeout-zero

Conversation

@jurgelenas

Copy link
Copy Markdown
Member

Fixes #16. Supersedes #20 (rebased on the current unified-lua-lsp; diagnosis by @Itay-Sharoni).

The next CMD_QUERY is armed with now + (command.timeout or 100). In Lua 0 is truthy, so a device that sends timeout = 0 is polled on every tick. execCommand now waits _responseTimeout() before the first poll, but the answer to CLICK re-arms the poll in _onEntry at now + 0, so the POLL can still reach the device before its CONFIRMATION_NEEDED is back. The device answers READY and the confirm dialog never shows.

Treat 0 like a missing timeout and poll once per second. Devices sending a real timeout (ELRS sends 200) are unaffected.

Checked in the simulator (GX12) with the CRSFSimulator Bind command set to timeout = 0:

CLICK CMD_QUERY polls
before t=7398 7408, 7418, 7428, 7438 — every 100 ms, first 100 ms after the click
after t=13705 13815, 13925, 14036, 14146 — ~1 s apart

No device with timeout 0 here — @wimalopaan, can you verify on yours?

The next CMD_QUERY is armed with now + (command.timeout or 100). 0 is
truthy in Lua, so a device that sends timeout 0 is polled on every
tick. The answer to CLICK re-arms the poll at now + 0, overriding the
response timeout execCommand set, and the POLL can reach the device
before its CONFIRMATION_NEEDED is back. The device answers READY and
the confirm dialog never shows (#16).

Treat 0 like a missing timeout and poll once per second.

Co-authored-by: Itay Sharoni <[email protected]>
@wimalopaan

Copy link
Copy Markdown

This also looks good now (well, the finishing text isn't shown, but that is fixed in #36).
Many thanks for fixing this!

@CapnBry CapnBry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

I will say that pushing a single-use constant into the module's locals means that the function then needs an upval object and pointer to access it which is like 30 bytes of RAM in addition to the value itself. It's good programming style to have named "constants" for things but in limited environments, not necessarily worth the cost of keeping it all in RAM all the time.

Not requesting a change but in general this should be avoided.

@jurgelenas
jurgelenas merged commit 9e57b9f into unified-lua-lsp Oct 2, 2026
@jurgelenas
jurgelenas deleted the command-timeout-zero branch October 4, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants