Skip to content

throw error if color tuple/pixel_order mismatch #37

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 3 commits into from
Oct 30, 2018
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
12 changes: 7 additions & 5 deletions neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def _set_item(self, index, value):
b = 0
w = 0
if isinstance(value, int):
if value>>24:
raise ValueError("only bits 0->23 valid for integer input")
r = value >> 16
g = (value >> 8) & 0xff
b = value & 0xff
Expand All @@ -142,11 +144,11 @@ def _set_item(self, index, value):
r = 0
g = 0
b = 0
elif len(value) == self.bpp:
if self.bpp == 3:
r, g, b = value
else:
r, g, b, w = value
elif (len(value) == self.bpp) or ((len(value) == 3) and (self.bpp == 4)):
r, g, b, w = value if len(value) == 4 else value+(0,)
else:
raise ValueError("Color tuple size does not match pixel_order.")

self.buf[offset + self.order[0]] = r
self.buf[offset + self.order[1]] = g
self.buf[offset + self.order[2]] = b
Expand Down