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>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
"""Art-Net (ArtDMX) output — UDP 6454.
|
|
|
|
ArtDMX packet:
|
|
0 "Art-Net\\0"
|
|
8 OpCode 0x5000 (little-endian)
|
|
10 ProtVer 14 (big-endian)
|
|
12 Sequence 1..255 (0 disables re-ordering)
|
|
13 Physical 0
|
|
14 Port-Address: SubUni (low byte), Net (high 7 bits)
|
|
16 Length (big-endian, even, 2..512)
|
|
18 DMX data
|
|
|
|
170 RGB pixels per universe; consecutive universes from ``universe``.
|
|
Optional ArtSync (OpCode 0x5200) after each frame when ``sync`` is set.
|
|
"""
|
|
|
|
import struct
|
|
|
|
from engine.outputs.base import UdpFrameOutput, _bool, _int, split_universes
|
|
|
|
ARTNET_PORT = 6454
|
|
ARTNET_ID = b"Art-Net\x00"
|
|
OP_DMX = 0x5000
|
|
OP_SYNC = 0x5200
|
|
PROT_VER = 14
|
|
|
|
|
|
def build_artdmx(universe, data, sequence=0, physical=0):
|
|
data = bytes(data[:512])
|
|
if len(data) % 2:
|
|
data += b"\x00"
|
|
if len(data) < 2:
|
|
data = data + bytes(2 - len(data))
|
|
universe &= 0x7FFF
|
|
return (
|
|
ARTNET_ID
|
|
+ struct.pack("<H", OP_DMX)
|
|
+ struct.pack(">H", PROT_VER)
|
|
+ bytes((sequence & 0xFF, physical & 0xFF, universe & 0xFF, (universe >> 8) & 0x7F))
|
|
+ struct.pack(">H", len(data))
|
|
+ data
|
|
)
|
|
|
|
|
|
def build_artsync():
|
|
return ARTNET_ID + struct.pack("<H", OP_SYNC) + struct.pack(">H", PROT_VER) + b"\x00\x00"
|
|
|
|
|
|
class ArtNetOutput(UdpFrameOutput):
|
|
protocol = "artnet"
|
|
default_port = ARTNET_PORT
|
|
|
|
def __init__(self, cfg):
|
|
super().__init__(cfg)
|
|
if not self.host:
|
|
self.host = "255.255.255.255"
|
|
self.broadcast = True
|
|
self.universe = _int(self.cfg.get("universe"), 0, 0, 0x7FFF)
|
|
self.sync = _bool(self.cfg.get("sync"), False)
|
|
self._sequence = 0
|
|
|
|
def next_sequence(self):
|
|
self._sequence = (self._sequence % 255) + 1
|
|
return self._sequence
|
|
|
|
def packets_for(self, payload):
|
|
seq = self.next_sequence()
|
|
packets = [
|
|
build_artdmx(self.universe + i, chunk, seq)
|
|
for i, chunk in enumerate(split_universes(payload))
|
|
]
|
|
if self.sync:
|
|
packets.append(build_artsync())
|
|
return packets
|
|
|
|
async def _send_prepared(self, payload):
|
|
for packet in self.packets_for(payload):
|
|
self.sendto(packet)
|