Skip to content

Commit 32c8019

Browse files
committed
Fix RGB for V6
1 parent 68bf9ea commit 32c8019

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

Diff for: pslab/protocol.py

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
READ_LOG = Byte.pack(18)
167167
RESTORE_STANDALONE = Byte.pack(19)
168168
GET_ALTERNATE_HIGH_FREQUENCY = Byte.pack(20)
169+
SET_RGB_COMMON = Byte.pack(21)
169170
SET_RGB3 = Byte.pack(22)
170171

171172
START_CTMU = Byte.pack(23)

Diff for: pslab/sciencelab.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ def __init__(
4646
self.pwm_generator = PWMGenerator(device=self)
4747
self.multimeter = Multimeter(device=self)
4848
self.power_supply = PowerSupply(device=self)
49-
self.i2c = I2CMaster(device=self)
50-
self.spi = SPIMaster(device=self)
51-
self.nrf = NRF24L01(device=self)
52-
53-
if "V6" in self.version: # Set the built-in WS2812B to green :)
54-
self.rgb_led([0, 20, 0])
49+
# self.i2c = I2CMaster(device=self)
50+
# self.spi = SPIMaster(device=self)
51+
# self.nrf = NRF24L01(device=self)
5552

5653
@property
5754
def temperature(self):
@@ -105,7 +102,7 @@ def _get_ctmu_voltage(self, channel: int, current_range: int, tgen: bool = True)
105102
self.get_ack()
106103
vmax = 3.3
107104
resolution = 12
108-
voltage = vmax * raw_voltage / (2 ** resolution - 1)
105+
voltage = vmax * raw_voltage / (2**resolution - 1)
109106
return voltage
110107

111108
def _start_ctmu(self, current_range: int, trim: int, tgen: int = 1):
@@ -160,15 +157,17 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
160157
161158
>>> psl.rgb_led([[10,0,0],[0,10,10],[10,0,10]], output="SQ1", order="RGB")
162159
"""
163-
if output == "RGB":
164-
pin = CP.SET_RGB1
165-
elif output == "PGC":
166-
pin = CP.SET_RGB2
167-
elif output == "SQ1":
168-
pin = CP.SET_RGB3
160+
if "6" in self.version:
161+
pins = {"ONBOARD": 0, "SQ1": 1, "SQ2": 2, "SQ3": 3, "SQ4": 4}
169162
else:
163+
pins = {"RGB": CP.SET_RGB1, "PGC": CP.SET_RGB2, "SQ1": CP.SET_RGB3}
164+
165+
try:
166+
pin = pins[output]
167+
except KeyError:
168+
pinnames = ", ".join(pins.keys())
170169
raise ValueError(
171-
f"Invalid output: {output}. output must be 'RGB', 'PCG', or 'SQ1'."
170+
f"Invalid output: {output}. output must be one of {pinnames}."
172171
)
173172

174173
if not isinstance(colors[0], Iterable):
@@ -185,14 +184,22 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
185184
)
186185

187186
self.send_byte(CP.COMMON)
188-
self.send_byte(pin)
187+
188+
if "6" in self.version:
189+
self.send_byte(CP.SET_RGB_COMMON)
190+
else:
191+
self.send_byte(pin)
192+
189193
self.send_byte(len(colors) * 3)
190194

191195
for color in colors:
192196
self.send_byte(color[order.index("R")])
193197
self.send_byte(color[order.index("G")])
194198
self.send_byte(color[order.index("B")])
195199

200+
if "6" in self.version:
201+
self.send_byte(pin)
202+
196203
self.get_ack()
197204

198205
def _read_program_address(self, address: int):

0 commit comments

Comments
 (0)