feat: simulator bridge, rig seed and web UI (in progress)

Work in progress from the same tree as the controller's sequences-v2 changes.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-11 14:10:55 +13:00
1 parent 4fc3345fc9
commit 4d8aeb5df8
26 files changed
+3907 -288

No files matched your search

+37 -22
View File
@@ -1,37 +1,52 @@
"""Host NeoPixel: keeps RGB buffer and notifies the GUI on `write()`."""
"""Host NeoPixel with MicroPython's semantics: a ``buf`` bytearray in ``ORDER`` (GRB), which led-driver
writes directly. ``write()`` sends the frame to the simulator as RGB."""
# Set by led-simulator main: callable(list[tuple[int,int,int]]) -> None
import _simlink
# Optional extra hook: callable(list[tuple[int, int, int]]) -> None
PIXEL_SINK = None
class NeoPixel:
def __init__(self, pin, n):
ORDER = (1, 0, 2, 3) # as MicroPython: buf holds G, R, B (, W)
def __init__(self, pin, n, bpp=3, timing=1):
self.pin = pin
self.n = n
self._buf = [(0, 0, 0)] * n
self.bpp = bpp
self.timing = timing
self.buf = bytearray(n * bpp)
def __len__(self):
return self.n
def __setitem__(self, index, value):
if isinstance(value, (list, tuple)) and len(value) >= 3:
r, g, b = (int(value[0]), int(value[1]), int(value[2]))
self._buf[index] = (
max(0, min(255, r)),
max(0, min(255, g)),
max(0, min(255, b)),
)
if index < 0:
index += self.n
off = index * self.bpp
for j in range(self.bpp):
self.buf[off + self.ORDER[j]] = int(value[j]) & 255
def __getitem__(self, index):
return self._buf[index]
if index < 0:
index += self.n
off = index * self.bpp
return tuple(self.buf[off + self.ORDER[j]] for j in range(self.bpp))
def fill(self, color):
c = (0, 0, 0)
if isinstance(color, (list, tuple)) and len(color) >= 3:
c = (
max(0, min(255, int(color[0]))),
max(0, min(255, int(color[1]))),
max(0, min(255, int(color[2]))),
)
self._buf = [c] * self.n
px = bytearray(self.bpp)
for j in range(self.bpp):
px[self.ORDER[j]] = int(color[j]) & 255
self.buf[:] = px * self.n
def _rgb(self):
b, bpp, o = self.buf, self.bpp, self.ORDER
return [(b[i + o[0]], b[i + o[1]], b[i + o[2]]) for i in range(0, self.n * bpp, bpp)]
def write(self):
if PIXEL_SINK is not None:
PIXEL_SINK(list(self._buf))
if _simlink.connected() or PIXEL_SINK is not None:
px = self._rgb()
if _simlink.connected():
_simlink.push_pixels(px)
if PIXEL_SINK is not None:
PIXEL_SINK(px)