From 3cb945a636b0fb7a66fa880f2de71d65f7f2687c Mon Sep 17 00:00:00 2001 From: George Waters Date: Mon, 13 Jul 2020 21:25:37 -0400 Subject: [PATCH 1/2] Truncate brightness byte value, same as pixelbuf --- adafruit_pypixelbuf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_pypixelbuf.py b/adafruit_pypixelbuf.py index c0d0469..01c655e 100644 --- a/adafruit_pypixelbuf.py +++ b/adafruit_pypixelbuf.py @@ -252,9 +252,7 @@ def _parse_color(self, value): # LED startframe is three "1" bits, followed by 5 brightness bits # then 8 bits for each of R, G, and B. The order of those 3 are configurable and # vary based on hardware - # same as math.ceil(brightness * 31) & 0b00011111 - # Idea from https://www.codeproject.com/Tips/700780/Fast-floor-ceiling-functions - w = (32 - int(32 - w * 31) & 0b00011111) | DOTSTAR_LED_START + w = (int(w * 31) & 0b00011111) | DOTSTAR_LED_START elif ( self._has_white and (isinstance(value, int) or len(value) == 3) From d1840763fd49657d69da16ec8202d26bee29638a Mon Sep 17 00:00:00 2001 From: George Waters Date: Mon, 13 Jul 2020 21:38:35 -0400 Subject: [PATCH 2/2] Initialize dotstar buffer with start bytes --- adafruit_pypixelbuf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_pypixelbuf.py b/adafruit_pypixelbuf.py index 01c655e..3cb83e9 100644 --- a/adafruit_pypixelbuf.py +++ b/adafruit_pypixelbuf.py @@ -98,6 +98,9 @@ def __init__( # pylint: disable=too-many-locals,too-many-arguments byteorder_tuple[2] + 1, 0, ) + # Initialize the buffer with the dotstar start bytes. + for i in range(self._offset, self._bytes + self._offset, 4): + self._post_brightness_buffer[i] = DOTSTAR_LED_START_FULL_BRIGHT self._brightness = 1.0 self.brightness = brightness