Skip to content
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

Fix typing for color565 function #118

Merged
merged 2 commits into from
Nov 28, 2023
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
13 changes: 9 additions & 4 deletions adafruit_rgb_display/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@

def color565(
r: Union[int, Tuple[int, int, int], List[int]],
g: int = 0,
b: int = 0,
g: Optional[int] = 0,
b: Optional[int] = 0,
) -> int:
"""Convert red, green and blue values (0-255) into a 16-bit 565 encoding. As
a convenience this is also available in the parent adafruit_rgb_display
package namespace."""
if not isinstance(r, int): # see if the first var is a tuple/list
red, g, b = r
if isinstance(r, (tuple, list)): # see if the first var is a tuple/list
if len(r) >= 3:
red, g, b = r
else:
raise ValueError(
"Not enough values to unpack (expected 3, got %d)" % len(r)
)
else:
red = r
return (red & 0xF8) << 8 | (g & 0xFC) << 3 | b >> 3
Expand Down