Skip to content

Commit a6251c9

Browse files
authored
Merge pull request #3 from chickadee-tech/fix_brightness
Fix brightness. Fixes #2
2 parents 14205d8 + 396e1a8 commit a6251c9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

adafruit_dotstar.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ def __init__(self, clock, data, n, brightness=1.0, auto_write=True):
7676
# Supply one extra clock cycle for each two pixels in the strip.
7777
self.end_header = n // 16
7878
if n % 16 != 0:
79-
n += 1
79+
self.end_header += 1
8080
self.buf = bytearray(n * 4 + self.start_header + self.end_header)
81+
8182
# Four empty bytes to start.
8283
for i in range(self.start_header):
8384
self.buf[i] = 0x00
@@ -203,18 +204,18 @@ def show(self):
203204
it may be done asynchronously."""
204205
# Create a second output buffer if we need to compute brightness
205206
buf = self.buf
206-
if self.brightness < 0.99:
207-
buf = bytearray(n * bpp + 8)
207+
if self.brightness < 1.0:
208+
buf = bytearray(self.n * 4 + self.start_header + self.end_header)
208209
# Four empty bytes to start.
209-
for i in range(4):
210+
for i in range(self.start_header):
210211
buf[i] = 0x00
211-
for i in range(4, len(self.buf) - 4):
212+
for i in range(self.start_header, len(self.buf) - self.end_header - 1):
212213
if i % 4 == 0:
213-
buf[i] = self.buf
214+
buf[i] = self.buf[i]
214215
continue
215-
buf[i] = self.buf[i] * self._brightness
216+
buf[i] = int(self.buf[i] * self._brightness)
216217
# Four 0xff bytes at the end.
217-
for i in range(4):
218+
for i in range(self.end_header):
218219
buf[len(self.buf) - 4 + i] = 0xff
219220

220221
if self.spi:

0 commit comments

Comments
 (0)