Skip to content

Backlight timeout + context-sensitive button - #2

Merged
varffs merged 9 commits into
masterfrom
feature/backlight-timeout
Jul 26, 2026
Merged

Backlight timeout + context-sensitive button#2
varffs merged 9 commits into
masterfrom
feature/backlight-timeout

Conversation

@varffs

@varffs varffs commented Jul 25, 2026

Copy link
Copy Markdown
Owner

LCD backlight now sleeps after 30 s. Button becomes context-sensitive: first press when dark wakes the backlight (mode untouched); presses while lit cycle DEFAULT ↔ DIAG and reset the timeout. Sleep resets mode to DEFAULT so a wake always shows main readings. Boot dispatches one buttonPress — startup behaves exactly like a first press (lit, timer armed).

How

  • Reducer owns press semantics (display/buttonPress, display/sleep) — pure, tested. display/next retired.
  • Timer is an RTK listener (src/backlight.js): cancelActiveListeners()delay(30s)sleep().
  • Edge-triggered listener syncs isBacklit to display.setBacklight() — fires only on change, no per-render I2C writes. No piteknix changes (both drivers already support setBacklight).

Testing

  • 31/31 unit + integration tests (real store + listener middleware, injected short timeouts).
  • Live virtual-mode smoke test: boot lit → dark after 30 s → press wakes → press cycles to DIAG → clean quit.
  • Whole-branch review clean (spec + quality per task, final review "ready to merge").

Spec: docs/superpowers/specs/2026-07-25-backlight-timeout-design.md · Plan: docs/superpowers/plans/2026-07-25-backlight-timeout.md

Backlog noted for follow-ups: rename sleep creator (collides with delay-helper idiom), move backlight-sync listener into src/backlight.js for coverage, GPIO err handling in button.watch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LWqqCXSnLqjh5WMDzPxSgy

varffs and others added 7 commits July 25, 2026 23:51
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an LCD backlight auto-sleep feature with context-sensitive button behavior, implemented via a reducer-owned action semantic (display/buttonPress, display/sleep) plus RTK listener middleware to manage the timeout and hardware backlight syncing.

Changes:

  • Replace display/next with display/buttonPress/display/sleep reducer semantics (wake when dark; cycle mode when lit; sleep resets to DEFAULT).
  • Add registerBacklightTimeout listener middleware to dispatch sleep() after a configurable timeout, canceling/re-arming on every press.
  • Wire the feature into app.js (render predicate broadened to display/*, backlight sync listener added, boot dispatch, and button handler updated) and document it (spec/plan/changelog).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/store.test.js Updates reducer tests for new buttonPress/sleep semantics.
src/store.js Implements display/buttonPress and display/sleep; removes display/next.
src/config.test.js Asserts new backlightTimeoutMs config field.
src/config.js Adds backlightTimeoutMs: 30000 to runtime config.
src/backlight.test.js Adds integration tests for listener-driven backlight timeout behavior.
src/backlight.js Introduces RTK listener that arms/cancels a sleep timer on buttonPress.
docs/superpowers/specs/2026-07-25-backlight-timeout-design.md Adds design spec for the behavior and architecture.
docs/superpowers/plans/2026-07-25-backlight-timeout.md Adds implementation plan documenting the intended wiring and tests.
CHANGELOG.md Adds an Unreleased entry describing the feature.
app.js Wires new actions and listeners into the running app (render predicate, backlight sync, timeout registration, boot press, button handler).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app.js
Comment thread app.js
Copilot review: boot buttonPress was dispatched after the initial
pollAll, so a slow/hung 1-wire read delayed arming the 30s sleep
timer. Now dispatched right after configureStore — spec doc wording
updated to match. Tests 31 pass; virtual boot smoke shows lit frames.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/backlight.test.js:33

  • This timeout-reset test also relies on very small real-time windows (50ms with 30/30/40 waits). If the second buttonPress() is delayed past the first 50ms window, the backlight could sleep before the reset press runs, making the test nondeterministic. Increasing the intervals keeps the same logic while making the test robust on slower machines.
test("a press mid-window resets the timeout", async () => {
  const store = makeStore(50);
  store.dispatch(buttonPress());          // lit, timer armed
  await wait(30);
  store.dispatch(buttonPress());          // lit -> cycles mode, re-arms timer
  await wait(30);                         // 60ms after first press, 30ms after second
  assert.equal(store.getState().display.isBacklit, true, "reset should have kept it lit");

Comment thread src/backlight.test.js
Comment thread src/backlight.test.js
Comment thread app.js
Copilot review round 2: real-timer windows widened 4x (same ratios,
per plan's flake recipe) so loaded machines can't skew assertions;
mode-cycle test now waits out its armed timer instead of leaving a
pending listener at suite end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@varffs
varffs merged commit 48c027b into master Jul 26, 2026
1 check passed
@varffs
varffs deleted the feature/backlight-timeout branch July 26, 2026 13:41
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.

2 participants