Skip to content

refactor: replace Ui::tick()'s timeout if-chain with a data table - #13

Merged
bin101 merged 1 commit into
mainfrom
refactor/ui-tick-timeouts
Jul 23, 2026
Merged

refactor: replace Ui::tick()'s timeout if-chain with a data table#13
bin101 merged 1 commit into
mainfrom
refactor/ui-tick-timeouts

Conversation

@bin101

@bin101 bin101 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

CLAUDE.md flags tick()'s timeout handling as the one place in ui.cpp's four-way State sync that's a plain if-chain, not a switch — so the compiler can't catch a State that should time out but has no entry yet. 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 going forward is one row instead of a copy-pasted block that's easy to get subtly wrong (wrong variable, missed needsRender, ...).

  • 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 — it runs unconditionally every tick while the prompt is open) stays exactly where it was, deliberately not folded into the table.
  • Idle/RangeTest/Charging remain 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 clean
  • pio test -e native — 61/61 pass
  • Manual inspection: diffed every original if-block against its table row to confirm no timeout/action/state was dropped or altered
  • On-hardware: spot-check a couple of the timed menus (e.g. Tone menu, Settings menu) still auto-return to Idle after the expected duration

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.
bin101 added a commit that referenced this pull request Jul 23, 2026
fix: bundle review findings from PRs #9-#13 into one release
@bin101
bin101 merged commit 75718f4 into main Jul 23, 2026
2 checks passed
@bin101
bin101 deleted the refactor/ui-tick-timeouts branch July 23, 2026 16:25
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.

1 participant