Add src/engine, modelled on technicalkiwi/portal's player and sequence runner: - Pixel generator: runs the unchanged led-driver patterns under CPython (utime shim + NeoPixel-like buffer) on a per-zone render thread and streams frames to pixel outputs, with keepalive for static frames. - Output drivers: DDP, Art-Net (ArtDMX/ArtSync), sACN/E1.31, USB-DMX (Enttec Pro / Open DMX), plus an ESP32 preset output that reuses the existing preset + select delivery path. Registry in db/output.json, CRUD and test pattern at /outputs. - Sequencer: timed preset chains per zone (portal step shape), deadline scheduling, loop/repeat, resume after restart; legacy sequence records are migrated. Zone play/stop, sequence and scene play/stop endpoints. - CLI (python -m engine.cli), Outputs and Sequences modals, preset tiles drive pixel outputs, API/README docs, engine test suite. ESP32 firmware is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Stand-in for the led-driver ``Presets`` object that patterns draw into.
|
|
|
|
Same surface the patterns use on the ESP32 (``n[i]``, ``n.write()``,
|
|
``n.fill``, ``num_leds``, ``step``, ``fill``, ``off``, ``on``,
|
|
``apply_brightness``), but ``write()`` hands the frame to a callback instead
|
|
of a NeoPixel strip.
|
|
"""
|
|
|
|
|
|
class PixelBuffer:
|
|
"""NeoPixel-compatible buffer of RGB tuples."""
|
|
|
|
def __init__(self, num_leds, on_write=None):
|
|
self.n = int(num_leds)
|
|
self._px = [(0, 0, 0)] * self.n
|
|
self.on_write = on_write
|
|
|
|
def __len__(self):
|
|
return self.n
|
|
|
|
def __setitem__(self, i, color):
|
|
self._px[i] = (int(color[0]) & 0xFF, int(color[1]) & 0xFF, int(color[2]) & 0xFF)
|
|
|
|
def __getitem__(self, i):
|
|
return self._px[i]
|
|
|
|
def fill(self, color):
|
|
c = (int(color[0]) & 0xFF, int(color[1]) & 0xFF, int(color[2]) & 0xFF)
|
|
self._px = [c] * self.n
|
|
|
|
def to_bytes(self):
|
|
out = bytearray(self.n * 3)
|
|
for i, (r, g, b) in enumerate(self._px):
|
|
j = i * 3
|
|
out[j] = r
|
|
out[j + 1] = g
|
|
out[j + 2] = b
|
|
return bytes(out)
|
|
|
|
def write(self):
|
|
if self.on_write is not None:
|
|
self.on_write(self.to_bytes())
|
|
|
|
|
|
class FrameDriver:
|
|
def __init__(self, num_leds, on_write=None):
|
|
self.num_leds = int(num_leds)
|
|
self.n = PixelBuffer(self.num_leds, on_write)
|
|
self.step = 0
|
|
# Global brightness is applied per output at send time, not here.
|
|
self.b = 255
|
|
|
|
def apply_brightness(self, color, brightness_override=None):
|
|
local = brightness_override if brightness_override is not None else 255
|
|
effective_brightness = int(local * self.b / 255)
|
|
return tuple(int(c * effective_brightness / 255) for c in color)
|
|
|
|
def fill(self, color=None):
|
|
self.n.fill(color if color is not None else (0, 0, 0))
|
|
self.n.write()
|
|
|
|
def off(self, preset=None):
|
|
self.fill((0, 0, 0))
|
|
|
|
def on(self, preset):
|
|
colors = preset.c
|
|
color = colors[0] if colors else (255, 255, 255)
|
|
self.fill(self.apply_brightness(color, preset.b))
|