Skip to content

Commit a74a071

Browse files
author
Melissa LeBlanc-Williams
committed
Merge branch 'neopixel2'
2 parents f16b992 + 20f1c9b commit a74a071

File tree

3 files changed

+156
-122
lines changed

3 files changed

+156
-122
lines changed

adafruit_featherwing/dotstar_featherwing.py

Lines changed: 1 addition & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -33,126 +33,7 @@
3333

3434
import board
3535
import adafruit_dotstar as dotstar
36-
#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
37-
38-
class PixelMatrixFeatherWing:
39-
"""Base Class for DotStar and NeoPixel FeatherWings
40-
41-
The feather uses pins D13 and D11"""
42-
def __init__(self):
43-
self.rows = 0
44-
self.columns = 0
45-
self._matrix = None
46-
self._auto_write = True
47-
48-
def __setitem__(self, indices, value):
49-
"""
50-
indices can be one of three things:
51-
x and y ints that are calculated to the DotStar index
52-
a slice of DotStar indexes with a set of values that match the slice
53-
a single int that specifies the DotStar index
54-
value can be one of three things:
55-
a (r,g,b) list/tuple
56-
a (r,g,b, brightness) list/tuple
57-
a single, longer int that contains RGB values, like 0xFFFFFF
58-
brightness, if specified should be a float 0-1
59-
"""
60-
self._matrix[self._get_index(indices)] = value
61-
self._update()
62-
63-
def __getitem__(self, indices):
64-
"""
65-
indices can be one of three things:
66-
x and y ints that are calculated to the DotStar index
67-
a slice of DotStar indexes to retrieve
68-
a single int that specifies the DotStar index
69-
"""
70-
return self._matrix[self._get_index(indices)]
71-
72-
def _get_index(self, indices):
73-
"""
74-
Figure out which DotStar to address based on what was passed in
75-
"""
76-
if isinstance(indices, int):
77-
if not 0 <= indices < self.rows * self.columns:
78-
raise ValueError('The index of {} is out of range'.format(indices))
79-
return indices
80-
elif isinstance(indices, slice):
81-
return indices
82-
elif len(indices) == 2:
83-
x, y = indices
84-
if not 0 <= x < self.columns:
85-
raise ValueError('The X value of {} is out of range'.format(x))
86-
if not 0 <= y < self.rows:
87-
raise ValueError('The Y value of {} is out of range'.format(y))
88-
return y * self.columns + x
89-
else:
90-
raise ValueError('Index must be 1 or 2 number')
91-
92-
def _update(self):
93-
"""
94-
Update the Display automatically if auto_write is set to True
95-
"""
96-
if self._auto_write:
97-
self._matrix.show()
98-
99-
def _fill(self, color=0):
100-
"""
101-
Fills all of the Pixels with a color or unlit if empty.
102-
"""
103-
self._matrix.fill(color)
104-
self._update()
105-
106-
def _show(self):
107-
"""
108-
Update the Pixels. This is only needed if auto_write is set to False
109-
This can be very useful for more advanced graphics effects.
110-
"""
111-
self._matrix.show()
112-
113-
def _shift_right(self, rotate=False):
114-
"""
115-
Shift all pixels right
116-
"""
117-
for y in range(0, self.rows):
118-
last_pixel = self._matrix[(y + 1) * self.columns - 1] if rotate else 0
119-
for x in range(self.columns - 1, 0, -1):
120-
self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x - 1]
121-
self._matrix[y * self.columns] = last_pixel
122-
self._update()
123-
124-
def _shift_left(self, rotate=False):
125-
"""
126-
Shift all pixels left
127-
"""
128-
for y in range(0, self.rows):
129-
last_pixel = self._matrix[y * self.columns] if rotate else 0
130-
for x in range(0, self.columns - 1):
131-
self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x + 1]
132-
self._matrix[(y + 1) * self.columns - 1] = last_pixel
133-
self._update()
134-
135-
def _shift_up(self, rotate=False):
136-
"""
137-
Shift all pixels up
138-
"""
139-
for x in range(0, self.columns):
140-
last_pixel = self._matrix[(self.rows - 1) * self.columns + x] if rotate else 0
141-
for y in range(self.rows - 1, 0, -1):
142-
self._matrix[y * self.columns + x] = self._matrix[(y - 1) * self.columns + x]
143-
self._matrix[x] = last_pixel
144-
self._update()
145-
146-
def _shift_down(self, rotate=False):
147-
"""
148-
Shift all pixels down
149-
"""
150-
for x in range(0, self.columns):
151-
last_pixel = self._matrix[x] if rotate else 0
152-
for y in range(0, self.rows - 1):
153-
self._matrix[y * self.columns + x] = self._matrix[(y + 1) * self.columns + x]
154-
self._matrix[(self.rows - 1) * self.columns + x] = last_pixel
155-
self._update()
36+
from adafruit_featherwing.pixelmatrix_featherwing import PixelMatrixFeatherWing
15637

15738
class DotStarFeatherWing(PixelMatrixFeatherWing):
15839
"""Class representing a `DotStar FeatherWing

adafruit_featherwing/neopixel_featherwing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
import board
3535
import neopixel
36-
from adafruit_featherwing.dotstar_featherwing import PixelMatrixFeatherWing
37-
#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
36+
from adafruit_featherwing.pixelmatrix_featherwing import PixelMatrixFeatherWing
3837

3938
class NeoPixelFeatherWing(PixelMatrixFeatherWing):
4039
"""Class representing a `NeoPixel FeatherWing
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_featherwing.pixelmatrix_featherwing`
24+
====================================================
25+
26+
Base Class for the `NeoPixel FeatherWing <https://www.adafruit.com/product/2945>` and
27+
`DotStar FeatherWing <https://www.adafruit.com/product/3449>`_.
28+
29+
* Author(s): Melissa LeBlanc-Williams
30+
"""
31+
32+
__version__ = "0.0.0-auto.0"
33+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
34+
35+
#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
36+
37+
class PixelMatrixFeatherWing:
38+
"""Base Class for DotStar and NeoPixel FeatherWings
39+
40+
The feather uses pins D13 and D11"""
41+
def __init__(self):
42+
self.rows = 0
43+
self.columns = 0
44+
self._matrix = None
45+
self._auto_write = True
46+
47+
def __setitem__(self, indices, value):
48+
"""
49+
indices can be one of three things:
50+
x and y ints that are calculated to the DotStar index
51+
a slice of DotStar indexes with a set of values that match the slice
52+
a single int that specifies the DotStar index
53+
value can be one of three things:
54+
a (r,g,b) list/tuple
55+
a (r,g,b, brightness) list/tuple
56+
a single, longer int that contains RGB values, like 0xFFFFFF
57+
brightness, if specified should be a float 0-1
58+
"""
59+
self._matrix[self._get_index(indices)] = value
60+
self._update()
61+
62+
def __getitem__(self, indices):
63+
"""
64+
indices can be one of three things:
65+
x and y ints that are calculated to the DotStar index
66+
a slice of DotStar indexes to retrieve
67+
a single int that specifies the DotStar index
68+
"""
69+
return self._matrix[self._get_index(indices)]
70+
71+
def _get_index(self, indices):
72+
"""
73+
Figure out which DotStar to address based on what was passed in
74+
"""
75+
if isinstance(indices, int):
76+
if not 0 <= indices < self.rows * self.columns:
77+
raise ValueError('The index of {} is out of range'.format(indices))
78+
return indices
79+
elif isinstance(indices, slice):
80+
return indices
81+
elif len(indices) == 2:
82+
x, y = indices
83+
if not 0 <= x < self.columns:
84+
raise ValueError('The X value of {} is out of range'.format(x))
85+
if not 0 <= y < self.rows:
86+
raise ValueError('The Y value of {} is out of range'.format(y))
87+
return y * self.columns + x
88+
else:
89+
raise ValueError('Index must be 1 or 2 number')
90+
91+
def _update(self):
92+
"""
93+
Update the Display automatically if auto_write is set to True
94+
"""
95+
if self._auto_write:
96+
self._matrix.show()
97+
98+
def _fill(self, color=0):
99+
"""
100+
Fills all of the Pixels with a color or unlit if empty.
101+
"""
102+
self._matrix.fill(color)
103+
self._update()
104+
105+
def _show(self):
106+
"""
107+
Update the Pixels. This is only needed if auto_write is set to False
108+
This can be very useful for more advanced graphics effects.
109+
"""
110+
self._matrix.show()
111+
112+
def _shift_right(self, rotate=False):
113+
"""
114+
Shift all pixels right
115+
"""
116+
for y in range(0, self.rows):
117+
last_pixel = self._matrix[(y + 1) * self.columns - 1] if rotate else 0
118+
for x in range(self.columns - 1, 0, -1):
119+
self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x - 1]
120+
self._matrix[y * self.columns] = last_pixel
121+
self._update()
122+
123+
def _shift_left(self, rotate=False):
124+
"""
125+
Shift all pixels left
126+
"""
127+
for y in range(0, self.rows):
128+
last_pixel = self._matrix[y * self.columns] if rotate else 0
129+
for x in range(0, self.columns - 1):
130+
self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x + 1]
131+
self._matrix[(y + 1) * self.columns - 1] = last_pixel
132+
self._update()
133+
134+
def _shift_up(self, rotate=False):
135+
"""
136+
Shift all pixels up
137+
"""
138+
for x in range(0, self.columns):
139+
last_pixel = self._matrix[(self.rows - 1) * self.columns + x] if rotate else 0
140+
for y in range(self.rows - 1, 0, -1):
141+
self._matrix[y * self.columns + x] = self._matrix[(y - 1) * self.columns + x]
142+
self._matrix[x] = last_pixel
143+
self._update()
144+
145+
def _shift_down(self, rotate=False):
146+
"""
147+
Shift all pixels down
148+
"""
149+
for x in range(0, self.columns):
150+
last_pixel = self._matrix[x] if rotate else 0
151+
for y in range(0, self.rows - 1):
152+
self._matrix[y * self.columns + x] = self._matrix[(y + 1) * self.columns + x]
153+
self._matrix[(self.rows - 1) * self.columns + x] = last_pixel
154+
self._update()

0 commit comments

Comments
 (0)