You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB
Python

#!/bin/python3
from omnia import leds
import pygame
# Re-implementation of LED in order to handle it ourself
class MyLED(leds.LED):
def __init__(self, alias, order):
self.alias = alias
self._state = leds.LedState(
r = 0,
g = 0,
b = 0,
brightness = 0,
autonomous = False,
)
self.order = order
self.pgled = PGLED(order)
@property
def state(self):
return self._state
def set(self, state):
self._state = state
self.pgled.show(state)
class PGLED:
"""This holds a pygame object to display the LED"""
SIZE = 30 # px incl. margins
BULB = 6 # px radius
def __init__(self, order):
self.order = order
self.rect = pygame.Rect(self.SIZE * self.order, 0, self.SIZE, self.SIZE)
self.surface = None
def set_surface(self, surf):
self.surface = surf
def show(self, state: leds.LedState):
# Fill with black
black = pygame.Color(0,0,0)
pygame.draw.rect(self.surface, black, self.rect)
# Draw the circle with required color
# And respect the brightness
color = pygame.Color(state.r * state.brightness//255, state.g * state.brightness//255, state.b * state.brightness//255)
pygame.draw.circle(self.surface, color, self.rect.center, self.BULB)
pygame.display.flip()
my_strip = leds.LedStrip([MyLED(al, i) for i, al in enumerate(leds.omnia_led_order)])
w = PGLED.SIZE * len(my_strip)
h = PGLED.SIZE
pygame.init()
pygame.mixer.quit()
display = pygame.display.set_mode((w, h))
display.fill((0,0,0))
pygame.display.flip()
for led in my_strip:
led.pgled.set_surface(display)