Skip to content

Commit 7054fde

Browse files
committed
feat(steami_screen): migrate steami_screen from tutorial repo
1 parent 2ddb36c commit 7054fde

4 files changed

Lines changed: 747 additions & 0 deletions

File tree

lib/steami_screen/manifest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
metadata(
2+
description="Library for controlling the STeaMi round display.",
3+
version="0.0.1",
4+
)
5+
6+
package("steami_screen")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from steami_screen.colors import rgb_to_gray4, rgb_to_rgb8, rgb_to_rgb565
2+
from steami_screen.screen import (
3+
BLACK,
4+
BLUE,
5+
DARK,
6+
GRAY,
7+
GREEN,
8+
LIGHT,
9+
RED,
10+
WHITE,
11+
YELLOW,
12+
Screen,
13+
)
14+
15+
__all__ = [
16+
"BLACK",
17+
"BLUE",
18+
"DARK",
19+
"GRAY",
20+
"GREEN",
21+
"LIGHT",
22+
"RED",
23+
"WHITE",
24+
"YELLOW",
25+
"Screen",
26+
"rgb_to_gray4",
27+
"rgb_to_rgb8",
28+
"rgb_to_rgb565",
29+
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Color conversion utilities for STeaMi display backends.
3+
4+
Colors are represented as RGB tuples (r, g, b) with values 0-255.
5+
Each backend converts to its native format:
6+
- SSD1327 : grayscale 4-bit (0-15)
7+
- GC9A01 : RGB565 (16-bit)
8+
- Simulator: RGB tuple (pass-through)
9+
10+
All functions accept legacy int values for backward compatibility.
11+
"""
12+
13+
14+
def rgb_to_gray4(color):
15+
"""Convert an RGB tuple to a 4-bit grayscale value (0-15).
16+
17+
Uses BT.601 luminance: Y = 0.299*R + 0.587*G + 0.114*B
18+
Accepts int for backward compatibility (returned as-is, clamped to 0-15).
19+
"""
20+
if isinstance(color, int):
21+
return max(0, min(15, color))
22+
r, g, b = color
23+
luminance = (r * 77 + g * 150 + b * 29) >> 8 # 0-255
24+
return luminance >> 4 # 0-15
25+
26+
27+
def rgb_to_rgb565(color):
28+
"""Convert an RGB tuple to a 16-bit RGB565 integer.
29+
30+
Accepts int for backward compatibility (treated as gray4, expanded).
31+
"""
32+
if isinstance(color, int):
33+
g = max(0, min(15, color)) * 17 # 0-255
34+
r, b = g, g
35+
else:
36+
r, g, b = color
37+
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
38+
39+
40+
def rgb_to_rgb8(color):
41+
"""Convert a color to an RGB tuple (r, g, b).
42+
43+
If already a tuple, returns it unchanged.
44+
Accepts int for backward compatibility (treated as gray4, expanded).
45+
"""
46+
if isinstance(color, int):
47+
v = max(0, min(15, color)) * 17 # 0-255
48+
return (v, v, v)
49+
return color

0 commit comments

Comments
 (0)