move rainbow generation to lights

so we can support lights with multiple pixels properly
This commit is contained in:
Franzi 2024-05-21 09:06:13 +02:00
parent ca5991da50
commit 85c3c1b8e3
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 26 additions and 18 deletions

View file

@ -1,5 +1,4 @@
import logging import logging
from colorsys import hsv_to_rgb
from queue import Empty from queue import Empty
from threading import Thread from threading import Thread
from time import sleep from time import sleep
@ -145,24 +144,14 @@ class DMXQueue:
self.queue.task_done() self.queue.task_done()
except Empty: except Empty:
if self.config.rainbow.enable: if self.config.rainbow.enable:
degrees_per_step = 360 / len(self.lights)
for idx, light in enumerate(self.lights): for idx, light in enumerate(self.lights):
light_degrees_dec = ( self._bulk(*light.rainbow(
(rotation + (idx * degrees_per_step)) % 360 / 360 idx,
) rotation,
r, g, b = hsv_to_rgb( len(self.lights),
light_degrees_dec, self.config.rainbow.intensity,
1, self.config.rainbow.brightness,
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())
if self.config.rainbow.speed >= 25: if self.config.rainbow.speed >= 25:
rotation = rotation + 1 rotation = rotation + 1

View file

@ -1,4 +1,5 @@
import logging import logging
from colorsys import hsv_to_rgb
LOG = logging.getLogger('DMX') LOG = logging.getLogger('DMX')
@ -22,3 +23,21 @@ class BaseDMXLight:
ret = self._dump() ret = self._dump()
LOG.debug(f'{str(self)} -> {ret[1]}') LOG.debug(f'{str(self)} -> {ret[1]}')
return ret 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()