-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLEDButtonElement.py
More file actions
46 lines (37 loc) · 1.48 KB
/
LEDButtonElement.py
File metadata and controls
46 lines (37 loc) · 1.48 KB
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
from LividConstants import *
from Elementary import Elementary
from FlashingButtonElement import FlashingButtonElement
from _Framework.ButtonElement import ButtonElement
class LEDButtonElement(FlashingButtonElement):
'Custom button element that can send state to multiple LEDs as needed'
def __init__(self,
is_momentary,
msg_type,
channel,
identifier,
off_color = 0,
on_color = 127,
blink_on = False,
blink_colors = [RED],
color_mappings = None,
**kwargs):
FlashingButtonElement.__init__(self, is_momentary, msg_type, channel, identifier,
blink_on = blink_on,
blink_colors = blink_colors)
self.setup_color_mappings(color_mappings)
def setup_color_mappings(self, color_mappings):
self.leds = {}
if color_mappings is not None:
for value, note_offset in color_mappings.items():
adjusted_identifier = self._msg_identifier + note_offset
if note_offset > 0: # Don't create an alias for the root button if it has one
self.leds[value] = ButtonElement(True, self._msg_type, self._msg_channel, adjusted_identifier)
def send_value(self, value, force_send=False):
if value == 0:
FlashingButtonElement.send_value(self, value, force_send)
else:
if self.leds.has_key(value):
FlashingButtonElement.send_value(self, value, force_send)
self.leds[value].send_value(127, True)
else:
FlashingButtonElement.send_value(self, value, force_send)