Skip to content

Fix brightness. Fixes #2 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2017
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
17 changes: 9 additions & 8 deletions adafruit_dotstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def __init__(self, clock, data, n, brightness=1.0, auto_write=True):
# Supply one extra clock cycle for each two pixels in the strip.
self.end_header = n // 16
if n % 16 != 0:
n += 1
self.end_header += 1
self.buf = bytearray(n * 4 + self.start_header + self.end_header)

# Four empty bytes to start.
for i in range(self.start_header):
self.buf[i] = 0x00
Expand Down Expand Up @@ -203,18 +204,18 @@ def show(self):
it may be done asynchronously."""
# Create a second output buffer if we need to compute brightness
buf = self.buf
if self.brightness < 0.99:
buf = bytearray(n * bpp + 8)
if self.brightness < 1.0:
buf = bytearray(self.n * 4 + self.start_header + self.end_header)
# Four empty bytes to start.
for i in range(4):
for i in range(self.start_header):
buf[i] = 0x00
for i in range(4, len(self.buf) - 4):
for i in range(self.start_header, len(self.buf) - self.end_header - 1):
if i % 4 == 0:
buf[i] = self.buf
buf[i] = self.buf[i]
continue
buf[i] = self.buf[i] * self._brightness
buf[i] = int(self.buf[i] * self._brightness)
# Four 0xff bytes at the end.
for i in range(4):
for i in range(self.end_header):
buf[len(self.buf) - 4 + i] = 0xff

if self.spi:
Expand Down