Skip to content

Instantly share code, notes, and snippets.

@adammhaile
Created May 1, 2017 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammhaile/3084947b80c69b2f6ce0739ff385e7bf to your computer and use it in GitHub Desktop.
Save adammhaile/3084947b80c69b2f6ce0739ff385e7bf to your computer and use it in GitHub Desktop.
SK9822 BiblioPixel Driver
from spi_driver_base import DriverSPIBase, ChannelOrder
class DriverSK9822(DriverSPIBase):
"""Main driver for SK9822 based LED strips on devices like the Raspberry Pi and BeagleBone"""
def __init__(self, num, c_order=ChannelOrder.RGB, use_py_spi=True, dev="/dev/spidev0.0", SPISpeed=2):
super(DriverSK9822, self).__init__(num, c_order=c_order,
use_py_spi=use_py_spi, dev=dev, SPISpeed=SPISpeed)
# SK9822 requires latch bytes at the end
self._latchBytes = (int(num / 64.0) + 1)
def _fixData(self, data):
gamma = self.gamma
self._buf[:] = [0] * self.bufByteCount
for a, b in enumerate(self.c_order):
self._buf[a:self.numLEDs * 3:3] = [gamma[v] for v in data[b::3]]
newBuf = [0xFF] * (self.bufByteCount + self.numLEDs)
newBuf[1::4] = self._buf[0::3]
newBuf[2::4] = self._buf[1::3]
newBuf[3::4] = self._buf[2::3]
self._buf[:] = [0, 0, 0, 0] + newBuf
self._buf.extend([0, 0, 0, 0] * self._latchBytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment