Host gateway that takes led-controller-style commands and fans out DMX512 universes to Art-Net devices and serial ports. Fixtures are patched onto outputs and a led-driver-style pattern engine writes channel roles into them. Includes the vendored microdot/utemplate libs, tests and the README. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
34 lines
930 B
Python
34 lines
930 B
Python
# DMX512 UART TX. MicroPython (ESP32) and buffer-only on CPython.
|
|
|
|
try:
|
|
from machine import UART, Pin
|
|
except ImportError:
|
|
UART = None
|
|
Pin = None
|
|
|
|
|
|
class DMX:
|
|
"""One DMX512 universe. UART TX on MicroPython; frame-only on CPython."""
|
|
|
|
def __init__(self, uart=1, tx=0, de=None):
|
|
self.frame = bytearray(513) # start code 0 + 512 slots
|
|
self.uart = None
|
|
self._de = None
|
|
if UART is None:
|
|
return
|
|
self.uart = UART(uart, tx=tx)
|
|
self.uart.init(250000, bits=8, parity=None, stop=2)
|
|
if de is not None and Pin is not None:
|
|
self._de = Pin(de, Pin.OUT)
|
|
self._de.value(0)
|
|
|
|
def send(self):
|
|
if self.uart is None:
|
|
return
|
|
if self._de is not None:
|
|
self._de.value(1)
|
|
self.uart.sendbreak()
|
|
self.uart.write(self.frame)
|
|
if self._de is not None:
|
|
self._de.value(0)
|