2023-08-07 11:39:15 +00:00
|
|
|
import logging
|
2024-05-21 07:06:13 +00:00
|
|
|
from colorsys import hsv_to_rgb
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
LOG = logging.getLogger("DMX")
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2023-08-07 12:48:18 +00:00
|
|
|
|
2023-08-07 11:39:15 +00:00
|
|
|
class BaseDMXLight:
|
|
|
|
def __init__(self, address):
|
|
|
|
self.address = address
|
|
|
|
self.intensity = 0
|
|
|
|
self.red = 0
|
|
|
|
self.green = 0
|
|
|
|
self.blue = 0
|
|
|
|
self.white = 0
|
|
|
|
|
|
|
|
def __str__(self):
|
2024-08-17 10:19:01 +00:00
|
|
|
return f"{self.name} ({self.address})"
|
2023-08-07 11:39:15 +00:00
|
|
|
|
|
|
|
def _dump(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def dump(self):
|
|
|
|
ret = self._dump()
|
2024-08-17 10:19:01 +00:00
|
|
|
LOG.debug(f"{str(self)} -> {ret[1]}")
|
2023-08-07 11:39:15 +00:00
|
|
|
return ret
|
2024-05-21 07:06:13 +00:00
|
|
|
|
|
|
|
def rainbow(self, idx, angle, number_of_lights, intensity, brightness):
|
2024-08-17 10:19:01 +00:00
|
|
|
my_degrees_dec = (angle + (idx * (360 / number_of_lights))) % 360 / 360
|
2024-05-21 07:06:13 +00:00
|
|
|
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()
|