Skip to content

Commit

Permalink
Use existing renderer for gb led settings (#3270)
Browse files Browse the repository at this point in the history
In the enigma from the beginning there is a renderer FrontpanelLed which is used for led control.
Therefore, we can use it and do not need to additionally write values in the proc on startup.
This also introduces the ability to set led profiles for use in different modes for frontpanel led control.
  • Loading branch information
Taapat committed Jan 11, 2022
1 parent 7ed8842 commit 27ac577
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
36 changes: 33 additions & 3 deletions lib/python/Components/Renderer/FrontpanelLed.py
Expand Up @@ -2,12 +2,42 @@

# this is not a GUI renderer.

# | two leds | single led |
# recordstate standby red green
# false false off on off
# true false blnk on blnk
# false true on off off
# true true blnk off blnk
PATTERN_ON = (20, 0xffffffff, 0xffffffff)
PATTERN_OFF = (20, 0, 0)
PATTERN_BLINK = (20, 0x55555555, 0xa7fccf7a)


class LedPatterns():
def __init__(self):
self.__led0_patterns = [PATTERN_OFF, PATTERN_BLINK, PATTERN_ON, PATTERN_BLINK]
self.__led1_patterns = [PATTERN_ON, PATTERN_ON, PATTERN_OFF, PATTERN_OFF]

def setLedPatterns(self, which, patterns):
if which == 0:
self.__led0_patterns = patterns
else:
self.__led1_patterns = patterns

def getLedPatterns(self, which):
if which == 0:
return self.__led0_patterns
return self.__led1_patterns


ledPatterns = LedPatterns()


class FrontpanelLed(Element):
def __init__(self, which=0, patterns=[(20, 0, 0xffffffff), (20, 0x55555555, 0x84fc8c04)], boolean=True):
def __init__(self, which=0, patterns=[PATTERN_ON, PATTERN_BLINK], boolean=True, get_patterns=None):
self.which = which
self.boolean = boolean
self.patterns = patterns
self.patterns = get_patterns if get_patterns else patterns
Element.__init__(self)

def changed(self, *args, **kwargs):
Expand All @@ -16,7 +46,7 @@ def changed(self, *args, **kwargs):
else:
val = self.source.value

(speed, pattern, pattern_4bit) = self.patterns[val]
(speed, pattern, pattern_4bit) = self.patterns[val] if self.patterns != True else ledPatterns.getLedPatterns(self.which)[val]

try:
open("/proc/stb/fp/led%d_pattern" % self.which, "w").write("%08x" % pattern)
Expand Down
27 changes: 9 additions & 18 deletions lib/python/Components/UsageConfig.py
Expand Up @@ -5,6 +5,7 @@
from enigma import setTunerTypePriorityOrder, setPreferredTuner, setSpinnerOnOff, setEnableTtCachingOnOff, eEnv, eDVBDB, Misc_Options, eBackgroundFileEraser, eServiceEvent, eDVBLocalTimeHandler, eEPGCache
from Components.About import GetIPsFromNetworkInterfaces
from Components.NimManager import nimmanager
from Components.Renderer.FrontpanelLed import ledPatterns, PATTERN_ON, PATTERN_OFF, PATTERN_BLINK
from Components.ServiceList import refreshServiceList
from SystemInfo import SystemInfo
import os
Expand All @@ -15,18 +16,6 @@
visuallyImpairedCommentary = "NAR qad"


def leaveStandby():
if not config.usage.powerLED.value:
open(SystemInfo["PowerLED"], "w").write("0")


def standbyCounterChanged(dummy):
from Screens.Standby import inStandby
inStandby.onClose.append(leaveStandby)
if not config.usage.standbyLED.value:
open(SystemInfo["StandbyLED"], "w").write("0")


def InitUsageConfig():
config.usage = ConfigSubsection()
config.usage.subnetwork = ConfigYesNo(default=True)
Expand Down Expand Up @@ -346,20 +335,22 @@ def fanSpeedChanged(configElement):
def powerLEDChanged(configElement):
if "fp" in SystemInfo["PowerLED"]:
open(SystemInfo["PowerLED"], "w").write(configElement.value and "1" or "0")
patterns = [PATTERN_ON, PATTERN_ON, PATTERN_OFF, PATTERN_OFF] if configElement.value else [PATTERN_OFF, PATTERN_OFF, PATTERN_OFF, PATTERN_OFF]
ledPatterns.setLedPatterns(1, patterns)
else:
open(SystemInfo["PowerLED"], "w").write(configElement.value and "on" or "off")
config.usage.powerLED = ConfigYesNo(default=True)
config.usage.powerLED.addNotifier(powerLEDChanged)

if SystemInfo["StandbyLED"]:
def standbyLEDChanged(configElement):
open(SystemInfo["StandbyLED"], "w").write(configElement.value and "on" or "off")
if "fp" in SystemInfo["StandbyLED"]:
patterns = [PATTERN_OFF, PATTERN_BLINK, PATTERN_ON, PATTERN_BLINK] if configElement.value else [PATTERN_OFF, PATTERN_OFF, PATTERN_OFF, PATTERN_OFF]
ledPatterns.setLedPatterns(0, patterns)
else:
open(SystemInfo["StandbyLED"], "w").write(configElement.value and "on" or "off")
config.usage.standbyLED = ConfigYesNo(default=True)
if not "fp" in SystemInfo["StandbyLED"]:
config.usage.standbyLED.addNotifier(standbyLEDChanged)

if SystemInfo["PowerLED"] and "fp" in SystemInfo["PowerLED"] and not config.usage.powerLED.value or (SystemInfo["StandbyLED"] and "fp" in SystemInfo["StandbyLED"] and not config.usage.standbyLED.value):
config.misc.standbyCounter.addNotifier(standbyCounterChanged, initial_call=False)
config.usage.standbyLED.addNotifier(standbyLEDChanged)

if SystemInfo["SuspendLED"]:
def suspendLEDChanged(configElement):
Expand Down
32 changes: 11 additions & 21 deletions lib/python/Screens/SessionGlobals.py
Expand Up @@ -8,7 +8,7 @@
from Components.Sources.Boolean import Boolean
from Components.Sources.RecordState import RecordState
from Components.Converter.Combine import Combine
from Components.Renderer.FrontpanelLed import FrontpanelLed
from Components.Renderer.FrontpanelLed import FrontpanelLed, PATTERN_OFF, PATTERN_BLINK


class SessionGlobals(Screen):
Expand All @@ -26,25 +26,15 @@ def __init__(self, session):

from Components.SystemInfo import SystemInfo

combine = Combine(func=lambda s: {(False, False): 0, (False, True): 1, (True, False): 2, (True, True): 3}[(s[0].boolean, s[1].boolean)])
combine.connect(self["Standby"])
combine.connect(self["RecordState"])

# | two leds | single led |
# recordstate standby red green
# false false off on off
# true false blnk on blnk
# false true on off off
# true true blnk off blnk

PATTERN_ON = (20, 0xffffffff, 0xffffffff)
PATTERN_OFF = (20, 0, 0)
PATTERN_BLINK = (20, 0x55555555, 0xa7fccf7a)

nr_leds = SystemInfo.get("NumFrontpanelLEDs", 0)

if nr_leds == 1:
FrontpanelLed(which=0, boolean=False, patterns=[PATTERN_OFF, PATTERN_BLINK, PATTERN_OFF, PATTERN_BLINK]).connect(combine)
elif nr_leds == 2:
FrontpanelLed(which=0, boolean=False, patterns=[PATTERN_OFF, PATTERN_BLINK, PATTERN_ON, PATTERN_BLINK]).connect(combine)
FrontpanelLed(which=1, boolean=False, patterns=[PATTERN_ON, PATTERN_ON, PATTERN_OFF, PATTERN_OFF]).connect(combine)
if nr_leds > 0:
combine = Combine(func=lambda s: {(False, False): 0, (False, True): 1, (True, False): 2, (True, True): 3}[(s[0].boolean, s[1].boolean)])
combine.connect(self["Standby"])
combine.connect(self["RecordState"])

if nr_leds == 1:
FrontpanelLed(which=0, boolean=False, patterns=[PATTERN_OFF, PATTERN_BLINK, PATTERN_OFF, PATTERN_BLINK]).connect(combine)
elif nr_leds == 2:
FrontpanelLed(which=0, boolean=False, get_patterns=True).connect(combine)
FrontpanelLed(which=1, boolean=False, get_patterns=True).connect(combine)

0 comments on commit 27ac577

Please sign in to comment.