- 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>
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
/* 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';
|
|
|
|
function fixtureLeds(room, f) {
|
|
return Number(f.leds) || room.definitions[f.def].leds;
|
|
}
|
|
|
|
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 {
|
|
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,
|
|
};
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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 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);
|
|
return { ax, ay, bx, by, len, ang: Math.atan2(by - ay, bx - ax), pitch: len / s.leds };
|
|
});
|
|
}
|
|
|
|
/** 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 = { roomStrips, fit, stripGeometry, distToStrip, fixtureLeds };
|
|
})(typeof self !== 'undefined' ? self : globalThis);
|