Skip to content

Commit c5522d5

Browse files
author
Melissa LeBlanc-Williams
committed
Undid class split. Linting.
1 parent b862de5 commit c5522d5

File tree

3 files changed

+64
-123
lines changed

3 files changed

+64
-123
lines changed

adafruit_featherwing/dotstar_featherwing.py

Lines changed: 50 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@
3434
import board
3535
import adafruit_dotstar as dotstar
3636

37-
class PixelDisplayFeatherWing:
38-
"""Base Class for DotStar and NeoPixel FeatherWings
37+
class DotStarFeatherWing:
38+
"""Class representing a `DotStar FeatherWing
39+
<https://www.adafruit.com/product/3449>`_.
3940
4041
The feather uses pins D13 and D11"""
41-
def __init__(self):
42-
self.rows = 0
43-
self.columns = 0
44-
self._display = None
42+
def __init__(self, clock=board.D13, data=board.D11, brightness=0.2):
43+
"""
44+
:param pin clock: The clock pin for the featherwing
45+
:param pin data: The data pin for the featherwing
46+
:param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
47+
"""
48+
self.rows = 6
49+
self.columns = 12
4550
self._auto_write = True
51+
self._display = dotstar.DotStar(clock, data, self.rows * self.columns,
52+
brightness=brightness, auto_write=False)
4653

4754
def __setitem__(self, indices, value):
4855
"""
@@ -56,9 +63,8 @@ def __setitem__(self, indices, value):
5663
a single, longer int that contains RGB values, like 0xFFFFFF
5764
brightness, if specified should be a float 0-1
5865
"""
59-
if self._display is not None:
60-
self._display[self._get_index(indices)] = value
61-
self._update()
66+
self._display[self._get_index(indices)] = value
67+
self._update()
6268

6369
def __getitem__(self, indices):
6470
"""
@@ -67,10 +73,7 @@ def __getitem__(self, indices):
6773
a slice of DotStar indexes to retrieve
6874
a single int that specifies the DotStar index
6975
"""
70-
if self._display is not None:
71-
return self._display[self._get_index(indices)]
72-
else:
73-
return None
76+
return self._display[self._get_index(indices)]
7477

7578
def _get_index(self, indices):
7679
"""
@@ -92,88 +95,6 @@ def _get_index(self, indices):
9295
else:
9396
raise ValueError('Index must be 1 or 2 number')
9497

95-
def _update(self):
96-
"""
97-
Update the Display automatically if auto_write is set to True
98-
"""
99-
if self._auto_write:
100-
self._display.show()
101-
102-
def _fill(self, color=0):
103-
"""
104-
Fills all of the Pixels with a color or unlit if empty.
105-
"""
106-
self._display.fill(color)
107-
self._update()
108-
109-
def _show(self):
110-
"""
111-
Update the Pixels. This is only needed if auto_write is set to False
112-
This can be very useful for more advanced graphics effects.
113-
"""
114-
self._display.show()
115-
116-
def _shift_right(self, rotate=False):
117-
"""
118-
Shift all pixels right
119-
"""
120-
for y in range(0, self.rows):
121-
last_pixel = self._display[(y + 1) * self.columns - 1] if rotate else 0
122-
for x in range(self.columns - 1, 0, -1):
123-
self._display[y * self.columns + x] = self._display[y * self.columns + x - 1]
124-
self._display[y * self.columns] = last_pixel
125-
self._update()
126-
127-
def _shift_left(self, rotate=False):
128-
"""
129-
Shift all pixels left
130-
"""
131-
for y in range(0, self.rows):
132-
last_pixel = self._display[y * self.columns] if rotate else 0
133-
for x in range(0, self.columns - 1):
134-
self._display[y * self.columns + x] = self._display[y * self.columns + x + 1]
135-
self._display[(y + 1) * self.columns - 1] = last_pixel
136-
self._update()
137-
138-
def _shift_up(self, rotate=False):
139-
"""
140-
Shift all pixels up
141-
"""
142-
for x in range(0, self.columns):
143-
last_pixel = self._display[(self.rows - 1) * self.columns + x] if rotate else 0
144-
for y in range(self.rows - 1, 0, -1):
145-
self._display[y * self.columns + x] = self._display[(y - 1) * self.columns + x]
146-
self._display[x] = last_pixel
147-
self._update()
148-
149-
def _shift_down(self, rotate=False):
150-
"""
151-
Shift all pixels down
152-
"""
153-
for x in range(0, self.columns):
154-
last_pixel = self._display[x] if rotate else 0
155-
for y in range(0, self.rows - 1):
156-
self._display[y * self.columns + x] = self._display[(y + 1) * self.columns + x]
157-
self._display[(self.rows - 1) * self.columns + x] = last_pixel
158-
self._update()
159-
160-
class DotStarFeatherWing(PixelDisplayFeatherWing):
161-
"""Class representing a `DotStar FeatherWing
162-
<https://www.adafruit.com/product/3449>`_.
163-
164-
The feather uses pins D13 and D11"""
165-
def __init__(self, clock=board.D13, data=board.D11, brightness=0.2):
166-
"""
167-
:param pin clock: The clock pin for the featherwing
168-
:param pin data: The data pin for the featherwing
169-
:param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
170-
"""
171-
super().__init__()
172-
self.rows = 6
173-
self.columns = 12
174-
self._display = dotstar.DotStar(clock, data, self.rows * self.columns,
175-
brightness=brightness, auto_write=False)
176-
17798
def fill(self, color=0):
17899
"""
179100
Fills all of the DotStars with a color or unlit if empty.
@@ -198,7 +119,8 @@ def fill(self, color=0):
198119
dotstar.fill() # Clear all lit DotStars
199120
200121
"""
201-
super()._fill(color)
122+
self._display.fill(color)
123+
self._update()
202124

203125
def show(self):
204126
"""
@@ -220,7 +142,7 @@ def show(self):
220142
dotstar.show() # Update the DotStars
221143
222144
"""
223-
super()._show()
145+
self._display.show()
224146

225147
def shift_right(self, rotate=False):
226148
"""
@@ -253,7 +175,12 @@ def shift_right(self, rotate=False):
253175
time.sleep(.1)
254176
255177
"""
256-
super()._shift_right(rotate)
178+
for y in range(0, self.rows):
179+
last_pixel = self._display[(y + 1) * self.columns - 1] if rotate else 0
180+
for x in range(self.columns - 1, 0, -1):
181+
self._display[y * self.columns + x] = self._display[y * self.columns + x - 1]
182+
self._display[y * self.columns] = last_pixel
183+
self._update()
257184

258185
def shift_left(self, rotate=False):
259186
"""
@@ -286,7 +213,12 @@ def shift_left(self, rotate=False):
286213
time.sleep(.1)
287214
288215
"""
289-
super()._shift_left(rotate)
216+
for y in range(0, self.rows):
217+
last_pixel = self._display[y * self.columns] if rotate else 0
218+
for x in range(0, self.columns - 1):
219+
self._display[y * self.columns + x] = self._display[y * self.columns + x + 1]
220+
self._display[(y + 1) * self.columns - 1] = last_pixel
221+
self._update()
290222

291223
def shift_up(self, rotate=False):
292224
"""
@@ -319,7 +251,12 @@ def shift_up(self, rotate=False):
319251
time.sleep(.1)
320252
321253
"""
322-
super()._shift_up(rotate)
254+
for x in range(0, self.columns):
255+
last_pixel = self._display[(self.rows - 1) * self.columns + x] if rotate else 0
256+
for y in range(self.rows - 1, 0, -1):
257+
self._display[y * self.columns + x] = self._display[(y - 1) * self.columns + x]
258+
self._display[x] = last_pixel
259+
self._update()
323260

324261
def shift_down(self, rotate=False):
325262
"""
@@ -352,7 +289,19 @@ def shift_down(self, rotate=False):
352289
time.sleep(.1)
353290
354291
"""
355-
super()._shift_down(rotate)
292+
for x in range(0, self.columns):
293+
last_pixel = self._display[x] if rotate else 0
294+
for y in range(0, self.rows - 1):
295+
self._display[y * self.columns + x] = self._display[(y + 1) * self.columns + x]
296+
self._display[(self.rows - 1) * self.columns + x] = last_pixel
297+
self._update()
298+
299+
def _update(self):
300+
"""
301+
Update the Display automatically if auto_write is set to True
302+
"""
303+
if self._auto_write:
304+
self._display.show()
356305

357306
@property
358307
def auto_write(self):

adafruit_featherwing/neopixel_featherwing.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,26 @@
3333

3434
import board
3535
import neopixel
36-
from adafruit_featherwing.dotstar_featherwing import PixelDisplayFeatherWing
36+
from adafruit_featherwing.dotstar_featherwing import DotStarFeatherWing
3737

38-
class NeoPixelFeatherWing(PixelDisplayFeatherWing):
38+
class NeoPixelFeatherWing(DotStarFeatherWing):
3939
"""Class representing a `NeoPixel FeatherWing
4040
<https://www.adafruit.com/product/2945>`_.
4141
4242
The feather uses pins D6 by default"""
43+
#pylint: disable-msg=super-init-not-called
4344
def __init__(self, pixel_pin=board.D6, brightness=0.1):
4445
"""
4546
:param pin pixel_pin: The pin for the featherwing
4647
:param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
4748
"""
48-
super().__init__()
4949
self.rows = 4
5050
self.columns = 8
51+
self._auto_write = True
5152
self._display = neopixel.NeoPixel(pixel_pin, self.rows * self.columns,
5253
brightness=brightness, auto_write=False,
5354
pixel_order=neopixel.GRB)
55+
#pylint: enable-msg=super-init-not-called
5456

5557
def fill(self, color=0):
5658
"""
@@ -74,7 +76,7 @@ def fill(self, color=0):
7476
neopixel.fill() # Clear all lit NeoPixels
7577
7678
"""
77-
super()._fill(color)
79+
super().fill(color)
7880

7981
def show(self):
8082
"""
@@ -96,7 +98,7 @@ def show(self):
9698
neopixel.show() # Update the NeoPixels
9799
98100
"""
99-
super()._show()
101+
super().show()
100102

101103
def shift_right(self, rotate=False):
102104
"""
@@ -129,7 +131,7 @@ def shift_right(self, rotate=False):
129131
time.sleep(.1)
130132
131133
"""
132-
super()._shift_right(rotate)
134+
super().shift_right(rotate)
133135

134136
def shift_left(self, rotate=False):
135137
"""
@@ -162,7 +164,7 @@ def shift_left(self, rotate=False):
162164
time.sleep(.1)
163165
164166
"""
165-
super()._shift_left(rotate)
167+
super().shift_left(rotate)
166168

167169
def shift_up(self, rotate=False):
168170
"""
@@ -195,7 +197,7 @@ def shift_up(self, rotate=False):
195197
time.sleep(.1)
196198
197199
"""
198-
super()._shift_down(rotate) # Up and down are reversed
200+
super().shift_down(rotate) # Up and down are reversed
199201

200202
def shift_down(self, rotate=False):
201203
"""
@@ -228,7 +230,7 @@ def shift_down(self, rotate=False):
228230
time.sleep(.1)
229231
230232
"""
231-
super()._shift_up(rotate) # Up and down are reversed
233+
super().shift_up(rotate) # Up and down are reversed
232234

233235
@property
234236
def auto_write(self):
@@ -254,12 +256,7 @@ def auto_write(self):
254256
neopixel.show() # Update the NeoPixels
255257
256258
"""
257-
return self._auto_write
258-
259-
@auto_write.setter
260-
def auto_write(self, write):
261-
if isinstance(write, bool):
262-
self._auto_write = write
259+
return super().auto_write
263260

264261
@property
265262
def brightness(self):
@@ -283,9 +280,4 @@ def brightness(self):
283280
neopixel.brightness = 0.3
284281
285282
"""
286-
return self._display.brightness
287-
288-
@brightness.setter
289-
def brightness(self, brightness):
290-
self._display.brightness = min(max(brightness, 0.0), 1.0)
291-
self._update()
283+
return super().brightness

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Ensure your device works with this simple test.
2626
Other tests
2727
------------
2828

29-
.. literalinclude:: ../examples/featherwing_dotstar_palettetest.py
29+
.. literalinclude:: ../examples/featherwing_dotstar_palette_example.py
3030
:caption: examples/featherwing_dotstar_palette_example.py
3131
:linenos:
3232

0 commit comments

Comments
 (0)