Skip to content

Commit 2064e3d

Browse files
committed
Maintain legacy comptibility with Unicorn HAT
1 parent 29725fa commit 2064e3d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/rpi_ws281x/rpi_ws281x.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __setitem__(self, pos, value):
5050

5151
class PixelStrip(object):
5252
def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
53-
brightness=255, channel=0, strip_type=ws.WS2811_STRIP_RGB, gamma=None):
53+
brightness=255, channel=0, strip_type=None, gamma=None):
5454
"""Class to represent a SK6812/WS281x LED display. Num should be the
5555
number of pixels in the display, and pin should be the GPIO pin connected
5656
to the display signal line (must be a PWM pin like 18!). Optional
@@ -63,12 +63,14 @@ def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
6363
if gamma is None:
6464
# Support gamma in place of strip_type for back-compat with
6565
# previous version of forked library
66-
if type(strip_type) is list and len(strip_type) == 255:
66+
if type(strip_type) is list and len(strip_type) == 256:
6767
gamma = strip_type
68+
strip_type = None
6869
else:
6970
gamma = list(range(256))
7071

71-
self._gamma = gamma
72+
if strip_type is None:
73+
strip_type = ws.WS2811_STRIP_GRB
7274

7375
# Create ws2811_t structure and fill in parameters.
7476
self._leds = ws.new_ws2811_t()
@@ -83,7 +85,7 @@ def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
8385

8486
# Initialize the channel in use
8587
self._channel = ws.ws2811_channel_get(self._leds, channel)
86-
ws.ws2811_channel_t_gamma_set(self._channel, self._gamma)
88+
ws.ws2811_channel_t_gamma_set(self._channel, gamma)
8789
ws.ws2811_channel_t_count_set(self._channel, num)
8890
ws.ws2811_channel_t_gpionum_set(self._channel, pin)
8991
ws.ws2811_channel_t_invert_set(self._channel, 0 if not invert else 1)
@@ -109,8 +111,7 @@ def _cleanup(self):
109111

110112
def setGamma(self, gamma):
111113
if type(gamma) is list and len(gamma) == 256:
112-
self._gamma = gamma
113-
ws.ws2811_channel_t_gamma_set(self._channel, self._gamma)
114+
ws.ws2811_channel_t_gamma_set(self._channel, gamma)
114115

115116
def begin(self):
116117
"""Initialize library, must be called once before other functions are

0 commit comments

Comments
 (0)