move rainbow generation to lights
so we can support lights with multiple pixels properly
This commit is contained in:
parent
ca5991da50
commit
85c3c1b8e3
2 changed files with 26 additions and 18 deletions
25
dmx_queue.py
25
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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue