Skip to content

Commit 7f44b16

Browse files
authored
Merge pull request #52 from makermelissa/master
Pointed matrix shift functions to use HT16K33 shift functions
2 parents e934566 + 2957bbe commit 7f44b16

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

adafruit_featherwing/matrix_featherwing.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ def shift_right(self, rotate=False):
110110
111111
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
112112
"""
113-
for y in range(0, self.rows):
114-
last_pixel = self._matrix[self.columns - 1, y] if rotate else 0
115-
for x in range(self.columns - 1, 0, -1):
116-
self._matrix[x, y] = self._matrix[x - 1, y]
117-
self._matrix[0, y] = last_pixel
113+
self._matrix.shift_right(rotate)
118114
self._update()
119115

120116
def shift_left(self, rotate=False):
@@ -123,11 +119,7 @@ def shift_left(self, rotate=False):
123119
124120
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
125121
"""
126-
for y in range(0, self.rows):
127-
last_pixel = self._matrix[0, y] if rotate else 0
128-
for x in range(0, self.columns - 1):
129-
self._matrix[x, y] = self._matrix[x + 1, y]
130-
self._matrix[self.columns - 1, y] = last_pixel
122+
self._matrix.shift_left(rotate)
131123
self._update()
132124

133125
def shift_up(self, rotate=False):
@@ -136,11 +128,7 @@ def shift_up(self, rotate=False):
136128
137129
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
138130
"""
139-
for x in range(0, self.columns):
140-
last_pixel = self._matrix[x, self.rows - 1] if rotate else 0
141-
for y in range(self.rows - 1, 0, -1):
142-
self._matrix[x, y] = self._matrix[x, y - 1]
143-
self._matrix[x, 0] = last_pixel
131+
self._matrix.shift_up(rotate)
144132
self._update()
145133

146134
def shift_down(self, rotate=False):
@@ -149,11 +137,7 @@ def shift_down(self, rotate=False):
149137
150138
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
151139
"""
152-
for x in range(0, self.columns):
153-
last_pixel = self._matrix[x, 0] if rotate else 0
154-
for y in range(0, self.rows - 1):
155-
self._matrix[x, y] = self._matrix[x, y + 1]
156-
self._matrix[x, self.rows - 1] = last_pixel
140+
self._matrix.shift_down(rotate)
157141
self._update()
158142

159143
@property

adafruit_featherwing/pixelmatrix.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,16 @@ def _get_index(self, indices):
7676
if not 0 <= indices < self.rows * self.columns:
7777
raise ValueError('The index of {} is out of range'.format(indices))
7878
return indices
79-
elif isinstance(indices, slice):
79+
if isinstance(indices, slice):
8080
return indices
81-
elif len(indices) == 2:
81+
if len(indices) == 2:
8282
x, y = indices
8383
if not 0 <= x < self.columns:
8484
raise ValueError('The X value of {} is out of range'.format(x))
8585
if not 0 <= y < self.rows:
8686
raise ValueError('The Y value of {} is out of range'.format(y))
8787
return y * self.columns + x
88-
else:
89-
raise ValueError('Index must be 1 or 2 number')
88+
raise ValueError('Index must be 1 or 2 number')
9089

9190
def _update(self):
9291
"""

adafruit_featherwing/rtc_featherwing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def _get_time_value(self, unit):
7878
now = self._get_now()
7979
if unit in now:
8080
return now[unit]
81-
else:
82-
raise ValueError('The specified unit of time is invalid')
81+
raise ValueError('The specified unit of time is invalid')
8382

8483
def _get_now(self):
8584
"""

0 commit comments

Comments
 (0)