foobazdmx/foobaz.py

79 lines
2.1 KiB
Python
Raw Normal View History

2022-07-20 22:27:40 +02:00
#!/usr/bin/env python
import argparse
import sys
2022-07-22 17:51:29 +02:00
from bottle import route, run, static_file, view
2022-07-20 22:27:40 +02:00
2022-07-22 17:51:29 +02:00
from dmx import DMX, Bar252, StairvilleLedPar56, Steady, RotatingRainbow, REDSpot18RGB, Chase, FadeTo
2022-07-20 22:27:40 +02:00
@route('/')
@view('index')
def index():
return {'foo': 'bar'}
@route('/static/<path:path>')
def static(path):
return static_file(path, root='static')
@route('/api/state/<state>')
def update(state):
if state == "off":
dmx.setAnimation(Steady(0, 0, 0))
elif state == "white":
dmx.setAnimation(Steady(255, 255, 255))
elif state == "red":
dmx.setAnimation(Steady(255, 0, 0))
elif state == "blue":
dmx.setAnimation(Steady(0, 0, 255))
elif state == "rainbow":
dmx.setAnimation(RotatingRainbow())
elif state == "chase-blue":
dmx.setAnimation(Chase(0, 0, 255))
2022-07-20 22:27:40 +02:00
dmx.start()
return {'result': 'ok'}
def main(args):
global dmx
parser = argparse.ArgumentParser(prog='foobazdmx', description='Make the lights flicker.')
parser.add_argument('-a', '--artnet', type=str, required=True, help="Art-Net server")
parser.add_argument('-r', '--room', type=str, required=True, help="light setup for room")
args = parser.parse_args(args)
artnet = args.artnet
2022-07-20 22:27:40 +02:00
print(f"Starting DMX via Art-Net to {artnet}", file=sys.stderr)
# dmx = DMX("10.31.242.35")
dmx = DMX(artnet, maxchan=64)
if args.room == "shop":
dmx.rgbs = [
REDSpot18RGB(dmx, 1),
REDSpot18RGB(dmx, 5),
REDSpot18RGB(dmx, 9),
REDSpot18RGB(dmx, 13),
]
elif args.room == "big":
dmx.rgbs = [
StairvilleLedPar56(dmx, 1),
StairvilleLedPar56(dmx, 8),
StairvilleLedPar56(dmx, 15),
StairvilleLedPar56(dmx, 22),
Bar252(dmx, 29),
Bar252(dmx, 40),
Bar252(dmx, 51),
Bar252(dmx, 62),
]
else:
print(f"Unknown room {args.room}", file=sys.stderr)
sys.exit(64)
2022-07-22 17:51:29 +02:00
dmx.setAnimation(FadeTo(128, 128, 128))
dmx.start()
2022-07-20 22:27:40 +02:00
run(host='0.0.0.0', port=8080, reloader=False)
2022-07-20 22:27:40 +02:00
if __name__ == '__main__':
main(sys.argv[1:])