refactor: replace Ui::tick()'s timeout if-chain with a data table - #13
Merged
Conversation
CLAUDE.md flags tick()'s timeout handling as the one place in ui.cpp's
four-way State sync that a plain if-chain, not a switch, so the compiler
can't catch a State that should time out but has no entry. Replaced the
eleven near-identical if-blocks with a small TimeoutEntry table ({State,
timeoutMs, optional action}) and a single loop, so adding a timed state is
now one row instead of a copy-pasted block that's easy to get subtly wrong.
BootChannelSelect keeps its distinct action (confirmBootChannel instead of
enterIdle) via the table's optional action function pointer.
DismissPrompt's extra per-tick candidate-refresh logic (not a timeout) stays
exactly where it was, unfolded into the table on purpose. Idle/RangeTest/
Charging remain absent, same as before.
Behavior is unchanged -- this is a pure refactor, verified by inspection
(every {state, timeout, action} triple carried over unmodified) plus a
clean build and the full native test suite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDE.mdflagstick()'s timeout handling as the one place inui.cpp's four-wayStatesync that's a plainif-chain, not aswitch— so the compiler can't catch aStatethat should time out but has no entry yet. Replaced the eleven near-identicalif-blocks with a smallTimeoutEntrytable ({State, timeoutMs, optional action}) and a single loop, so adding a timed state going forward is one row instead of a copy-pasted block that's easy to get subtly wrong (wrong variable, missedneedsRender, ...).BootChannelSelectkeeps its distinct action (confirmBootChannelinstead ofenterIdle) via the table's optional action function pointer.DismissPrompt's extra per-tick candidate-refresh logic (not a timeout — it runs unconditionally every tick while the prompt is open) stays exactly where it was, deliberately not folded into the table.Idle/RangeTest/Chargingremain absent, same as before (see the new comment above the table for why).Behavior is unchanged — every
{state, timeout, action}triple was carried over unmodified; this is a pure refactor.Test plan
pio run— builds cleanpio test -e native— 61/61 pass