diff --git a/dmx.py b/dmx.py index de35045..23130e3 100644 --- a/dmx.py +++ b/dmx.py @@ -1,7 +1,7 @@ import colorsys import socket import struct -import threading +import sys from threading import Thread from time import sleep, time @@ -59,7 +59,7 @@ class Steady: return (self.r, self.g, self.b) def __str__(self): - return f"steady({self.r}, {self.g}, {self.b})" + return f"{type(self).__name__}({self.r}, {self.g}, {self.b})" class FadeTo(Steady): @@ -74,7 +74,7 @@ class FadeTo(Steady): return (int(self.r * h), int(self.g * h), int(self.b * h)) def __str__(self): - return f"fadeTo({self.r}, {self.g}, {self.b})" + return f"{type(self).__name__}({self.r}, {self.g}, {self.b}, {self.t:.2f})" class RotatingRainbow: @@ -94,7 +94,7 @@ class RotatingRainbow: return rgb def __str__(self): - return "RotatingRainbow" + return "{type(self).__name__}" class Chase(Steady): @@ -109,7 +109,7 @@ class Chase(Steady): return (int(self.r * l), int(self.g * l), int(self.b * l)) def __str__(self): - return f"fadeTo({self.r}, {self.g}, {self.b})" + return f"{type(self).__name__}({self.r}, {self.g}, {self.b}, {self.looptime:.2f})" class DMX: @@ -169,4 +169,4 @@ class DMX: def setAnimation(self, animation): self.animation = animation - print(f"Animation: {animation}") \ No newline at end of file + print(f"Animation: {animation}", file=sys.stderr) \ No newline at end of file diff --git a/foobaz.py b/foobaz.py index ba2d464..f7cd36c 100644 --- a/foobaz.py +++ b/foobaz.py @@ -2,11 +2,10 @@ import argparse import sys -from time import sleep -from bottle import route, run, static_file, template, view +from bottle import route, run, static_file, view -from dmx import DMX, Bar252, StairvilleLedPar56, Steady, RotatingRainbow, REDSpot18RGB, Chase +from dmx import DMX, Bar252, StairvilleLedPar56, Steady, RotatingRainbow, REDSpot18RGB, Chase, FadeTo @route('/') @@ -20,7 +19,6 @@ def static(path): @route('/api/state/') def update(state): - print(f"state -> {state}") if state == "off": dmx.setAnimation(Steady(0, 0, 0)) elif state == "white": @@ -71,7 +69,7 @@ def main(args): else: print(f"Unknown room {args.room}", file=sys.stderr) sys.exit(64) - dmx.update() + dmx.setAnimation(FadeTo(128, 128, 128)) dmx.start() run(host='0.0.0.0', port=8080, reloader=False)