Skip to content

Commit

Permalink
improve apa102 display fcn
Browse files Browse the repository at this point in the history
Actually for APA102 LEDs, the start-frame needs to be zeros of 32bit size.
For the end-frame n/2 bits needs to be written (n is size of apa102 strip.
This improvement reduces the bytes needed to be written resulting in notable increase of speed.
  • Loading branch information
markoaurelije authored Nov 2, 2024
1 parent cfc425a commit 57d13ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions luma/led_matrix/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@ def display(self, image):
assert image.size == self.size
self._last_image = image.copy()

# Send zeros to reset, then pixel values then zeros at end
# Send 32 zero-bits to reset, then pixel values then n/2 zero-bits at end
sz = image.width * image.height * 4
buf = bytearray(sz * 3)
buf = bytearray(4 + sz + round(image.width * image.height/8/2))

m = self._mapping
for idx, (r, g, b, a) in enumerate(image.getdata()):
offset = sz + m[idx] * 4
offset = 4 + m[idx] * 4
brightness = (a >> 4) if a != 0xFF else self._brightness
buf[offset] = (0xE0 | brightness)
buf[offset + 1] = b
Expand Down

0 comments on commit 57d13ce

Please sign in to comment.