From ff3ea2f45203bf112cb2da180dccd7925bf2719c Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 7 Aug 2023 14:45:01 +0200 Subject: [PATCH] add rainbow idle animation --- dmx_queue.py | 24 +++++++++++++++++++++++- main.py | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/dmx_queue.py b/dmx_queue.py index 96c87c7..4184d21 100644 --- a/dmx_queue.py +++ b/dmx_queue.py @@ -1,4 +1,5 @@ import logging +from colorsys import hsv_to_rgb from queue import Empty from threading import Thread from time import sleep @@ -58,6 +59,7 @@ class DMXQueue: def _worker(self): LOG.info('Worker startup') + rotation = 0 while self.worker_should_be_running: try: level, component, text = self.queue.get_nowait() @@ -99,5 +101,25 @@ class DMXQueue: sleep(0.03) self.queue.task_done() except Empty: - sleep(0.1) + degrees_per_step = 360 / len(self.lights) + + for idx, light in enumerate(self.lights): + light_degrees_dec = ( + (rotation + (idx * degrees_per_step)) % 360 / 360 + ) + r, g, b = hsv_to_rgb( + light_degrees_dec, 1, self.args.rainbow_intensity / 100 + ) + + light.red = int(r * 255) + light.green = int(g * 255) + light.blue = int(b * 200) + light.intensity = self.args.rainbow_brightness + self._bulk(*light.dump()) + + rotation = rotation + 1 + if rotation >= 360: + rotation = 0 + + sleep(self.args.rainbow_speed / 1000) LOG.info('Worker shutdown') diff --git a/main.py b/main.py index 9954196..88e799b 100755 --- a/main.py +++ b/main.py @@ -24,6 +24,26 @@ def main(): parser = ArgumentParser() + # rainbow is output if we have no effects + parser.add_argument( + '--rainbow-intensity', + type=int, + default=50, + help='intensity of the rainbow colours in percent ("value" in HSV)', + ) + parser.add_argument( + '--rainbow-brightness', + type=int, + default=150, + help='brightness of the rainbow colour (dmx value of dimmer)', + ) + parser.add_argument( + '--rainbow-speed', + type=int, + default=10, + help='speed of rainbow colour change (ms per degree hue)', + ) + # MQTT parser.add_argument('--mqtt-host', required=True) parser.add_argument('--mqtt-port', type=int, default=1883)