Skip to content

Commit 55614af

Browse files
Glasses rings: move LED maps out of setter functions into classes, add getter funcs
1 parent 49ff250 commit 55614af

File tree

1 file changed

+72
-54
lines changed

1 file changed

+72
-54
lines changed

adafruit_is31fl3741/adafruit_ledglasses.py

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,86 +30,104 @@
3030
class Right_Ring(IS31FL3741):
3131
"""The right eye ring of the LED glasses"""
3232

33+
ledmap = (
34+
(287, 31, 30), # 0
35+
(278, 1, 0), # 1
36+
(273, 274, 275), # 2
37+
(282, 283, 284), # 3
38+
(270, 271, 272), # 4
39+
(27, 28, 29), # 5
40+
(23, 24, 25), # 6
41+
(276, 277, 22), # 7
42+
(20, 21, 26), # 8
43+
(50, 51, 56), # 9
44+
(80, 81, 86), # 10
45+
(110, 111, 116), # 11
46+
(140, 141, 146), # 12
47+
(170, 171, 176), # 13
48+
(200, 201, 206), # 14
49+
(230, 231, 236), # 15
50+
(260, 261, 266), # 16
51+
(348, 349, 262), # 17
52+
(233, 234, 235), # 18
53+
(237, 238, 239), # 19
54+
(339, 340, 232), # 20
55+
(327, 328, 329), # 21
56+
(305, 91, 90), # 22
57+
(296, 61, 60), # 23
58+
)
59+
3360
def __init__(self, is31_controller):
3461
self._is31 = is31_controller
3562

3663
def __setitem__(self, led, color):
3764
if not 0 <= led <= 23:
3865
raise ValueError("led must be 0~23")
3966

40-
ledmap = (
41-
(287, 31, 30), # 0
42-
(278, 1, 0), # 1
43-
(273, 274, 275), # 2
44-
(282, 283, 284), # 3
45-
(270, 271, 272), # 4
46-
(27, 28, 29), # 5
47-
(23, 24, 25), # 6
48-
(276, 277, 22), # 7
49-
(20, 21, 26), # 8
50-
(50, 51, 56), # 9
51-
(80, 81, 86), # 10
52-
(110, 111, 116), # 11
53-
(140, 141, 146), # 12
54-
(170, 171, 176), # 13
55-
(200, 201, 206), # 14
56-
(230, 231, 236), # 15
57-
(260, 261, 266), # 16
58-
(348, 349, 262), # 17
59-
(233, 234, 235), # 18
60-
(237, 238, 239), # 19
61-
(339, 340, 232), # 20
62-
(327, 328, 329), # 21
63-
(305, 91, 90), # 22
64-
(296, 61, 60), # 23
65-
)
66-
rgb = ledmap[led]
67+
rgb = Right_Ring.ledmap[led]
6768
self._is31[rgb[0]] = (color >> 16) & 0xFF
6869
self._is31[rgb[1]] = (color >> 8) & 0xFF
6970
self._is31[rgb[2]] = color & 0xFF
7071

72+
def __getitem__(self, led):
73+
if not 0 <= led <= 23:
74+
raise ValueError("led must be 0~23")
75+
rgb = Right_Ring.ledmap[led]
76+
return (
77+
(self._is31[rgb[0]] << 16) | (self._is31[rgb[1]] << 8) | self._is31[rgb[2]]
78+
)
79+
7180

7281
class Left_Ring:
7382
"""The left eye ring of the LED glasses"""
7483

84+
ledmap = (
85+
(341, 211, 210), # 0
86+
(332, 181, 180), # 1
87+
(323, 151, 150), # 2
88+
(127, 126, 125), # 3
89+
(154, 153, 152), # 4
90+
(163, 162, 161), # 5
91+
(166, 165, 164), # 6
92+
(244, 243, 242), # 7
93+
(259, 258, 257), # 8
94+
(169, 168, 167), # 9
95+
(139, 138, 137), # 10
96+
(109, 108, 107), # 11
97+
(79, 78, 77), # 12
98+
(49, 48, 47), # 13
99+
(199, 198, 197), # 14
100+
(229, 228, 227), # 15
101+
(19, 18, 17), # 16
102+
(4, 3, 2), # 17
103+
(16, 15, 14), # 18
104+
(13, 12, 11), # 19
105+
(10, 9, 8), # 20
106+
(217, 216, 215), # 21
107+
(7, 6, 5), # 22
108+
(350, 241, 240), # 23
109+
)
110+
75111
def __init__(self, is31_controller):
76112
self._is31 = is31_controller
77113

78114
def __setitem__(self, led, color):
79115
if not 0 <= led <= 23:
80116
raise ValueError("led must be 0~23")
81117

82-
ledmap = (
83-
(341, 211, 210), # 0
84-
(332, 181, 180), # 1
85-
(323, 151, 150), # 2
86-
(127, 126, 125), # 3
87-
(154, 153, 152), # 4
88-
(163, 162, 161), # 5
89-
(166, 165, 164), # 6
90-
(244, 243, 242), # 7
91-
(259, 258, 257), # 8
92-
(169, 168, 167), # 9
93-
(139, 138, 137), # 10
94-
(109, 108, 107), # 11
95-
(79, 78, 77), # 12
96-
(49, 48, 47), # 13
97-
(199, 198, 197), # 14
98-
(229, 228, 227), # 15
99-
(19, 18, 17), # 16
100-
(4, 3, 2), # 17
101-
(16, 15, 14), # 18
102-
(13, 12, 11), # 19
103-
(10, 9, 8), # 20
104-
(217, 216, 215), # 21
105-
(7, 6, 5), # 22
106-
(350, 241, 240), # 23
107-
)
108-
rgb = ledmap[led]
118+
rgb = Left_Ring.ledmap[led]
109119
self._is31[rgb[0]] = (color >> 16) & 0xFF
110120
self._is31[rgb[1]] = (color >> 8) & 0xFF
111121
self._is31[rgb[2]] = color & 0xFF
112122

123+
def __getitem__(self, led):
124+
if not 0 <= led <= 23:
125+
raise ValueError("led must be 0~23")
126+
rgb = Left_Ring.ledmap[led]
127+
return (
128+
(self._is31[rgb[0]] << 16) | (self._is31[rgb[1]] << 8) | self._is31[rgb[2]]
129+
)
130+
113131

114132
class LED_Glasses(IS31FL3741):
115133
"""Class representing LED Glasses"""

0 commit comments

Comments
 (0)