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>
71 lines
2.2 KiB
Python
Executable File
71 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import shutil
|
|
import subprocess
|
|
import serial
|
|
import sys
|
|
|
|
|
|
def mpremote_base():
|
|
"""mpremote on PATH, or same interpreter as this script (e.g. pipenv venv)."""
|
|
exe = shutil.which("mpremote")
|
|
if exe:
|
|
return [exe]
|
|
return [sys.executable, "-m", "mpremote"]
|
|
|
|
|
|
print(sys.argv)
|
|
|
|
commands = ["src", "lib", "ls", "reset", "follow", "test"]
|
|
port = None
|
|
if len(sys.argv) > 1 and sys.argv[1] not in commands:
|
|
port = sys.argv[1]
|
|
|
|
|
|
for cmd in sys.argv[1:]:
|
|
print(cmd)
|
|
match cmd:
|
|
case "src":
|
|
if port:
|
|
subprocess.call(
|
|
[*mpremote_base(), "connect", port, "fs", "cp", "-r", ".", ":"],
|
|
cwd="src",
|
|
)
|
|
else:
|
|
print("Error: Port required for 'src' command")
|
|
case "lib":
|
|
if port:
|
|
subprocess.call(
|
|
[*mpremote_base(), "connect", port, "fs", "cp", "-r", "lib", ":"]
|
|
)
|
|
else:
|
|
print("Error: Port required for 'lib' command")
|
|
case "ls":
|
|
if port:
|
|
subprocess.call([*mpremote_base(), "connect", port, "fs", "ls", ":"])
|
|
else:
|
|
print("Error: Port required for 'ls' command")
|
|
case "reset":
|
|
if port:
|
|
with serial.Serial(port, baudrate=115200) as ser:
|
|
ser.write(b"\x03\x03\x04")
|
|
else:
|
|
print("Error: Port required for 'reset' command")
|
|
case "follow":
|
|
if port:
|
|
with serial.Serial(port, baudrate=115200) as ser:
|
|
while True:
|
|
if ser.in_waiting > 0:
|
|
data = ser.readline().decode("utf-8").strip()
|
|
print(data)
|
|
else:
|
|
print("Error: Port required for 'follow' command")
|
|
case "test":
|
|
if port:
|
|
# Self-contained; requires ``lib`` on device first.
|
|
subprocess.call(
|
|
[*mpremote_base(), "connect", port, "run", "tests/artnet_dmx.py"]
|
|
)
|
|
else:
|
|
print("Error: Port required for 'test' command")
|