Skip to content

Commit 175796e

Browse files
committed
change base class to pypixebuf
1 parent c8ec8d8 commit 175796e

File tree

4 files changed

+22
-45
lines changed

4 files changed

+22
-45
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This driver depends on:
2222

2323
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
2424
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
25+
* `Pypixelbuf <https://github.com/adafruit/Adafruit_CircuitPython_Pypixelbuf>`_
2526

2627
Please ensure all dependencies are available on the CircuitPython filesystem.
2728
This is easily achieved by downloading

neopixel_spi.py

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,7 @@
4343
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
4444
"""
4545

46-
# The following creates a mock neopixel_write module to allow importing
47-
# the CircuitPython NeoPixel module without actually providing neopixel_write.
48-
#pylint: disable=wrong-import-position, exec-used
49-
import sys
50-
from types import ModuleType
51-
MOCK_MODULE = ModuleType('mock_neopixel_write')
52-
exec('def neopixel_write(): pass', MOCK_MODULE.__dict__)
53-
sys.modules['neopixel_write'] = MOCK_MODULE
54-
#pylint: enable=wrong-import-position, exec-used
55-
56-
from neopixel import NeoPixel
46+
from adafruit_pypixelbuf import PixelBuf, fill
5747

5848
__version__ = "0.0.0-auto.0"
5949
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI.git"
@@ -68,7 +58,7 @@
6858
GRBW = 'GRBW'
6959
"""Green Red Blue White"""
7060

71-
class NeoPixel_SPI(NeoPixel):
61+
class NeoPixel_SPI(PixelBuf):
7262
"""
7363
A sequence of neopixels.
7464
@@ -91,45 +81,20 @@ class NeoPixel_SPI(NeoPixel):
9181
pixels = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
9282
pixels.fill(0xff0000)
9383
"""
94-
#pylint: disable=invalid-name, super-init-not-called, too-many-instance-attributes
84+
#pylint: disable=invalid-name
9585

9686
FREQ = 6400000 # 800kHz * 8, actual may be different
9787
TRST = 80e-6 # Reset code low level time
9888

9989
def __init__(self, spi, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None):
100-
# We can't call super().__init__() since we don't actually
101-
# have a pin to supply it. So setup is done manually.
102-
#
103-
# neopixel stuff
104-
#
105-
self.bpp = bpp
106-
self.n = n
90+
91+
# configure bpp and pixel_order
10792
if not pixel_order:
10893
pixel_order = GRB if bpp == 3 else GRBW
10994
else:
110-
self.bpp = bpp = len(pixel_order)
111-
#
112-
# pypixelbuf stuff
113-
#
114-
bpp, byteorder_tuple, has_white, _ = self.parse_byteorder(pixel_order)
115-
self._pixels = n
116-
self._bytes = bpp * n
117-
self._byteorder = byteorder_tuple
118-
self._byteorder_string = pixel_order
119-
self._has_white = has_white
120-
self._bpp = bpp
121-
self._bytearray = bytearray(n * bpp)
122-
self._two_buffers = True
123-
self._rawbytearray = bytearray(n * bpp)
124-
self._offset = 0
125-
self._dotstar_mode = False
126-
self._pixel_step = bpp
127-
self.auto_write = False
128-
self.brightness = min(1.0, max(0, brightness))
129-
self.auto_write = auto_write
130-
#
131-
# neopixel_spi stuff
132-
#
95+
bpp = len(pixel_order)
96+
97+
# set up SPI related stuff
13398
from adafruit_bus_device.spi_device import SPIDevice
13499
self._spi = SPIDevice(spi, baudrate=self.FREQ)
135100
with self._spi as spibus:
@@ -142,6 +107,13 @@ def __init__(self, spi, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_orde
142107
self.RESET = bytes([0]*round(freq * self.TRST / 8))
143108
self.spibuf = bytearray(8 * n * bpp)
144109

110+
# everything else taken care of by base class
111+
super().__init__(n, bytearray(n * bpp),
112+
brightness=brightness,
113+
rawbuf=bytearray(n * bpp),
114+
byteorder=pixel_order,
115+
auto_write=auto_write)
116+
145117
def deinit(self):
146118
"""Blank out the NeoPixels."""
147119
self.fill(0)
@@ -169,3 +141,7 @@ def _transmogrify(self):
169141
else:
170142
self.spibuf[k] = 0b11000000 # A NeoPixel 0 bit
171143
k += 1
144+
145+
def fill(self, color):
146+
"""Colors all pixels the given ***color***."""
147+
fill(self, color)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Adafruit-Blinka
22
adafruit-circuitpython-busdevice
3-
adafruit-circuitpython-neopixel
3+
adafruit-circuitpython-pypixelbuf

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
install_requires=[
3737
'Adafruit-Blinka',
3838
'adafruit-circuitpython-busdevice',
39-
'adafruit-circuitpython-neopixel'
39+
'adafruit-circuitpython-pypixelbuf'
4040
],
4141

4242
# Choose your license

0 commit comments

Comments
 (0)