2022-07-20 22:27:40 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2022-07-21 18:45:46 +02:00
|
|
|
import argparse
|
|
|
|
import sys
|
2022-07-24 11:43:00 +02:00
|
|
|
from typing import Tuple
|
2022-07-21 18:45:46 +02:00
|
|
|
|
2022-07-24 11:43:00 +02:00
|
|
|
from bottle import post, request, route, run, static_file, view
|
2022-07-20 22:27:40 +02:00
|
|
|
|
2022-07-24 11:43:00 +02:00
|
|
|
from animation import Off
|
|
|
|
from dmx import DMX, Bar252, StairvilleLedPar56, REDSpot18RGB
|
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')
|
|
|
|
|
2022-07-24 11:43:00 +02:00
|
|
|
@route('/api/state')
|
|
|
|
def state():
|
|
|
|
return {
|
|
|
|
'animation': dmx.animation,
|
|
|
|
'color': rgb_to_hex(dmx.color)
|
|
|
|
}
|
2022-07-20 22:27:40 +02:00
|
|
|
|
2022-07-24 11:43:00 +02:00
|
|
|
@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}"
|
2022-07-22 17:56:53 +02:00
|
|
|
|
2022-07-21 18:45:46 +02:00
|
|
|
def main(args):
|
|
|
|
global dmx
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(prog='foobazdmx', description='Make the lights flicker.')
|
2024-02-26 22:52:47 +01:00
|
|
|
parser.add_argument('-a', '--artnet', type=str, required=True, default="127.0.0.1", help="Art-Net server")
|
2022-07-22 17:56:53 +02:00
|
|
|
parser.add_argument('-r', '--room', type=str, required=True, help="light setup for room: shop or big")
|
2024-02-26 22:52:47 +01:00
|
|
|
parser.add_argument('-u', '--universe', type=int, required=False, default=1, help="Universe to send to")
|
2022-07-21 18:45:46 +02:00
|
|
|
args = parser.parse_args(args)
|
|
|
|
|
2024-02-26 22:52:47 +01:00
|
|
|
print(f"Starting DMX via Art-Net to {args.artnet}", file=sys.stderr)
|
2024-02-26 22:56:17 +01:00
|
|
|
dmx = DMX(args.artnet, maxchan=128, universe=args.universe)
|
2022-07-21 18:45:46 +02:00
|
|
|
|
|
|
|
if args.room == "shop":
|
2022-07-24 11:43:00 +02:00
|
|
|
dmx._rgbs = [
|
2022-07-21 18:45:46 +02:00
|
|
|
REDSpot18RGB(dmx, 1),
|
|
|
|
REDSpot18RGB(dmx, 5),
|
|
|
|
REDSpot18RGB(dmx, 9),
|
|
|
|
REDSpot18RGB(dmx, 13),
|
|
|
|
]
|
|
|
|
elif args.room == "big":
|
2022-07-24 11:43:00 +02:00
|
|
|
dmx._rgbs = [
|
2022-07-21 18:45:46 +02:00
|
|
|
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-24 11:43:00 +02:00
|
|
|
dmx.animation = Off()
|
2022-07-31 11:21:33 +02:00
|
|
|
dmx.color = (0, 0, 0)
|
|
|
|
dmx.animation = "off"
|
2022-07-20 22:27:40 +02:00
|
|
|
|
2022-07-24 11:43:00 +02:00
|
|
|
run(host='0.0.0.0', port=8080, reloader=False, debug=True)
|
2022-07-20 22:27:40 +02:00
|
|
|
|
2022-07-21 18:45:46 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main(sys.argv[1:])
|