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

Dotstar brightness and Initialization #26

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions adafruit_pypixelbuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -252,9 +255,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)
Expand Down