add rainbow idle animation

This commit is contained in:
Franzi 2023-08-07 14:45:01 +02:00
parent c8630735c4
commit ff3ea2f452
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 43 additions and 1 deletions

View file

@ -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')

20
main.py
View file

@ -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)