-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_display.py
49 lines (45 loc) · 1.66 KB
/
led_display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import sys
from typing import Any
import aiomisc
import asyncio
import neopixel
from adafruit_blinka.microcontroller.generic_micropython import Pin
from adafruit_pixel_framebuf import PixelFramebuffer
from animation import animation
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout))
class LedDisplay(aiomisc.Service):
def __init__(self, led_pin: Pin, pixel_width: int, pixel_height: int, **kwargs: Any):
super().__init__(**kwargs)
self._leds_width = pixel_width
self._leds_height = pixel_height
self._pixels = neopixel.NeoPixel(
led_pin,
pixel_width * pixel_height,
brightness=0.1,
auto_write=False)
# noinspection PyTypeChecker
self._pixel_buf = PixelFramebuffer(
self._pixels,
pixel_width,
pixel_height,
reverse_x=True)
# clear display
logger.info('Clearing display')
self._pixel_buf.fill_rect(0, 0, pixel_width, pixel_height, 0x000000)
self._pixel_buf.display()
async def start(self):
logger.info(f'Starting LedDisplay')
while True:
if animation.frames:
logger.debug(f'Animation frames: {animation.frames}')
for frame in animation.frames:
logger.debug('Animating frame')
self._pixel_buf.image(frame)
self._pixel_buf.display()
await asyncio.sleep(animation.speed)
else:
logger.debug('Waiting for frames')
await asyncio.sleep(animation.speed)