|
| 1 | +from enigma import iRecordableService |
| 2 | +from Components.config import config, ConfigSlider, ConfigSelection, ConfigSubsection |
| 3 | +from Tools.Directories import fileExists |
| 4 | + |
| 5 | + |
| 6 | +config.fp = ConfigSubsection() |
| 7 | +config.fp.led = ConfigSubsection() |
| 8 | +colors = [ |
| 9 | + ("0xFF0000", _("red")), |
| 10 | + ("0xFF3333", _("rose")), |
| 11 | + ("0xFF5500", _("orange")), |
| 12 | + ("0xDD9900", _("yellow")), |
| 13 | + ("0x99DD00", _("lime")), |
| 14 | + ("0x00FF00", _("green")), |
| 15 | + ("0x00FF99", _("aqua")), |
| 16 | + ("0x00BBFF", _("olympic blue")), |
| 17 | + ("0x0000FF", _("blue")), |
| 18 | + ("0x6666FF", _("azure")), |
| 19 | + ("0x9900FF", _("purple")), |
| 20 | + ("0xFF0066", _("pink")), |
| 21 | + ("0xFFFFFF", _("white")), |
| 22 | +] |
| 23 | +# running |
| 24 | +config.fp.led.default_color = ConfigSelection(colors, default="0xFFFFFF") |
| 25 | +config.fp.led.default_brightness = ConfigSlider(default=0xff, increment=25, limits=(0, 0xff)) |
| 26 | +# standby |
| 27 | +config.fp.led.standby_color = ConfigSelection(colors, default="0xFFFFFF") |
| 28 | +config.fp.led.standby_brightness = ConfigSlider(default=0x08, increment=8, limits=(0, 0xff)) |
| 29 | +# shutdown |
| 30 | +config.fp.led.shutdown_color = ConfigSelection(colors, default="0xFF5500") |
| 31 | + |
| 32 | +frontPanelLed = None |
| 33 | + |
| 34 | + |
| 35 | +class FrontPanelLed: |
| 36 | + BLINK_PATH = "/proc/stb/fp/led_blink" |
| 37 | + BLINK_DEFAULT = 0x0710ff |
| 38 | + |
| 39 | + BRIGHTNESS_PATH = "/proc/stb/fp/led_brightness" |
| 40 | + BRIGHTNESS_DEFAULT = 0xFF |
| 41 | + |
| 42 | + COLOR_PATH = "/proc/stb/fp/led_color" |
| 43 | + COLOR_DEFAULT = 0xFFFFFF |
| 44 | + |
| 45 | + FADE_PATH = "/proc/stb/fp/led_fade" |
| 46 | + FADE_DEFAULT = 0x7 |
| 47 | + |
| 48 | + instance = None |
| 49 | + |
| 50 | + def __init__(self): |
| 51 | + assert (not FrontPanelLed.instance) |
| 52 | + FrontPanelLed.instance = self |
| 53 | + self._session = None |
| 54 | + self.default() |
| 55 | + config.misc.standbyCounter.addNotifier(self._onStandby, initial_call=False) |
| 56 | + config.fp.led.default_color.addNotifier(self._onDefaultChanged, initial_call=False) |
| 57 | + config.fp.led.default_brightness.addNotifier(self._onDefaultChanged, initial_call=False) |
| 58 | + |
| 59 | + def init(self, session): |
| 60 | + self._session = session |
| 61 | + session.nav.record_event.append(self.checkRecordings) |
| 62 | + |
| 63 | + def _onDefaultChanged(self, *args): |
| 64 | + from Screens.Standby import inStandby |
| 65 | + if not inStandby: |
| 66 | + FrontPanelLed.default() |
| 67 | + |
| 68 | + def _onStandby(self, *args): |
| 69 | + FrontPanelLed.standby() |
| 70 | + from Screens.Standby import inStandby |
| 71 | + if inStandby: |
| 72 | + inStandby.onClose.append(self._onLeaveStandby) |
| 73 | + |
| 74 | + def _onLeaveStandby(self): |
| 75 | + FrontPanelLed.default() |
| 76 | + |
| 77 | + def checkRecordings(self, service=None, event=iRecordableService.evEnd): |
| 78 | + if not self._session: |
| 79 | + return |
| 80 | + if event == iRecordableService.evEnd: |
| 81 | + recordings = self._session.nav.getRecordings() |
| 82 | + if not recordings: |
| 83 | + FrontPanelLed.stopRecording() |
| 84 | + else: |
| 85 | + FrontPanelLed.recording() |
| 86 | + elif event == iRecordableService.evStart: |
| 87 | + FrontPanelLed.recording() |
| 88 | + |
| 89 | + @staticmethod |
| 90 | + def _write(path, value): |
| 91 | + if not fileExists(path): |
| 92 | + print("[FrontPanelLed] %s does not exist!" % (path)) |
| 93 | + return |
| 94 | + with open(path, 'w') as f: |
| 95 | + value = "%x" % (value) |
| 96 | + print("[FrontPanelLed] : %s" % (value)) |
| 97 | + f.write(value) |
| 98 | + |
| 99 | + # 8 bit brightness |
| 100 | + @staticmethod |
| 101 | + def setBrightness(value=BRIGHTNESS_DEFAULT): |
| 102 | + if value > 0xff or value < 0: |
| 103 | + print("[FrontPanelLed] LED brightness has to be between 0x0 and 0xff! Using default value (%x)" % (FrontPanelLed.BRIGHTNESS_DEFAULT)) |
| 104 | + value = FrontPanelLed.BRIGHTNESS_DEFAULT |
| 105 | + FrontPanelLed._write(FrontPanelLed.BRIGHTNESS_PATH, value) |
| 106 | + |
| 107 | + # 24 bit RGB |
| 108 | + @staticmethod |
| 109 | + def setColor(value=COLOR_DEFAULT): |
| 110 | + if value > 0xffffff or value < 0: |
| 111 | + print("[FrontPanelLed] LED color has to be between 0x0 and 0xffffff (r, g b)! Using default value (%x)" % (FrontPanelLed.COLOR_DEFAULT)) |
| 112 | + value = FrontPanelLed.COLOR_DEFAULT |
| 113 | + FrontPanelLed._write(FrontPanelLed.COLOR_PATH, value) |
| 114 | + |
| 115 | + # 8 bit on-time (* 31ms), 8 bit total time (* 31ms), 8 bit number of repeats (ff == unlimited) |
| 116 | + @staticmethod |
| 117 | + def setBlink(value=BLINK_DEFAULT): |
| 118 | + if value > 0xffffff or value < 0: |
| 119 | + print("[FrontPanelLed] LED blink has to be between 0x0 and 0xffffff (on, total, repeats)! Using default value (%x)" % (FrontPanelLed.BLINK_DEFAULT)) |
| 120 | + value = FrontPanelLed.BLINK_DEFAULT |
| 121 | + FrontPanelLed._write(FrontPanelLed.BLINK_PATH, value) |
| 122 | + |
| 123 | + # 8 bit fade time (* 51ms) |
| 124 | + @staticmethod |
| 125 | + def setFade(value=FADE_DEFAULT): |
| 126 | + if value > 0xff or value < 0: |
| 127 | + value = FrontPanelLed.FADE_DEFAULT |
| 128 | + print("[FrontPanelLed] LED fade has to be between 0x0 and 0xff! Using default value (%x)" % (FrontPanelLed.FADE_DEFAULT)) |
| 129 | + FrontPanelLed._write(FrontPanelLed.FADE_PATH, value) |
| 130 | + |
| 131 | + @staticmethod |
| 132 | + def default(checkRec=True): |
| 133 | + FrontPanelLed.setBrightness(config.fp.led.default_brightness.value) |
| 134 | + FrontPanelLed.setColor(int(config.fp.led.default_color.value, 0)) |
| 135 | + if checkRec: |
| 136 | + FrontPanelLed.instance.checkRecordings() |
| 137 | + |
| 138 | + @staticmethod |
| 139 | + def recording(): |
| 140 | + FrontPanelLed.setFade() |
| 141 | + FrontPanelLed.setBlink() |
| 142 | + |
| 143 | + @staticmethod |
| 144 | + def stopRecording(): |
| 145 | + from Screens.Standby import inStandby |
| 146 | + if inStandby: |
| 147 | + FrontPanelLed.standby(False) |
| 148 | + else: |
| 149 | + FrontPanelLed.default(False) |
| 150 | + |
| 151 | + @staticmethod |
| 152 | + def standby(checkRec=True): |
| 153 | + FrontPanelLed.setBrightness(config.fp.led.standby_brightness.value) |
| 154 | + FrontPanelLed.setColor(int(config.fp.led.standby_color.value, 0)) |
| 155 | + if checkRec: |
| 156 | + FrontPanelLed.instance.checkRecordings() |
| 157 | + |
| 158 | + @staticmethod |
| 159 | + def shutdown(): |
| 160 | + FrontPanelLed.setFade(0) |
| 161 | + FrontPanelLed.setBrightness(0xFF) |
| 162 | + FrontPanelLed.setColor(int(config.fp.led.shutdown_color.value, 0)) |
| 163 | + FrontPanelLed.setBlink() |
| 164 | + |
| 165 | + |
| 166 | +frontPanelLed = FrontPanelLed() |
0 commit comments