-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathleds.py
84 lines (66 loc) · 2.08 KB
/
leds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
###############################################################################
#
# Copyright (c) 2017-2020 Master AI, Inc.
# ALL RIGHTS RESERVED
#
# Use of this library, in source or binary form, is prohibited without written
# approval from Master AI, Inc.
#
###############################################################################
"""
This module provides an easy way to control the LEDs on your device.
This module provides a fully **synchronous** interface.
"""
from auto.asyncio_tools import thread_safe
from auto.capabilities import list_caps, acquire
def led_map():
"""
Return identifiers and descriptions of the LEDs
available on this controller as a dictionary.
The keys are the identifiers used to control the LEDs
via the `set_led()` method.
"""
return _get_leds().led_map()
def set_led(led_identifier, val):
"""
Set the LED on/off value.
"""
return _get_leds().set_led(led_identifier, val)
def set_many_leds(id_val_list):
"""
Pass a list of tuples, where each tuple is an LED identifier
and the value you want it set to.
"""
return _get_leds().set_many_leds(id_val_list)
def mode_map():
"""
Return identifiers and descriptions of the LED modes
that are available as a dictionary.
The keys are the identifiers used to set the mode
via the `set_mode()` method.
"""
return _get_leds().mode_map()
def set_mode(mode_identifier):
"""
Set the `mode` of the LEDs.
Pass `None` to clear the mode, thereby commencing
basic on/off control via the `set_led()` method.
"""
return _get_leds().set_mode(mode_identifier)
def set_brightness(brightness):
"""
Set the brightness of the LEDs, in the range [0-255].
Raises if not supported by the hardware you have.
"""
return _get_leds().set_brightness(brightness)
@thread_safe
def _get_leds():
global _LEDs
try:
_LEDs
except NameError:
caps = list_caps()
if 'LEDs' not in caps:
raise AttributeError("This device does not have LEDs.")
_LEDs = acquire('LEDs')
return _LEDs