forked from dylanrush/categorical-sectional
-
Notifications
You must be signed in to change notification settings - Fork 17
/
renderer.py
48 lines (38 loc) · 1.61 KB
/
renderer.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
import lib.local_debug as local_debug
from configuration import configuration
from lib.safe_logging import safe_log
from renderers.debug import Renderer
if local_debug.is_debug():
from renderers import debug
elif configuration.get_mode() == configuration.WS2801:
from renderers import ws2801
elif configuration.get_mode() == configuration.WS281x:
from renderers import ws281x
else:
from renderers import debug
def get_renderer() -> Renderer:
"""
Returns the renderer to use based on the type of
LED lights given in the config.
Returns:
renderer -- Object that takes the colors and airport config and
sets the LEDs.
"""
if local_debug.is_debug():
return Renderer(configuration.CONFIG[configuration.PIXEL_COUNT_KEY])
if configuration.get_mode() == configuration.WS2801:
pixel_count = configuration.CONFIG[configuration.PIXEL_COUNT_KEY]
spi_port = configuration.CONFIG[configuration.SPI_PORT_KEY]
spi_device = configuration.CONFIG[configuration.SPI_DEVICE_KEY]
return ws2801.Ws2801Renderer(pixel_count, spi_port, spi_device)
elif configuration.get_mode() == configuration.WS281x:
pixel_count = configuration.CONFIG[configuration.PIXEL_COUNT_KEY]
gpio_pin = configuration.CONFIG[configuration.GPIO_PIN_KEY]
safe_log("Setting up WS281x on Pin{} for {} lights".format(
gpio_pin,
pixel_count))
return ws281x.Ws281xRenderer(
pixel_count,
gpio_pin,
configuration.get_pixel_order())
return Renderer(configuration.CONFIG[configuration.PIXEL_COUNT_KEY])