feat: browser simulator served by the controller, desktop build, browser bridge

- led-simulator: the rig runs the C++ led-driver as WebAssembly (sim-driver/),
  one single-threaded worker per bar, no cross-origin isolation needed. Rooms
  (one JSON per room) with an on-page editor, and a pattern gallery. The
  Python server, Pyodide boot and ring buffer are removed.
- sim-controller sim_rig.c: serves /sim/ from an embedded pack, the page's
  WebSocket and the rooms/flash API. The desktop build embeds it too.
- bridge.c: a "browser" bridge kind that carries ESP-NOW frames to the page;
  devices announced through it are marked sim.
- UI: Simulator in the Menu, split view with resize and pop-out, swipe
  between controller and rig on phones; SIM/REAL badges in Devices.
- Fades: preset pushes and Wi-Fi driver bodies always carry fade and
  beat_time, so "off" no longer inherits an earlier fade.
- Also the sequences-v2 work in progress: desktop port, bridge firmware,
  serial bridge, Wi-Fi drivers, sequence timeline, audio and API changes.
- led-driver: ESP-NOW link, beat sync, control messages, sim hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-16 19:32:46 +13:00
1 parent 698c1463c0
commit 581b751904
506 files changed
+42336 -3599

No files matched your search

+62 -84
View File
@@ -1,103 +1,81 @@
/* Rig geometry for the canvas: strips along their rows, pixel 0 at the
* strip's start end (next to the centre line for start: "center").
* Strip placement (row, col, reversed) comes from the server (layout.py).
/* Room geometry for the canvas: metres <-> canvas pixels, and where each strip's LEDs are.
*
* A room (rooms/<name>.json, see rooms.py) spans x -width/2..width/2 and y 0..depth, metres,
* y up on screen. A fixture's x, y is pixel 0; the strip runs along `direction` (degrees clockwise
* from +y) for leds x pitch_m metres. roomStrips() mirrors rooms.room_strips() on the server.
*/
(function (g) {
'use strict';
/**
* @param {object} layout {rows, columns, leds_per_strip}
* @param {Array} strips [{row, col, leds, reversed}]
* @returns {object} {ledPitch, ledW, ledH, strips:[{x0, y, w, labelX, labelY, labelAlign}], centreLines}
*/
function computeGeometry(layout, strips, width, height, opts = {}) {
const margin = opts.margin ?? 16;
const colGap = opts.colGap ?? 32;
const labelH = opts.labelH ?? 16;
const rows = layout.rows;
const cols = layout.columns;
const n = layout.leds_per_strip;
const usableW = Math.max(cols * n, width - 2 * margin - (cols - 1) * colGap);
const colW = usableW / cols;
const pitch = colW / n;
const rowH = Math.max(labelH + 6, (height - 2 * margin) / rows);
const ledH = Math.max(6, Math.min(rowH - labelH - 10, 18));
const gap = pitch >= 3 ? 1 : 0;
const ledW = Math.max(1, pitch - gap);
function fixtureLeds(room, f) {
return Number(f.leds) || room.definitions[f.def].leds;
}
const out = strips.map((s) => {
const x0 = margin + s.col * (colW + colGap);
const yTop = margin + s.row * rowH;
// strip sits just under its label; leftover row space goes below it
const y = yTop + labelH + 4;
function fixtureEnd(room, f) {
const len = fixtureLeds(room, f) * room.definitions[f.def].pitch_m;
const a = (f.direction * Math.PI) / 180;
return [f.x + len * Math.sin(a), f.y + len * Math.cos(a)];
}
/** One entry per fixture, in file order. */
function roomStrips(room) {
return Object.entries(room.fixtures).map(([id, f], i) => {
const [x1, y1] = fixtureEnd(room, f);
return {
x0,
y,
w: colW,
h: ledH,
top: yTop,
rowH,
reversed: Boolean(s.reversed),
labelX: s.reversed ? x0 + colW : x0,
labelY: yTop + labelH / 2 + 2,
labelAlign: s.reversed ? 'right' : 'left',
index: i,
n: i + 1,
id,
label: f.label,
mac: f.mac,
leds: fixtureLeds(room, f),
x: f.x,
y: f.y,
x1,
y1,
direction: f.direction,
};
});
const centreLines = [];
for (let c = 1; c < cols; c += 1) {
centreLines.push(margin + c * (colW + colGap) - colGap / 2);
}
return { ledPitch: pitch, ledW, ledH, strips: out, centreLines };
}
/**
* Geometry from each strip's rig place [x0, y0, x1, y1] (y up, centre 0, as the controller sends it),
* fitted to the canvas with one scale. Used once every strip has a place.
* @returns {object} {placed: true, ledH, strips: [{ax, ay, bx, by, ang, len, pitch, labelX, labelY}], centre}
* Fit the room to a width x height canvas with one scale.
* @returns {object} {scale, sx(x), sy(y), mx(px), my(py)} metres -> px and back
*/
function computePlaced(strips, width, height, opts = {}) {
const margin = opts.margin ?? 28;
const ledH = opts.ledH ?? 12;
let lo = [Infinity, Infinity];
let hi = [-Infinity, -Infinity];
for (const s of strips) {
const p = s.place;
for (let k = 0; k < 4; k += 2) {
lo = [Math.min(lo[0], p[k]), Math.min(lo[1], p[k + 1])];
hi = [Math.max(hi[0], p[k]), Math.max(hi[1], p[k + 1])];
}
}
const spanX = Math.max(hi[0] - lo[0], 1e-3);
const spanY = Math.max(hi[1] - lo[1], 1e-3);
const scale = Math.min((width - 2 * margin) / spanX, (height - 2 * margin) / spanY);
const ox = width / 2 - ((lo[0] + hi[0]) / 2) * scale;
const oy = height / 2 + ((lo[1] + hi[1]) / 2) * scale;
const tx = (x) => ox + x * scale;
const ty = (y) => oy - y * scale;
const out = strips.map((s) => {
const [x0, y0, x1, y1] = s.place;
const ax = tx(x0);
const ay = ty(y0);
const bx = tx(x1);
const by = ty(y1);
function fit(room, width, height, margin = 28) {
const scale = Math.max(
1e-3,
Math.min((width - 2 * margin) / room.width, (height - 2 * margin) / room.depth),
);
const ox = width / 2;
const oy = height / 2 + (room.depth / 2) * scale;
return {
scale,
sx: (x) => ox + x * scale,
sy: (y) => oy - y * scale,
mx: (px) => (px - ox) / scale,
my: (py) => (oy - py) / scale,
};
}
/** Canvas geometry of each strip: pixel 0 at (ax, ay), the end at (bx, by). */
function stripGeometry(view, strips) {
return strips.map((s) => {
const ax = view.sx(s.x);
const ay = view.sy(s.y);
const bx = view.sx(s.x1);
const by = view.sy(s.y1);
const len = Math.hypot(bx - ax, by - ay);
const n = s.leds;
return {
ax, ay, bx, by, len,
ang: Math.atan2(by - ay, bx - ax),
pitch: len / n,
labelX: (ax + bx) / 2,
labelY: (ay + by) / 2 - ledH / 2 - 9,
};
return { ax, ay, bx, by, len, ang: Math.atan2(by - ay, bx - ax), pitch: len / s.leds };
});
return { placed: true, ledH, strips: out, centre: { x: tx(0), y: ty(0) } };
}
/** x of pixel i of a strip (pixel 0 at the start end). */
function pixelX(geo, sg, i, leds) {
const pos = sg.reversed ? leds - 1 - i : i;
return sg.x0 + pos * geo.ledPitch;
/** Distance from point (x, y) to the segment of a strip, canvas px. */
function distToStrip(sg, x, y) {
const dx = sg.bx - sg.ax;
const dy = sg.by - sg.ay;
const t = Math.max(0, Math.min(1, ((x - sg.ax) * dx + (y - sg.ay) * dy) / (dx * dx + dy * dy || 1)));
return Math.hypot(x - (sg.ax + t * dx), y - (sg.ay + t * dy));
}
g.RigLayout = { computeGeometry, computePlaced, pixelX };
g.RigLayout = { roomStrips, fit, stripGeometry, distToStrip, fixtureLeds };
})(typeof self !== 'undefined' ? self : globalThis);