Skip to content

Pointed matrix shift functions to use HT16K33 shift functions #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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