69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
import sys
|
||
|
import json
|
||
|
import subprocess
|
||
|
from time import sleep
|
||
|
from PyDMXControl.controllers import OpenDMXController
|
||
|
from PyDMXControl.profiles.Generic import Dimmer
|
||
|
|
||
|
## ask for input, play, wait for stop, ask again
|
||
|
|
||
|
# python3 mapchannels.py
|
||
|
|
||
|
# 0-255 dim / brightness range
|
||
|
# fadein, fadeout in milliseconds
|
||
|
brightness = 10
|
||
|
fadein = 1000
|
||
|
fadeout = 1000
|
||
|
|
||
|
data = json.load(open('sequence.json'))
|
||
|
|
||
|
print("\n * Reset USB device")
|
||
|
subprocess.call(['usbreset', "FT232R USB UART"])
|
||
|
|
||
|
print("\n ** DMX start...")
|
||
|
dmx = OpenDMXController()
|
||
|
|
||
|
## sort by "channel" -> channel/line number
|
||
|
lines = sorted(data, key=lambda x: x["channel"])
|
||
|
## remove dupes and add lights once in this order
|
||
|
channels = []
|
||
|
for l in lines:
|
||
|
if l['channel'] not in channels:
|
||
|
channels.append(l['channel'])
|
||
|
line = dmx.add_fixture(Dimmer, name=l['channel'])
|
||
|
print("\n All channel names:")
|
||
|
print(channels)
|
||
|
print()
|
||
|
#dmx.web_control()
|
||
|
|
||
|
try:
|
||
|
# forever until keyboard interrupt / ctrl-C
|
||
|
while 1>0:
|
||
|
print(" * Press 'CTRL-C' to EXIT, or ")
|
||
|
channelname = input(" - Enter channel name to fadein: ")
|
||
|
# invalid channelname
|
||
|
while channelname not in channels:
|
||
|
print(" !! Please check channel name !!")
|
||
|
print("\n All channel names:")
|
||
|
print(channels)
|
||
|
print()
|
||
|
channelname = input(" - Enter correct channel name: ")
|
||
|
print(f"\n - Play channel: {channelname}")
|
||
|
line = dmx.get_fixtures_by_name(channelname)[0]
|
||
|
line.dim(brightness, fadein)
|
||
|
x = input(f" - Press ANY key (+ENTER) to fadeout {channelname}")
|
||
|
line.dim(0, fadeout)
|
||
|
sleep(fadeout/1000 + 1)
|
||
|
print()
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
line.dim(0, fadeout)
|
||
|
sleep(fadeout/1000 + 1)
|
||
|
dmx.close()
|
||
|
print()
|
||
|
sys.exit()
|
||
|
print()
|
||
|
|