Skip to content

Commit

Permalink
Merge pull request #3 from chickadee-tech/fix_brightness
Browse files Browse the repository at this point in the history
Fix brightness. Fixes #2
  • Loading branch information
dhalbert authored Sep 12, 2017
2 parents 14205d8 + 396e1a8 commit a6251c9
Showing 1 changed file with 9 additions and 8 deletions.
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

0 comments on commit a6251c9

Please sign in to comment.