Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Support #91

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ovos_plugin_manager/hardware/led/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def from_hex(hex_code: str) -> tuple:
@param hex_code: RGB hex code, optionally starting with '#'
@return: tuple RGB values
"""
hex_code = hex_code.lstrip('#').strip()
hex_code = hex_code.lstrip('#').strip().lower()
if hex_code.startswith("ff") and len(hex_code) == 8:
hex_code = hex_code[2:]
if len(hex_code) != 6:
raise ValueError(f"Expected 6-character hex code, got: {hex_code}")
return tuple(int(hex_code[i:i + 2], 16) for i in (0, 2, 4))
Expand Down
23 changes: 12 additions & 11 deletions ovos_plugin_manager/hardware/led/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, leds: AbstractLed, color: Color):
@param color: Base color of LEDs
"""
LedAnimation.__init__(self, leds)
self.color_tuple = color.as_rgb_tuple()
self.color = color
self.step = 0.05
self.step_delay = 0.05
self.stopping = Event()
Expand All @@ -50,7 +50,8 @@ def start(self, timeout=None):
step = self.step

brightness += step
self.leds.fill(tuple(brightness * part for part in self.color_tuple))
self.leds.fill(tuple(brightness * part for part in
self.color.as_rgb_tuple()))
sleep(self.step_delay)
if end_time and time() > end_time:
self.stopping.set()
Expand All @@ -71,8 +72,8 @@ def __init__(self, leds: AbstractLed, foreground_color: Color,
@param background_color: Color of inactive LEDs
"""
LedAnimation.__init__(self, leds)
self.foreground_color_tuple: tuple = foreground_color.as_rgb_tuple()
self.background_color_tuple: tuple = background_color.as_rgb_tuple()
self.foreground_color = foreground_color
self.background_color = background_color
self.step = 0.05
self.step_delay = 0.1
self.stopping = Event()
Expand All @@ -81,12 +82,12 @@ def start(self, timeout=None):
self.stopping.clear()
end_time = time() + timeout if timeout else None

self.leds.fill(self.background_color_tuple)
self.leds.fill(self.background_color.as_rgb_tuple())
while not self.stopping.is_set():
for led in range(0, self.leds.num_leds):
self.leds.set_led(led, self.foreground_color_tuple)
self.leds.set_led(led, self.foreground_color.as_rgb_tuple())
sleep(self.step_delay)
self.leds.set_led(led, self.background_color_tuple)
self.leds.set_led(led, self.background_color.as_rgb_tuple())
if end_time and time() > end_time:
self.stopping.set()
self.leds.fill(Color.BLACK.as_rgb_tuple())
Expand All @@ -106,7 +107,7 @@ def __init__(self, leds: AbstractLed, fill_color: Color,
@param reverse: If true, fill in reverse order
"""
LedAnimation.__init__(self, leds)
self.fill_color_tuple = fill_color.as_rgb_tuple()
self.fill_color = fill_color
self.reverse = reverse
self.step_delay = 0.05

Expand All @@ -115,7 +116,7 @@ def start(self, timeout=None):
if self.reverse:
leds.reverse()
for led in leds:
self.leds.set_led(led, self.fill_color_tuple)
self.leds.set_led(led, self.fill_color.as_rgb_tuple())
sleep(self.step_delay)

def stop(self):
Expand Down Expand Up @@ -177,10 +178,10 @@ def start(self, timeout=None):
while not self.stopping.is_set():
self.fill_animation.start()
self.fill_animation.reverse = not self.fill_animation.reverse
self.fill_animation.fill_color_tuple = Color.BLACK.as_rgb_tuple()
self.fill_animation.fill_color = Color.BLACK
self.fill_animation.start()
self.fill_animation.reverse = not self.fill_animation.reverse
self.fill_animation.fill_color_tuple = self.fill_color.as_rgb_tuple()
self.fill_animation.fill_color = self.fill_color
if end_time and time() > end_time:
self.stopping.set()

Expand Down
3 changes: 3 additions & 0 deletions test/unittests/test_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ def test_color(self):

Color.set_theme('#aaaaaa')
self.assertEqual(Color.THEME.as_rgb_tuple(), Color.from_hex('#aaaaaa'))

Color.set_theme('#FFFF0000')
self.assertEqual(Color.THEME.as_rgb_tuple(), (255, 0, 0))