89 lines
2.3 KiB
Python
89 lines
2.3 KiB
Python
#!/usr/bin/env python
|
|
|
|
import argparse
|
|
import sys
|
|
from typing import Tuple
|
|
|
|
from bottle import post, request, route, run, static_file, view
|
|
|
|
from animation import Off
|
|
from dmx import DMX, Bar252, StairvilleLedPar56, REDSpot18RGB
|
|
|
|
|
|
@route('/')
|
|
@view('index')
|
|
def index():
|
|
return {'foo': 'bar'}
|
|
|
|
@route('/static/<path:path>')
|
|
def static(path):
|
|
return static_file(path, root='static')
|
|
|
|
@route('/api/state')
|
|
def state():
|
|
return {
|
|
'animation': dmx.animation,
|
|
'color': rgb_to_hex(dmx.color)
|
|
}
|
|
|
|
@post('/api/state')
|
|
def update():
|
|
json = request.json
|
|
print(json)
|
|
dmx.animation = json["animation"]
|
|
dmx.color = hex_to_rgb(json["color"])
|
|
return state()
|
|
|
|
|
|
def hex_to_rgb(hex: str) -> tuple[int, ...]:
|
|
return tuple(int(hex[i:i+2], 16) for i in (1, 3, 5))
|
|
|
|
|
|
def rgb_to_hex(color: Tuple[int, int, int]) -> str:
|
|
return f"#{color[0]:02X}{color[1]:02X}{color[2]:02X}"
|
|
|
|
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: shop or big")
|
|
args = parser.parse_args(args)
|
|
|
|
artnet = args.artnet
|
|
|
|
print(f"Starting DMX via Art-Net to {artnet}", file=sys.stderr)
|
|
dmx = DMX(artnet, maxchan=128)
|
|
|
|
if args.room == "shop":
|
|
dmx.group(0, [
|
|
REDSpot18RGB(1),
|
|
REDSpot18RGB(5),
|
|
REDSpot18RGB(9),
|
|
REDSpot18RGB(13),
|
|
])
|
|
elif args.room == "big":
|
|
dmx.group(0, [
|
|
StairvilleLedPar56(1), # Window/Kitchen
|
|
StairvilleLedPar56(15), # Hallway/Kitchen
|
|
Bar252(29), # Window/Blackboard
|
|
Bar252(40), # Hallway/Blackboard
|
|
Bar252(51), # Window/Kitchen
|
|
Bar252(62), # Hallway/Kitchen
|
|
])
|
|
dmx.group(0, [
|
|
StairvilleLedPar56(8), # Window/Blackboard
|
|
StairvilleLedPar56(22), # Hallway/Blackboard
|
|
])
|
|
else:
|
|
print(f"Unknown room {args.room}", file=sys.stderr)
|
|
sys.exit(64)
|
|
dmx.animation = Off()
|
|
dmx.color = (0, 0, 0)
|
|
dmx.animation = "off"
|
|
|
|
run(host='0.0.0.0', port=8080, reloader=False, debug=True)
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1:])
|