Skip to content

Live viz: the channel visualizer mirrors the real strip (3/7) - #44

Merged
bring42 merged 4 commits into
mainfrom
claude/pr3-live-viz-readback
Sep 12, 2026
Merged

bring42 merged 4 commits into
mainfrom
claude/pr3-live-viz-readback

Conversation

@bring42

@bring42 bring42 commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

Stacked PR — part 3 of 7. Merge in order (1 → 7) using a merge commit, not squash: the per-commit messages are the documentation, and squashing would also break the PRs stacked on top. Split from claude/next-goal-notes-merge-prep-6bb680; the top of the stack is byte-identical to that branch.

What

The channel visualizer mirrors the real strip.

  • Bug: the viz approximated effects from their color/palette params, and every premium mode has neither, so all 13 rendered as a hardcoded cyan gradient.
  • Fix: new GET /api/v2/pixels returns the strip's current perceptual output (pre-gamma, so it looks right on a screen), and the UI paints it at ~10 Hz. A new effect needs zero viz code, ever.
  • The endpoint is auth-gated like every other /api/v2 read. Its heap budget comment is corrected (~15 KB peak at 1000 LEDs).
  • The viz glow and FPS readout no longer go stale when the stream drops.
  • Review follow-up: the FPS readout no longer reads ~10% high in its first window or shows "0" after a resume. The API doc now says the endpoint returns 401 when the token is omitted or wrong.

Review notes

  • A native test proves the readback is perceptual/pre-gamma rather than the gamma-encoded wire bytes.
  • Showing raw sources (sACN, /api/pixels overlays) correctly in the viz lands in part 7.

Verification

Built and tested on this branch alone. This stacked state is new, so it was verified independently rather than assumed: 81/81 native tests pass, the firmware builds for seeed_xiao_esp32c3 (91.0% of the app partition), and the web UI JS passes node --check.

Also verified on hardware (XIAO ESP32-C3 + WS2812B): the endpoint streams the strip's real output.

🤖 Generated with Claude Code


The stack (merge top to bottom):

  1. Premium render substrate + 13 premium modes (1/7) #42 — Premium render substrate + 13 premium modes (1/7)
  2. Web UI: data/ as the single source of truth (2/7) #43 — Web UI: data/ as the single source of truth (2/7)
  3. Live viz: the channel visualizer mirrors the real strip (3/7) #44 — Live viz: the channel visualizer mirrors the real strip (3/7)
  4. WiFi observability: stop failing silently (4/7) #45 — WiFi observability: stop failing silently (4/7)
  5. 4 MB partition table: 1.75 MB A/B app slots (5/7) #46 — 4 MB partition table: 1.75 MB A/B app slots (5/7)
  6. AI prompt pipeline: key save, live model, honest outcomes (6/7) #47 — AI prompt pipeline: key save, live model, honest outcomes (6/7)
  7. Core hardening from the external review (7/7) #48 — Core hardening from the external review (7/7)

benno6 and others added 4 commits September 12, 2026 18:08
The channel visualizer approximated effects from their color/palette params —
and every premium mode is self-contained (no color params, no palette), so all
13 fell through to a hardcoded cyan gradient. Instead of per-effect viz hints
(which would re-couple effects to the UI), the device now reports its actual
output and the viz just paints it — a new effect needs zero viz code, ever.

Firmware:
- LumeController::copyVizPixels() exposes the PERCEPTUAL frame (smooth_ —
  post master-brightness/power-fade/dim-to-warm, pre gamma/WS2812B/dither).
  That's the screen-ready choice: leds[] holds gamma-encoded wire bytes that
  an sRGB display would double-gamma. Unsynchronized read-only access from
  the web task by design (a torn pixel is one frame of viz noise; P0.1's
  single-writer rule untouched).
- GET /api/v2/pixels → {"count":N,"rgb":"rrggbb…"} (hex triplet per pixel,
  physical order, no auth — matches the other GETs). Documented in API_V2.md.

Web UI:
- engine.fetchPixels() → Uint8Array|null (null in demo/unreachable);
  documented in ENGINE_API.md.
- app.js: chained single-flight ~10 Hz poll while the tab is visible and a
  channel is selected; vizTick paints the segment's real window, derives the
  glow from the strip average, and shows the true stream rate instead of the
  fake 42 FPS. Demo/unreachable falls back to the old procedural stand-in,
  whose no-color fallback is now a warm ember drift instead of cyan.
- dev_server.js mocks the endpoint (animated warm wave) to stay faithful.

Verified: new native test proves the readback is perceptual + pre-gamma and
clamps (28/28 pass); C3 firmware builds; browser run against the dev server
shows live streaming on CH1/CH2 windows, power-off, and zero console errors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The endpoint shipped unauthenticated on the claim that it "matches the
other GET endpoints". It does not: the unauthenticated GETs are the v1
routes (/api/status, /api/config, /api/nightlight) plus effects/palettes,
while every /api/v2 read — segments list and get, info, controller —
calls checkAuth. This was the one v2 read that leaked live state (the
strip's actual output, pollable at ~10 Hz) to anyone on the LAN once an
authToken was configured.

checkAuth is a pass-through when no token is set, so the default setup is
unaffected. Note the stock web UI sends no token, so configuring one
already disables the rest of the v2 read surface for it — this makes the
viz consistent with that, rather than a hole in it. Documented in
API_V2.md, including that caveat.

Also corrects the heap comment, which claimed ~9 KB transient at
MAX_LED_COUNT. AsyncWebServer copies the String in request->send(), so the
real peak is ~15 KB (3 KB frame + ~6 KB String + ~6 KB copy) — still
comfortable against the C3's ~93 KB free heap, and ~2.5 KB at the 160-LED
default, but the old figure would have misled future heap budgeting.
Two cosmetic defects in the channel visualizer, both from the live-stream
work earlier in this PR (the /api/v2/pixels readback commit).

- Stale glow: when a live pixel stream dropped (device unreachable), the
  stand-in and powered-off branches of vizTick never repainted #vizGlow,
  and renderVisualizer only repaints it on an engine "change" event, which
  may never arrive with the device down. The last strip-average glow could
  therefore persist indefinitely behind the procedural fallback. Both
  branches now repaint — the stand-in from the segment swatch, powered-off
  to none.

- FPS counter: fpsAt started at 0, so the first computed rate divided by
  time-since-page-load and read far too low; and `frames` was not cleared
  when the stream paused, understating the rate for one window after a
  resume. Added vizStreamIdle() to reset the counter whenever the stream
  isn't live, and fpsAt is now seeded on the first real frame.

Verified in the browser against the mock device: page renders, no console
errors, and engine.fetchPixels() parses to the exact expected length
(900 bytes for 300 px) with the first triplet matching the source hex.
Two cosmetic follow-ups from review of the viz glow/FPS fix.

- The frame that seeds the measuring window was also counted in it, so
  the first reading after every resume was ~10% high (11 frames in a
  1000 ms window at 10 Hz). The seed frame now only opens the window.
- The stream-idle reset zeroes the rate, so the readout showed "0" for
  about a second after every tab return, channel reselect or single
  failed fetch. It now shows "—" until the first window closes.
- docs/API_V2.md: the pixels endpoint returns 401 when the token is
  omitted or wrong; the doc only said "omits".

Verified: node --check passes; asset stamps regenerated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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