Skip to content

Fix clipping in pixel() function #6

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 2 commits into from
Sep 24, 2021
Merged
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
25 changes: 9 additions & 16 deletions adafruit_is31fl3741/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,19 @@ def pixel(self, x, y, color=None):

:param x: horizontal pixel position
:param y: vertical pixel position
:param color: hex color value 0x000000 to 0xFFFFFF
:param color: hex color value 0x000000 to 0xFFFFFF to set,
or None to return current pixel value
"""
if not 0 <= x <= self.width:
return None
if not 0 <= y <= self.height:
return None
addrs = self.pixel_addrs(x, y)
# print(addrs)
if color is not None: # set the color

if 0 <= x < self.width and 0 <= y < self.height: # Clip
addrs = self.pixel_addrs(x, y) # LED indices
# print(addrs)
if color is None: # Return current pixel color if unspecified
return (self[addrs[0]] << 16) | (self[addrs[1]] << 8) | self[addrs[2]]
self[addrs[0]] = (color >> 16) & 0xFF
self[addrs[1]] = (color >> 8) & 0xFF
self[addrs[2]] = color & 0xFF
return None
# we want to fetch the color
color = self[addrs[0]]
color <<= 8
color |= self[addrs[1]]
color <<= 8
color |= self[addrs[2]]
return color
return None

# pylint: enable-msg=too-many-arguments

Expand Down