Skip to content

Commit

Permalink
Merge pull request #52 from makermelissa/master
Browse files Browse the repository at this point in the history
Pointed matrix shift functions to use HT16K33 shift functions
  • Loading branch information
makermelissa committed Jan 15, 2020
2 parents e934566 + 2957bbe commit 7f44b16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
24 changes: 4 additions & 20 deletions adafruit_featherwing/matrix_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ def shift_right(self, rotate=False):
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
"""
for y in range(0, self.rows):
last_pixel = self._matrix[self.columns - 1, y] if rotate else 0
for x in range(self.columns - 1, 0, -1):
self._matrix[x, y] = self._matrix[x - 1, y]
self._matrix[0, y] = last_pixel
self._matrix.shift_right(rotate)
self._update()

def shift_left(self, rotate=False):
Expand All @@ -123,11 +119,7 @@ def shift_left(self, rotate=False):
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
"""
for y in range(0, self.rows):
last_pixel = self._matrix[0, y] if rotate else 0
for x in range(0, self.columns - 1):
self._matrix[x, y] = self._matrix[x + 1, y]
self._matrix[self.columns - 1, y] = last_pixel
self._matrix.shift_left(rotate)
self._update()

def shift_up(self, rotate=False):
Expand All @@ -136,11 +128,7 @@ def shift_up(self, rotate=False):
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
"""
for x in range(0, self.columns):
last_pixel = self._matrix[x, self.rows - 1] if rotate else 0
for y in range(self.rows - 1, 0, -1):
self._matrix[x, y] = self._matrix[x, y - 1]
self._matrix[x, 0] = last_pixel
self._matrix.shift_up(rotate)
self._update()

def shift_down(self, rotate=False):
Expand All @@ -149,11 +137,7 @@ def shift_down(self, rotate=False):
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
"""
for x in range(0, self.columns):
last_pixel = self._matrix[x, 0] if rotate else 0
for y in range(0, self.rows - 1):
self._matrix[x, y] = self._matrix[x, y + 1]
self._matrix[x, self.rows - 1] = last_pixel
self._matrix.shift_down(rotate)
self._update()

@property
Expand Down
7 changes: 3 additions & 4 deletions adafruit_featherwing/pixelmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,16 @@ def _get_index(self, indices):
if not 0 <= indices < self.rows * self.columns:
raise ValueError('The index of {} is out of range'.format(indices))
return indices
elif isinstance(indices, slice):
if isinstance(indices, slice):
return indices
elif len(indices) == 2:
if len(indices) == 2:
x, y = indices
if not 0 <= x < self.columns:
raise ValueError('The X value of {} is out of range'.format(x))
if not 0 <= y < self.rows:
raise ValueError('The Y value of {} is out of range'.format(y))
return y * self.columns + x
else:
raise ValueError('Index must be 1 or 2 number')
raise ValueError('Index must be 1 or 2 number')

def _update(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions adafruit_featherwing/rtc_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def _get_time_value(self, unit):
now = self._get_now()
if unit in now:
return now[unit]
else:
raise ValueError('The specified unit of time is invalid')
raise ValueError('The specified unit of time is invalid')

def _get_now(self):
"""
Expand Down

0 comments on commit 7f44b16

Please sign in to comment.