Skip to content

Commit c35f7a6

Browse files
committed
Update several functions to match changes in firmware
1 parent f03c494 commit c35f7a6

File tree

3 files changed

+14
-58
lines changed

3 files changed

+14
-58
lines changed

pslab/instrument/oscilloscope.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def __init__(self, device: ConnectionHandler | None = None):
3838
self._trigger_voltage = None
3939
self._trigger_enabled = False
4040
self._trigger_channel = "CH1"
41-
self._set_gain("CH1", 1)
42-
self._set_gain("CH2", 1)
41+
# self._set_gain("CH1", 1)
42+
# self._set_gain("CH2", 1)
4343

4444
def capture(
4545
self,
@@ -375,12 +375,6 @@ def select_range(self, channel: str, voltage_range: Union[int, float]):
375375
self._set_gain(channel, gain)
376376

377377
def _set_gain(self, channel: str, gain: int):
378-
spi_config_supported = self._check_spi_config()
379-
380-
if not spi_config_supported:
381-
spi_parameters = SPIMaster.get_parameters()
382-
spi = SPIMaster(self._device) # Initializing SPIMaster will reset config.
383-
384378
self._channels[channel].gain = gain
385379
pga = self._channels[channel].programmable_gain_amplifier
386380
gain_idx = GAIN_VALUES.index(gain)
@@ -390,9 +384,6 @@ def _set_gain(self, channel: str, gain: int):
390384
self._device.send_byte(gain_idx)
391385
self._device.get_ack()
392386

393-
if not spi_config_supported:
394-
spi.set_parameters(*spi_parameters)
395-
396387
@staticmethod
397388
def _check_spi_config() -> bool:
398389
"""Check whether current SPI config is supported by PGA.

pslab/protocol.py

+1-28
Original file line numberDiff line numberDiff line change
@@ -193,36 +193,9 @@
193193
BAUD230400_LEGACY = Byte.pack(8)
194194
BAUD1000000_LEGACY = Byte.pack(9)
195195

196-
# /*-----------NRFL01 radio module----------*/
197-
NRFL01 = Byte.pack(13)
198-
NRF_SETUP = Byte.pack(1)
199-
NRF_RXMODE = Byte.pack(2)
200-
NRF_TXMODE = Byte.pack(3)
201-
NRF_POWER_DOWN = Byte.pack(4)
202-
NRF_RXCHAR = Byte.pack(5)
203-
NRF_TXCHAR = Byte.pack(6)
204-
NRF_HASDATA = Byte.pack(7)
205-
NRF_FLUSH = Byte.pack(8)
206-
NRF_WRITEREG = Byte.pack(9)
207-
NRF_READREG = Byte.pack(10)
208-
NRF_GETSTATUS = Byte.pack(11)
209-
NRF_WRITECOMMAND = Byte.pack(12)
210-
NRF_WRITEPAYLOAD = Byte.pack(13)
211-
NRF_READPAYLOAD = Byte.pack(14)
212-
NRF_WRITEADDRESS = Byte.pack(15)
213-
NRF_TRANSACTION = Byte.pack(16)
214-
NRF_START_TOKEN_MANAGER = Byte.pack(17)
215-
NRF_STOP_TOKEN_MANAGER = Byte.pack(18)
216-
NRF_TOTAL_TOKENS = Byte.pack(19)
217-
NRF_REPORTS = Byte.pack(20)
218-
NRF_WRITE_REPORT = Byte.pack(21)
219-
NRF_DELETE_REPORT_ROW = Byte.pack(22)
220-
221-
NRF_WRITEADDRESSES = Byte.pack(23)
222-
223196
# ---------Non standard IO protocols--------
224197

225-
NONSTANDARD_IO = Byte.pack(14)
198+
NONSTANDARD_IO = Byte.pack(13)
226199
# HX711_HEADER = Byte.pack(1)
227200
HCSR04_HEADER = Byte.pack(2)
228201
# AM2302_HEADER = Byte.pack(3)

pslab/sciencelab.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ScienceLab:
3636

3737
def __init__(self, device: ConnectionHandler | None = None):
3838
self.device = device if device is not None else autoconnect()
39+
self.version = self.device.get_version()
3940
self.logic_analyzer = LogicAnalyzer(device=self.device)
4041
self.oscilloscope = Oscilloscope(device=self.device)
4142
self.waveform_generator = WaveformGenerator(device=self.device)
@@ -163,8 +164,10 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
163164
164165
>>> psl.rgb_led([[10,0,0],[0,10,10],[10,0,10]], output="SQ1", order="RGB")
165166
"""
166-
if "6" in self.device.version:
167+
if "6" in self.version:
167168
pins = {"ONBOARD": 0, "SQ1": 1, "SQ2": 2, "SQ3": 3, "SQ4": 4}
169+
if output == "RGB":
170+
output = "ONBOARD"
168171
else:
169172
pins = {"RGB": CP.SET_RGB1, "PGC": CP.SET_RGB2, "SQ1": CP.SET_RGB3}
170173

@@ -189,24 +192,13 @@ def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
189192
f"Invalid order: {order}. order must contain 'R', 'G', and 'B'."
190193
)
191194

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)
210202

211203
def _read_program_address(self, address: int):
212204
"""Return the value stored at the specified address in program memory.

0 commit comments

Comments
 (0)