Skip to content

Commit

Permalink
Fix brightness. Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Sep 12, 2017
1 parent 14205d8 commit 88fb096
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 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 @@ -204,17 +205,17 @@ def show(self):
# Create a second output buffer if we need to compute brightness
buf = self.buf
if self.brightness < 0.99:
buf = bytearray(n * bpp + 8)
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

0 comments on commit 88fb096

Please sign in to comment.