@@ -74,7 +74,7 @@ def _map(self, x: float | int, in_min: float | int, in_max: float | int, out_min
74
74
def _mapi (self , x : float | int , in_min : float | int , in_max : float | int , out_min : float | int , out_max : float | int ) -> int :
75
75
return int (self ._map (x , in_min , in_max , out_min , out_max ))
76
76
77
- def set_range_rgb (self , index_from : int , index_to : int , r : int , g : int , b : int , brightness : int = 100 ) -> None :
77
+ def set_range_rgb (self , index_from : int , index_to : int , r : int , g : int , b : int , brightness : int = 100 ) -> 'ModulinoPixels' :
78
78
"""
79
79
Sets the color of the LEDs in the given range to the given RGB values.
80
80
@@ -85,10 +85,14 @@ def set_range_rgb(self, index_from: int, index_to: int, r: int, g: int, b: int,
85
85
g (int): The green value of the color.
86
86
b (int): The blue value of the color.
87
87
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
88
+
89
+ Returns:
90
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
88
91
"""
89
92
self .set_range_color (index_from , index_to , ModulinoColor (r , g , b ), brightness )
93
+ return self
90
94
91
- def set_range_color (self , index_from : int , index_to : int , color : ModulinoColor , brightness : int = 100 ) -> None :
95
+ def set_range_color (self , index_from : int , index_to : int , color : ModulinoColor , brightness : int = 100 ) -> 'ModulinoPixels' :
92
96
"""
93
97
Sets the color of the LEDs in the given range to the given color.
94
98
@@ -97,11 +101,15 @@ def set_range_color(self, index_from: int, index_to: int, color: ModulinoColor,
97
101
index_to (int): The ending index (inclusive) of the range.
98
102
color (ModulinoColor): The color of the LEDs.
99
103
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
104
+
105
+ Returns:
106
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
100
107
"""
101
108
for i in range (index_from , index_to + 1 ):
102
109
self .set_color (i , color , brightness )
110
+ return self
103
111
104
- def set_all_rgb (self , r : int , g : int , b : int , brightness : int = 100 ) -> None :
112
+ def set_all_rgb (self , r : int , g : int , b : int , brightness : int = 100 ) -> 'ModulinoPixels' :
105
113
"""
106
114
Sets the color of all the LEDs to the given RGB values.
107
115
@@ -110,27 +118,38 @@ def set_all_rgb(self, r: int, g: int, b: int, brightness: int = 100) -> None:
110
118
g (int): The green value of the color.
111
119
b (int): The blue value of the color.
112
120
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
121
+
122
+ Returns:
123
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
113
124
"""
114
125
self .set_all_color (ModulinoColor (r , g , b ), brightness )
126
+ return self
115
127
116
- def set_all_color (self , color : ModulinoColor , brightness : int = 100 ) -> None :
128
+ def set_all_color (self , color : ModulinoColor , brightness : int = 100 ) -> 'ModulinoPixels' :
117
129
"""
118
130
Sets the color of all the LEDs to the given color.
119
131
120
132
Parameters:
121
133
color (ModulinoColor): The color of the LEDs.
122
134
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
135
+
136
+ Returns:
137
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
123
138
"""
124
139
self .set_range_color (0 , NUM_LEDS - 1 , color , brightness )
140
+ return self
125
141
126
- def set_color (self , idx : int , rgb : ModulinoColor , brightness : int = 100 ) -> None :
142
+ def set_color (self , idx : int , rgb : ModulinoColor , brightness : int = 100 ) -> 'ModulinoPixels' :
127
143
"""
128
144
Sets the color of the given LED index to the given color.
129
145
130
146
Parameters:
131
147
idx (int): The index of the LED (0..7).
132
148
rgb (ModulinoColor): The color of the LED.
133
149
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
150
+
151
+ Returns:
152
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
134
153
"""
135
154
if idx < 0 or idx >= NUM_LEDS :
136
155
raise ValueError (f"LED index out of range { idx } (Valid: 0..{ NUM_LEDS - 1 } )" )
@@ -139,8 +158,9 @@ def set_color(self, idx: int, rgb: ModulinoColor, brightness: int = 100) -> None
139
158
mapped_brightness = self ._mapi (brightness , 0 , 100 , 0 , 0x1f )
140
159
color_data_bytes = int (rgb ) | mapped_brightness | 0xE0
141
160
self .data [byte_index : byte_index + 4 ] = color_data_bytes .to_bytes (4 , 'little' )
161
+ return self
142
162
143
- def set_rgb (self , idx : int , r : int , g : int , b : int , brightness : int = 100 ) -> None :
163
+ def set_rgb (self , idx : int , r : int , g : int , b : int , brightness : int = 100 ) -> 'ModulinoPixels' :
144
164
"""
145
165
Set the color of the given LED index to the given RGB values.
146
166
@@ -150,34 +170,50 @@ def set_rgb(self, idx: int, r: int, g: int, b: int, brightness: int = 100) -> No
150
170
g (int): The green value of the color.
151
171
b (int): The blue value of the color.
152
172
brightness (int): The brightness of the LED. It should be a value between 0 and 100.
173
+
174
+ Returns:
175
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
153
176
"""
154
177
self .set_color (idx , ModulinoColor (r , g , b ), brightness )
178
+ return self
155
179
156
- def clear (self , idx : int ) -> None :
180
+ def clear (self , idx : int ) -> 'ModulinoPixels' :
157
181
"""
158
182
Turns off the LED at the given index.
159
183
160
184
Parameters:
161
185
idx (int): The index of the LED (0..7).
186
+
187
+ Returns:
188
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
162
189
"""
163
190
self .set_color (idx , ModulinoColor (0 , 0 , 0 ), 0 )
191
+ return self
164
192
165
- def clear_range (self , start : int , end : int ) -> None :
193
+ def clear_range (self , start : int , end : int ) -> 'ModulinoPixels' :
166
194
"""
167
195
Turns off the LEDs in the given range.
168
196
169
197
Parameters:
170
198
start (int): The starting index of the range.
171
199
end (int): The ending index (inclusive) of the range.
200
+
201
+ Returns:
202
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
172
203
"""
173
204
for i in range (start , end ):
174
205
self .clear (i )
206
+ return self
175
207
176
- def clear_all (self ) -> None :
208
+ def clear_all (self ) -> 'ModulinoPixels' :
177
209
"""
178
210
Turns all the LEDs off.
211
+
212
+ Returns:
213
+ ModulinoPixels: The object itself. Allows for daily chaining of methods.
179
214
"""
180
215
self .data = bytearray ([0xE0 ] * NUM_LEDS * 4 )
216
+ return self
181
217
182
218
def show (self ) -> None :
183
219
"""
0 commit comments