Skip to content

Commit 683797e

Browse files
PSOSPA LED updated (#70)
* Added features: - Get channel number for psospa class - Added str Literals for colours (hue) - Added set all functions for colour and states * Updated documentation to match changes * Upversioned 1.2.2 (docs 0.3.1)
1 parent 469bc8a commit 683797e

File tree

6 files changed

+101
-24
lines changed

6 files changed

+101
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ Current PicoScope support:
4545
- [pypi-nightly (dev repo)](https://pypi.org/project/pypicosdk-nightly/)
4646

4747
## Version Control
48-
pyPicoSDK: 1.2.1
48+
pyPicoSDK: 1.2.2
4949

50-
Docs: 0.3.0
50+
Docs: 0.3.1

docs/docs/ref/psospa/led.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The LED's on the 3000E are controllable via hue, saturation and brightness. To control them these rules need to be met:
44

5-
- To control each LED `set_led_states([led], 'on')` must be called first per LED. It is automatically called in `set_led_colours()`.
5+
- To control each LED `set_led_states([led], 'on')` must be called first per LED.
66
<!-- - For both `set_led_brightness()` and `set_led_colours()`, on of the following commands needs to be ran to apply the settings:
77
- `run_block_capture()`
88
- `run_streaming()`
@@ -12,12 +12,21 @@ The LED's on the 3000E are controllable via hue, saturation and brightness. To c
1212
Here is an example of changing Channel A and Channel B to red and green, respectively:
1313
```
1414
import pypicosdk as psdk
15+
import time
1516
1617
scope = psdk.psospa()
1718
scope.open_unit()
1819
20+
scope.set_led_states('A', 'on')
1921
scope.set_led_colours('A', 0, 100)
20-
scope.set_led_colours('B', 100, 100)
22+
time.sleep(2)
23+
# OR
24+
scope.set_led_states(['A', 'B', 'C'], ['on', 'on', 'on'])
25+
scope.set_led_colours(['A', 'B', 'C'], ['red', 'green', 'blue'], [100, 100, 100])
26+
time.sleep(2)
27+
# or
28+
scope.set_all_led_states('on')
29+
scope.set_all_led_colours('pink')
2130
2231
input('Waiting for user... ')
2332
```
@@ -29,6 +38,7 @@ The LEDs are controlled via the functions below:
2938
filters:
3039
- "!.*"
3140
- "set_led"
41+
- "set_all_led"
3242
- "!_to_"
3343
- "!^_"
3444
show_root_toc_entry: false

pypicosdk/constants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ class PICO_LED_COLOUR_PROPERTIES(ctypes.Structure):
948948
class PICO_LED_STATE_PROPERTIES(ctypes.Structure):
949949
"""This structure is used with set_led_states() to define the
950950
state for one LED."""
951-
_pack_ = 1
951+
# _pack_ = 8
952952
_fields_ = [
953953
("led_", ctypes.c_uint32),
954954
("state_", ctypes.c_int8),
@@ -957,6 +957,9 @@ class PICO_LED_STATE_PROPERTIES(ctypes.Structure):
957957
led_state_l = Literal['auto', 'off', 'on']
958958
led_state_m = {'auto': -1, 'off': 0, 'on': 1}
959959

960+
led_colours_l = Literal['red', 'green', 'blue', 'yellow', 'pink']
961+
led_colours_m = {'red': 0, 'green': 100, 'blue': 244, 'yellow': 61, 'pink':306}
962+
960963
# Public names exported by :mod:`pypicosdk.constants` for ``import *`` support.
961964
# This explicit list helps static analyzers like Pylance discover available
962965
# attributes when the parent package re-exports ``pypicosdk.constants`` using
@@ -1023,6 +1026,8 @@ class PICO_LED_STATE_PROPERTIES(ctypes.Structure):
10231026
'led_channel_m',
10241027
'led_state_l',
10251028
'led_state_m',
1029+
'led_colours_l',
1030+
'led_colours_m',
10261031
'range_literal',
10271032
'range_map',
10281033
'resolution_literal',

pypicosdk/psospa.py

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def open_unit(self, serial_number:str=None, resolution:RESOLUTION | resolution_l
4949
self.resolution = resolution
5050
self.set_all_channels_off()
5151
self.min_adc_value, self.max_adc_value =super().get_adc_limits()
52+
self.n_channels = self.get_variant_details()['NumberOfAnalogueChannels']
5253

5354
return usb_power_struct
5455

@@ -214,7 +215,27 @@ def set_led_brightness(self, brightness:int) -> None:
214215
brightness,
215216
)
216217

217-
def set_led_colours(self, led:led_channel_l, hue:int, saturation:int) -> None:
218+
def set_all_led_colours(self, hue:int|led_colours_l, saturation:int=100) -> None:
219+
"""
220+
Sets all LED's on the PicoScope to a single colour
221+
222+
Args:
223+
hue (int | str): Colour as a hue in [0-359] or a
224+
basic colour from the following:
225+
['red', 'green', 'blue', 'yellow', 'pink']
226+
227+
saturation (int, optional): Saturation of the colour [0-100]. Defaults to 100.
228+
"""
229+
led_list = list(led_channel_m.keys())
230+
led_list = led_list[:self.n_channels] + led_list[-2:]
231+
self.set_led_colours(led_list, [hue] * len(led_list), [saturation] * len(led_list))
232+
233+
def set_led_colours(
234+
self,
235+
led:led_channel_l | list[led_channel_l],
236+
hue:int | led_colours_l | list[int] | list[led_colours_l],
237+
saturation:int | list[int]
238+
) -> None:
218239
"""Sets the colour of the selected LED using HUE and Saturation
219240
220241
It will not take affect until one of the following
@@ -225,22 +246,53 @@ def set_led_colours(self, led:led_channel_l, hue:int, saturation:int) -> None:
225246
- siggen_apply()
226247
227248
Args:
228-
led (str): The selected LED. Must be one of these values:
249+
led (str|list[str]): The selected LED. Must be one or a list of these values:
229250
`'A'`, `'B'`, `'C'`, `'D'`, `'E'`, `'F'`, `'G'`, `'H'`, `'AWG'`, `'AUX'`.
230-
hue (int): Hue of the LED, [0-359].
231-
saturation (int): Saturation of the LED, [0-100].
251+
hue (int|list[int]): Colour as a hue in [0-359] or a
252+
basic colour from the following:
253+
['red', 'green', 'blue', 'yellow', 'pink']
254+
saturation (int|list[int]): Saturation of the LED, [0-100].
232255
"""
233-
self.set_led_states(led, "on")
234-
led = led_channel_m[led]
235-
led_struct = PICO_LED_COLOUR_PROPERTIES(led, hue, saturation)
256+
# if isinstance(hue, str):
257+
# hue = led_colours_m[hue]
258+
259+
if not isinstance(led, list):
260+
led = [led]
261+
hue = [hue]
262+
saturation = [saturation]
263+
264+
if isinstance(hue[0], str):
265+
hue = [led_colours_m[i] for i in hue]
266+
267+
array_len = len(led)
268+
array_struct = (PICO_LED_COLOUR_PROPERTIES * array_len)()
269+
270+
for i in range(array_len):
271+
array_struct[i] = PICO_LED_COLOUR_PROPERTIES(
272+
led_channel_m[led[i]],
273+
hue[i],
274+
saturation[i]
275+
)
276+
236277
self._call_attr_function(
237278
"SetLedColours",
238279
self.handle,
239-
led_struct,
240-
1,
280+
ctypes.byref(array_struct),
281+
array_len,
241282
)
283+
284+
def set_all_led_states(self,state:str|led_state_l):
285+
"""
286+
Sets the state of all LED's on the PicoScope.
242287
243-
def set_led_states(self, led:str|led_channel_l, state:str|led_state_l):
288+
Args:
289+
state (str): ['auto', 'on', 'off']
290+
"""
291+
led_list = list(led_channel_m.keys())
292+
led_list = led_list[:self.n_channels] + led_list[-2:]
293+
self.set_led_states(led_list, [state] * len(led_list))
294+
295+
def set_led_states(self, led:str|led_channel_l|list[led_channel_l], state:str|led_state_l|list[led_state_l]):
244296
"""
245297
Sets the state for a selected LED. Between default behaviour (auto),
246298
on or off.
@@ -250,12 +302,22 @@ def set_led_states(self, led:str|led_channel_l, state:str|led_state_l):
250302
`'A'`, `'B'`, `'C'`, `'D'`, `'E'`, `'F'`, `'G'`, `'H'`, `'AWG'`, `'AUX'`.
251303
state (str): State of selected LED: `'auto'`, `'off'`, `'on'`.
252304
"""
253-
led = led_channel_m[led]
254-
state = led_state_m[state]
255-
struct = PICO_LED_STATE_PROPERTIES(led, state)
305+
if not isinstance(led, list):
306+
led = [led]
307+
state = [state]
308+
309+
array_len = len(led)
310+
array_struct = (PICO_LED_STATE_PROPERTIES * array_len)()
311+
312+
for i in range(array_len):
313+
array_struct[i] = PICO_LED_STATE_PROPERTIES(
314+
led_channel_m[led[i]],
315+
led_state_m[state[i]]
316+
)
317+
256318
self._call_attr_function(
257319
'SetLedStates',
258320
self.handle,
259-
struct,
260-
1
261-
)
321+
ctypes.byref(array_struct),
322+
ctypes.c_uint32(array_len)
323+
)

pypicosdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
VERSION = "1.2.1"
2+
VERSION = "1.2.2"

version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Master version file for all scripts.
22
# Update these variables and run a build-tool (which will run version_updater.py)
3-
docs_version = "0.3.0"
4-
package_version = "1.2.1"
3+
docs_version = "0.3.1"
4+
package_version = "1.2.2"

0 commit comments

Comments
 (0)