Files
led-controller/tools/build_web.sh
T
jimmyandClaude Opus 5.5 581b751904 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>
2026-11-16 19:32:46 +13:00

65 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Minify and gzip the web UI into www_dist and pack it into www_dist/www.pack, which the
# firmware embeds (main/CMakeLists.txt). Usage: tools/build_web.sh (needs node/npx; WWW_MAX = size limit in bytes)
set -euo pipefail
cd "$(dirname "$0")/.."
SRC=web
OUT=www_dist
MAX=${WWW_MAX:-524288}
rm -rf "$OUT"; mkdir -p "$OUT/static"
for f in "$SRC"/static/*; do
[[ -f $f ]] || continue
b=$(basename "$f")
case $b in
*.min.js) cp "$f" "$OUT/static/$b" ;;
*.js|*.css) npx --yes esbuild@0.25.0 "$f" --minify --target=es2019 --legal-comments=none \
--outfile="$OUT/static/$b" --log-level=warning ;;
*) cp "$f" "$OUT/static/$b" ;;
esac
done
for p in index settings settings_editor; do
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
--minify-css true --minify-js true -o "$OUT/$p.html" "$SRC/templates/$p.html"
done
# Live audio and beat page (served at /audio)
npx --yes html-minifier-terser@7.2.0 --collapse-whitespace --remove-comments \
--minify-css true --minify-js true -o "$OUT/audio.html" web/audio.html
# Ship only the .gz copies; the server sends Content-Encoding: gzip
find "$OUT" -type f -exec gzip -9 -n -f {} \;
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"
# (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)"
(( total <= MAX )) || { echo "ERROR: web UI exceeds the size limit" >&2; exit 1; }
# One blob for the firmware: "WWW1", then per file u16 name length, u32 data length, name (no .gz),
# data; a zero name length ends it. Little-endian, read by main/web.c. patterns/*.py go in as they are.
python3 - "$OUT" <<'PY'
import os, struct, sys
root = sys.argv[1]
out = bytearray(b"WWW1")
for dirpath, _, names in sorted(os.walk(root)):
for n in sorted(names):
full = os.path.join(dirpath, n)
rel = os.path.relpath(full, root)
if rel.startswith("patterns/") and n.endswith(".py"):
name = rel.encode()
elif n.endswith(".gz"):
name = rel[:-3].encode()
else:
continue
data = open(full, "rb").read()
out += struct.pack("<HI", len(name), len(data)) + name + data
out += struct.pack("<H", 0)
open(os.path.join(root, "www.pack"), "wb").write(out)
print("www.pack: %d bytes" % len(out))
PY