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:
1 parent
698c1463c0
commit
581b751904
506 files changed
+42336
-3599
No files matched your search
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pack the simulated rig's page (led-simulator/web) and the drivers built to WebAssembly (led-simulator/web/wasm,
|
||||
# from `make sim-wasm`) into www_dist/sim.pack, which the host builds embed and serve at /sim/
|
||||
# (sim-controller/components/sim/sim_rig.c). Same format as www.pack: "WWW1", then per file u16 name length,
|
||||
# u32 data length, name, gzipped data; a zero name length ends it.
|
||||
# Without the wasm the pack is empty, and /sim/ says how to build it.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
SRC=led-simulator/web
|
||||
OUT=www_dist
|
||||
mkdir -p "$OUT"
|
||||
python3 - "$SRC" "$OUT/sim.pack" <<'PY'
|
||||
import gzip, os, struct, sys
|
||||
src, out_path = sys.argv[1], sys.argv[2]
|
||||
files = ["index.html", "app.js", "layout.js", "styles.css", "driver-worker.js",
|
||||
"gallery.html", "gallery.js", "gallery.css",
|
||||
"wasm/led_driver.mjs", "wasm/led_driver.wasm", "wasm/led_fx.mjs", "wasm/led_fx.wasm"]
|
||||
out = bytearray(b"WWW1")
|
||||
if not os.path.isfile(os.path.join(src, "wasm/led_driver.wasm")):
|
||||
print("sim.pack: no drivers built (make sim-wasm): the rig is left out")
|
||||
else:
|
||||
for name in files:
|
||||
data = gzip.compress(open(os.path.join(src, name), "rb").read(), 9, mtime=0)
|
||||
out += struct.pack("<HI", len(name), len(data)) + name.encode() + data
|
||||
print("sim.pack: %d files" % len(files))
|
||||
out += struct.pack("<H", 0)
|
||||
open(out_path, "wb").write(out)
|
||||
print("sim.pack: %d bytes" % len(out))
|
||||
PY
|
||||
+2
-1
@@ -33,7 +33,8 @@ find "$OUT" -name '*.gz' -exec gzip -t {} \;
|
||||
|
||||
# led-driver pattern sources, kept uncompressed: the controller serves them and pushes them to drivers
|
||||
mkdir -p "$OUT/patterns"
|
||||
cp led-driver/src/patterns/*.py "$OUT/patterns/"
|
||||
# (the cpp led-driver has no MicroPython pattern sources, so this is optional)
|
||||
if compgen -G "led-driver/src/patterns/*.py" > /dev/null; then cp led-driver/src/patterns/*.py "$OUT/patterns/"; fi
|
||||
|
||||
total=$(find "$OUT" -name '*.gz' -printf '%s\n' | paste -sd+ | bc)
|
||||
echo "www_dist: $(find "$OUT" -name '*.gz' | wc -l) files, $total bytes (limit $MAX)"
|
||||
|
||||
+14
-14
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Load demo animations for the simulated bridge rig (or any 2-column rig) into led-controller.
|
||||
"""Load demo sequences for the simulated bridge rig (or any 2-column rig) into led-controller.
|
||||
|
||||
python3 tools/sim_demo.py # controller at localhost:8080, simulator at :8765
|
||||
python3 tools/sim_demo.py --host 10.1.1.180 --sim http://localhost:8765
|
||||
@@ -8,7 +8,7 @@ Creates (again, if run twice) a "Sim demo" profile and makes it current, with:
|
||||
- groups: Rig (all bars), Left, Right, Row 1-8
|
||||
- presets: the field patterns (sweep, ripple, spin, grow, field_wave) and hit / keyframes, timed in beats
|
||||
- sequences: row chase, column ping-pong, a two-lane canon, a looks medley
|
||||
- animations (one-shot clips over whatever plays): flash, rows drop, centre burst
|
||||
- one-shot sequences (loop off: play once over whatever loops): flash, rows drop, centre burst
|
||||
- a zone "Bridge" over the whole rig with all of the above as tiles
|
||||
|
||||
Drivers restart their pattern on every beat, so every preset here lasts one beat (beat_time, delay 4
|
||||
@@ -107,8 +107,8 @@ def main():
|
||||
|
||||
row_targets = [{"name": f"Row {r + 1}", "group_ids": [g[f"Row {r + 1}"]]} for r in range(rows)]
|
||||
|
||||
def sequence(name, kind="sequence", **body):
|
||||
body = {"name": name, "kind": kind, "loop": kind != "animation", "advance_mode": "beats", **body}
|
||||
def sequence(name, loop=True, **body):
|
||||
body = {"name": name, "loop": loop, "advance_mode": "beats", **body}
|
||||
return new_id(api("POST", "/sequences", body))
|
||||
|
||||
seqs = {
|
||||
@@ -138,29 +138,29 @@ def main():
|
||||
("Ripple", "Sweep →", "Radar", "Grow out", "Plasma", "Pinwheel", "Swirl", "Sweep ↑")]],
|
||||
),
|
||||
}
|
||||
anims = {
|
||||
"Flash": sequence("Flash", kind="animation", group_ids=[g["Rig"]],
|
||||
lanes=[[{"preset_id": P["Hit"], "beats": 1}]]),
|
||||
oneshots = { # loop off: each plays once, then the zone goes back to what looped
|
||||
"Flash": sequence("Flash", loop=False, group_ids=[g["Rig"]],
|
||||
lanes=[[{"preset_id": P["Hit"], "seconds": 0.5}]]),
|
||||
"Rows drop": sequence(
|
||||
"Rows drop", kind="animation", targets=row_targets,
|
||||
lanes=[[{"preset_id": P["White"], "beats": 0.25}] * rows],
|
||||
"Rows drop", loop=False, targets=row_targets,
|
||||
lanes=[[{"preset_id": P["White"], "seconds": 0.25}] * rows],
|
||||
lane_opts=[{"targets": list(range(rows)), "chase": {"order": "forward", "width": 1}}],
|
||||
),
|
||||
"Burst": sequence("Burst", kind="animation", group_ids=[g["Rig"]],
|
||||
lanes=[[{"preset_id": P["Ripple in"], "beats": 1},
|
||||
{"preset_id": P["Ripple"], "beats": 1}]]),
|
||||
"Burst": sequence("Burst", loop=False, group_ids=[g["Rig"]],
|
||||
lanes=[[{"preset_id": P["Ripple in"], "seconds": 0.5},
|
||||
{"preset_id": P["Ripple"], "seconds": 0.5}]]),
|
||||
}
|
||||
|
||||
names = list(P)
|
||||
zone = new_id(api("POST", "/zones", {
|
||||
"name": "Bridge", "group_ids": [g["Rig"]],
|
||||
"presets": [[P[n] for n in names[i:i + 6]] for i in range(0, len(names), 6)],
|
||||
"sequence_ids": list(seqs.values()), "animation_ids": list(anims.values()),
|
||||
"sequence_ids": list(seqs.values()) + list(oneshots.values()),
|
||||
}))
|
||||
api("POST", f"/zones/{zone}/set-current")
|
||||
api("POST", f"/zones/{zone}/play", {"preset_id": P["Ripple"]})
|
||||
print(f"profile {pid} '{PROFILE}', zone {zone} 'Bridge': {len(g)} groups, {len(P)} presets, "
|
||||
f"{len(seqs)} sequences ({', '.join(seqs)}), {len(anims)} animations ({', '.join(anims)}). Playing Ripple.")
|
||||
f"{len(seqs)} sequences ({', '.join(seqs)}), {len(oneshots)} one-shots ({', '.join(oneshots)}). Playing Ripple.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user