43
43
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
44
44
"""
45
45
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
57
47
58
48
__version__ = "0.0.0-auto.0"
59
49
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI.git"
68
58
GRBW = 'GRBW'
69
59
"""Green Red Blue White"""
70
60
71
- class NeoPixel_SPI (NeoPixel ):
61
+ class NeoPixel_SPI (PixelBuf ):
72
62
"""
73
63
A sequence of neopixels.
74
64
@@ -91,45 +81,20 @@ class NeoPixel_SPI(NeoPixel):
91
81
pixels = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
92
82
pixels.fill(0xff0000)
93
83
"""
94
- #pylint: disable=invalid-name, super-init-not-called, too-many-instance-attributes
84
+ #pylint: disable=invalid-name
95
85
96
86
FREQ = 6400000 # 800kHz * 8, actual may be different
97
87
TRST = 80e-6 # Reset code low level time
98
88
99
89
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
107
92
if not pixel_order :
108
93
pixel_order = GRB if bpp == 3 else GRBW
109
94
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
133
98
from adafruit_bus_device .spi_device import SPIDevice
134
99
self ._spi = SPIDevice (spi , baudrate = self .FREQ )
135
100
with self ._spi as spibus :
@@ -142,6 +107,13 @@ def __init__(self, spi, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_orde
142
107
self .RESET = bytes ([0 ]* round (freq * self .TRST / 8 ))
143
108
self .spibuf = bytearray (8 * n * bpp )
144
109
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
+
145
117
def deinit (self ):
146
118
"""Blank out the NeoPixels."""
147
119
self .fill (0 )
@@ -169,3 +141,7 @@ def _transmogrify(self):
169
141
else :
170
142
self .spibuf [k ] = 0b11000000 # A NeoPixel 0 bit
171
143
k += 1
144
+
145
+ def fill (self , color ):
146
+ """Colors all pixels the given ***color***."""
147
+ fill (self , color )
0 commit comments