From 85c3c1b8e39b47311823d1150bc43375e5a0ab4f Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Tue, 21 May 2024 09:06:13 +0200 Subject: [PATCH] move rainbow generation to lights so we can support lights with multiple pixels properly --- dmx_queue.py | 25 +++++++------------------ lights/common.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/dmx_queue.py b/dmx_queue.py index 9b53a32..4cb892f 100644 --- a/dmx_queue.py +++ b/dmx_queue.py @@ -1,5 +1,4 @@ import logging -from colorsys import hsv_to_rgb from queue import Empty from threading import Thread from time import sleep @@ -145,24 +144,14 @@ class DMXQueue: self.queue.task_done() except Empty: if self.config.rainbow.enable: - 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.config.rainbow.intensity / 100, - ) - - light.red = int(r * 255) - light.green = int(g * 255) - light.blue = int(b * 200) - light.white = 0 - light.intensity = self.config.rainbow.brightness - self._bulk(*light.dump()) + self._bulk(*light.rainbow( + idx, + rotation, + len(self.lights), + self.config.rainbow.intensity, + self.config.rainbow.brightness, + )) if self.config.rainbow.speed >= 25: rotation = rotation + 1 diff --git a/lights/common.py b/lights/common.py index e1c2784..2b98fe5 100644 --- a/lights/common.py +++ b/lights/common.py @@ -1,4 +1,5 @@ import logging +from colorsys import hsv_to_rgb LOG = logging.getLogger('DMX') @@ -22,3 +23,21 @@ class BaseDMXLight: ret = self._dump() LOG.debug(f'{str(self)} -> {ret[1]}') return ret + + def rainbow(self, idx, angle, number_of_lights, intensity, brightness): + my_degrees_dec = ( + (angle + (idx * (360 / number_of_lights))) % 360 / 360 + ) + r, g, b = hsv_to_rgb( + my_degrees_dec, + 1, + intensity / 100, + ) + + self.red = int(r * 255) + self.green = int(g * 255) + self.blue = int(b * 255) + self.white = 0 + self.intensity = brightness + + return self.dump()