Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 49cadeb

Browse files
authored
Merge pull request #26 from dunkmann00/dotstar-brightness
Dotstar brightness and Initialization
2 parents e52c672 + d184076 commit 49cadeb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

adafruit_pypixelbuf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def __init__( # pylint: disable=too-many-locals,too-many-arguments
9898
byteorder_tuple[2] + 1,
9999
0,
100100
)
101+
# Initialize the buffer with the dotstar start bytes.
102+
for i in range(self._offset, self._bytes + self._offset, 4):
103+
self._post_brightness_buffer[i] = DOTSTAR_LED_START_FULL_BRIGHT
101104

102105
self._brightness = 1.0
103106
self.brightness = brightness
@@ -252,9 +255,7 @@ def _parse_color(self, value):
252255
# LED startframe is three "1" bits, followed by 5 brightness bits
253256
# then 8 bits for each of R, G, and B. The order of those 3 are configurable and
254257
# vary based on hardware
255-
# same as math.ceil(brightness * 31) & 0b00011111
256-
# Idea from https://www.codeproject.com/Tips/700780/Fast-floor-ceiling-functions
257-
w = (32 - int(32 - w * 31) & 0b00011111) | DOTSTAR_LED_START
258+
w = (int(w * 31) & 0b00011111) | DOTSTAR_LED_START
258259
elif (
259260
self._has_white
260261
and (isinstance(value, int) or len(value) == 3)

0 commit comments

Comments
 (0)