allow non-binary states
[enigma2.git] / lib / python / Components / Renderer / FrontpanelLed.py
1 from Components.Element import Element
2
3 # this is not a GUI renderer.
4 class FrontpanelLed(Element):
5         def __init__(self, which = 0, patterns = [(20, 0, 0xffffffff),(20, 0x55555555, 0x84fc8c04)], boolean = True):
6                 self.which = which
7                 self.boolean = boolean
8                 self.patterns = patterns
9                 Element.__init__(self)
10
11         def changed(self, *args, **kwargs):
12                 if self.boolean:
13                         val = self.source.boolean and 0 or 1
14                 else:
15                         val = self.source.value
16         
17                 (speed, pattern, pattern_4bit) = self.patterns[val]
18
19                 try:
20                         open("/proc/stb/fp/led%d_pattern" % self.which, "w").write("%08x" % pattern)
21                 except IOError:
22                         pass
23                 if self.which == 0:
24                         try:
25                                 open("/proc/stb/fp/led_pattern", "w").write("%08x" % pattern_4bit)
26                         except IOError:
27                                 pass
28                         try:
29                                 open("/proc/stb/fp/led_pattern_speed", "w").write("%d" % speed)
30                         except IOError:
31                                 pass