diff options
author | Radomir Dopieralski <openstack@sheep.art.pl> | 2016-10-19 22:09:51 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-10-25 14:21:07 +1100 |
commit | 984a867341970f311a143906d62c74fa1bfb93fb (patch) | |
tree | 283e0d2b2a5db15cfbf1e36735a2f38b203162a1 /esp8266/scripts/apa102.py | |
parent | f1b2b1b600cd21d4835c3ad6c784eaafd215c046 (diff) |
esp8266/scripts: Make neopixel/apa102 handle 4bpp LEDs with common code.
The NeoPixel class now handles 4 bytes-per-pixel LEDs (extra byte is
intensity) and arbitrary byte ordering. APA102 class is now derived from
NeoPixel to reduce code size and support fill() operation.
Diffstat (limited to 'esp8266/scripts/apa102.py')
-rw-r--r-- | esp8266/scripts/apa102.py | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/esp8266/scripts/apa102.py b/esp8266/scripts/apa102.py index 126448cc2..41b7c0485 100644 --- a/esp8266/scripts/apa102.py +++ b/esp8266/scripts/apa102.py @@ -2,27 +2,16 @@ # MIT license; Copyright (c) 2016 Robert Foss, Daniel Busch from esp import apa102_write +from neopixel import NeoPixel -class APA102: - def __init__(self, clock_pin, data_pin, n): - self.clock_pin = clock_pin - self.data_pin = data_pin - self.n = n - self.buf = bytearray(n * 4) - - self.clock_pin.init(clock_pin.OUT) - self.data_pin.init(data_pin.OUT) - def __setitem__(self, index, val): - r, g, b, brightness = val - self.buf[index * 4] = r - self.buf[index * 4 + 1] = g - self.buf[index * 4 + 2] = b - self.buf[index * 4 + 3] = brightness +class APA102(NeoPixel): + ORDER = (0, 1, 2, 3) - def __getitem__(self, index): - i = index * 4 - return self.buf[i], self.buf[i + 1], self.buf[i + 2], self.buf[i + 3] + def __init__(self, clock_pin, data_pin, n, bpp=4): + super().__init__(data_pin, n, bpp) + self.clock_pin = clock_pin + self.clock_pin.init(clock_pin.OUT) def write(self): - apa102_write(self.clock_pin, self.data_pin, self.buf) + apa102_write(self.clock_pin, self.pin, self.buf) |