#!/usr/bin/env python import argparse import sys from bottle import route, run, static_file, view from dmx import DMX, Bar252, StairvilleLedPar56, Steady, RotatingRainbow, REDSpot18RGB, Chase, FadeTo @route('/') @view('index') def index(): return {'foo': 'bar'} @route('/static/') def static(path): return static_file(path, root='static') @route('/api/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)) 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 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) dmx.setAnimation(FadeTo(128, 128, 128)) dmx.start() run(host='0.0.0.0', port=8080, reloader=False) if __name__ == '__main__': main(sys.argv[1:])