From 05c06a326502fefefd3df72b06595469dd3c151e Mon Sep 17 00:00:00 2001 From: George Waters Date: Thu, 2 Jul 2020 17:17:21 -0400 Subject: [PATCH] Set auto_write after brightness in init This prevents an error from being thrown if the brightness is set to something other than 1.0 and the pin for the led's is not yet set. --- adafruit_pypixelbuf.py | 6 ++++-- examples/pypixelbuf_simpletest.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/adafruit_pypixelbuf.py b/adafruit_pypixelbuf.py index f36aded..66189fc 100644 --- a/adafruit_pypixelbuf.py +++ b/adafruit_pypixelbuf.py @@ -61,6 +61,8 @@ def __init__( # pylint: disable=too-many-locals,too-many-arguments bpp, byteorder_tuple, has_white, dotstar_mode = self.parse_byteorder(byteorder) + self.auto_write = False + effective_bpp = 4 if dotstar_mode else bpp _bytes = effective_bpp * n buf = bytearray(_bytes) @@ -89,8 +91,6 @@ def __init__( # pylint: disable=too-many-locals,too-many-arguments self._dotstar_mode = dotstar_mode self._pixel_step = effective_bpp - self.auto_write = auto_write - if dotstar_mode: self._byteorder_tuple = ( byteorder_tuple[0] + 1, @@ -102,6 +102,8 @@ def __init__( # pylint: disable=too-many-locals,too-many-arguments self._brightness = 1.0 self.brightness = brightness + self.auto_write = auto_write + @staticmethod def parse_byteorder(byteorder): """ diff --git a/examples/pypixelbuf_simpletest.py b/examples/pypixelbuf_simpletest.py index 2fe22e1..76a92bd 100644 --- a/examples/pypixelbuf_simpletest.py +++ b/examples/pypixelbuf_simpletest.py @@ -12,7 +12,7 @@ def _transmit(self, buffer): # pylint: disable=unused-argument self.called = True -buf = TestBuf(20, "RGBW", 1.0, auto_write=True) +buf = TestBuf(20, "RGBW", brightness=0.5, auto_write=True) buf[0] = (1, 2, 3) buf[1] = (1, 2, 3, 4) buf[2] = (2, 2, 2)