@@ -36,6 +36,7 @@ class ScienceLab:
36
36
37
37
def __init__ (self , device : ConnectionHandler | None = None ):
38
38
self .device = device if device is not None else autoconnect ()
39
+ self .version = self .device .get_version ()
39
40
self .logic_analyzer = LogicAnalyzer (device = self .device )
40
41
self .oscilloscope = Oscilloscope (device = self .device )
41
42
self .waveform_generator = WaveformGenerator (device = self .device )
@@ -163,8 +164,10 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
163
164
164
165
>>> psl.rgb_led([[10,0,0],[0,10,10],[10,0,10]], output="SQ1", order="RGB")
165
166
"""
166
- if "6" in self .device . version :
167
+ if "6" in self .version :
167
168
pins = {"ONBOARD" : 0 , "SQ1" : 1 , "SQ2" : 2 , "SQ3" : 3 , "SQ4" : 4 }
169
+ if output == "RGB" :
170
+ output = "ONBOARD"
168
171
else :
169
172
pins = {"RGB" : CP .SET_RGB1 , "PGC" : CP .SET_RGB2 , "SQ1" : CP .SET_RGB3 }
170
173
@@ -189,24 +192,13 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
189
192
f"Invalid order: { order } . order must contain 'R', 'G', and 'B'."
190
193
)
191
194
192
- self .device .send_byte (CP .COMMON )
193
-
194
- if "6" in self .device .version :
195
- self .device .send_byte (CP .SET_RGB_COMMON )
196
- else :
197
- self .device .send_byte (pin )
198
-
199
- self .device .send_byte (len (colors ) * 3 )
200
-
201
- for color in colors :
202
- self .device .send_byte (color [order .index ("R" )])
203
- self .device .send_byte (color [order .index ("G" )])
204
- self .device .send_byte (color [order .index ("B" )])
205
-
206
- if "6" in self .device .version :
207
- self .device .send_byte (pin )
208
-
209
- self .device .get_ack ()
195
+ cmd = CP .COMMON + CP .SET_RGB_COMMON
196
+ args = CP .Byte .pack (pin )
197
+ args += CP .Byte .pack (len (colors ) * 3 )
198
+ args += bytes (
199
+ color [order .index (channel )] for channel in "RGB" for color in colors
200
+ )
201
+ self .device .exchange (cmd , args )
210
202
211
203
def _read_program_address (self , address : int ):
212
204
"""Return the value stored at the specified address in program memory.
0 commit comments