Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / LEDBrightnessSetup / plugin.py
index a679237..9d29a46 100755 (executable)
@@ -8,12 +8,10 @@ from Plugins.Plugin import PluginDescriptor
 from Screens.MessageBox import MessageBox
 from Tools.Directories import fileExists
 from enigma import eTimer
-from enigma import eDBoxLCD
-from ledsetup import LEDUpdate
+import fcntl
 
 config.plugins.brightnesssetup = ConfigSubsection()
 config.plugins.brightnesssetup.brightness = ConfigSlider(default = 1, increment = 1, limits = (0,15))
-config.plugins.brightnesssetup.brightnessstandby = ConfigSlider(default = 1, increment = 1, limits = (0,15))
 config.plugins.brightnesssetup.brightnessdeepstandby = ConfigSlider(default = 5, increment = 1, limits = (0,15))
 config.plugins.brightnesssetup.blinkingtime = ConfigSlider(default = 5, increment = 1, limits = (0,15))
 
@@ -22,41 +20,57 @@ class LEDOption:
        DEEPSTANDBY = 1
        BLINKINGTIME = 2
 
-class LEDBrightnessSetupStandby:
+class LEDSetup:
+       LED_IOCTL_BRIGHTNESS_NORMAL = 0X10
+       LED_IOCTL_BRIGHTNESS_DEEPSTANDBY = 0X11
+       LED_IOCTL_BLINKING_TIME = 0X12
+       LED_IOCTL_SET_DEFAULT = 0X13
+
        def __init__(self):
+               self.led_fd = open("/dev/dbox/oled0",'rw')
                self.initLEDSetup()
-               config.misc.standbyCounter.addNotifier(self.standbyBegin, initial_call = False)
-
-       def standbyBegin(self, configElement):
-               from Screens.Standby import inStandby
-               inStandby.onClose.append(self.StandbyEnd)
-               brightness = int(config.plugins.brightnesssetup.brightnessstandby.value)
-               eDBoxLCD.getInstance().setLED(brightness ,LEDOption.BRIGHTNESS)
-
-       def StandbyEnd(self):
-               brightness = int(config.plugins.brightnesssetup.brightness.value)
-               eDBoxLCD.getInstance().setLED(brightness ,LEDOption.BRIGHTNESS)
 
        def initLEDSetup(self):
                brightness = int(config.plugins.brightnesssetup.brightness.value)
                brightnessstandby = int(config.plugins.brightnesssetup.brightnessdeepstandby.value)
                blinkingtime = int(config.plugins.brightnesssetup.blinkingtime.value)
-               eDBoxLCD.getInstance().setLED(brightness ,LEDOption.BRIGHTNESS)
-               eDBoxLCD.getInstance().setLED(brightnessstandby ,LEDOption.DEEPSTANDBY)
-               eDBoxLCD.getInstance().setLED(blinkingtime ,LEDOption.BLINKINGTIME)
+               self.setLEDDefault(brightness, brightnessstandby, blinkingtime)
+
+       def setLEDDefault(self, brightness = 1, brightnessstandby = 5, blinkingtime = 5):
+               default_value = (blinkingtime<<16) + (brightnessstandby<<8) + brightness
+               fcntl.ioctl(self.led_fd , self.LED_IOCTL_SET_DEFAULT, default_value)
+
+       def setLED(self, value, option):
+               if option == LEDOption.BRIGHTNESS:
+                       cmd = self.LED_IOCTL_BRIGHTNESS_NORMAL
+               elif option == LEDOption.DEEPSTANDBY:
+                       cmd = self.LED_IOCTL_BRIGHTNESS_DEEPSTANDBY
+               elif option == LEDOption.BLINKINGTIME:
+                       cmd = self.LED_IOCTL_BLINKING_TIME
+               else:
+                       return
+               fcntl.ioctl(self.led_fd, cmd, value)
+
+       def __del__(self):
+               self.led_fd.close()
+
+ledsetup = LEDSetup()
 
 class LEDBrightnessSetup(Screen,ConfigListScreen):
-       skin = """
-                       <screen name="LEDBrightnessSetup" position="center,center" size="560,300" title="LED Brightness Setup">
-                       <ePixmap pixmap="Vu_HD/buttons/red.png" position="10,10" size="25,25" alphatest="on" />
-                       <ePixmap pixmap="Vu_HD/buttons/green.png" position="195,10" size="25,25" alphatest="on" />
-                       <ePixmap pixmap="Vu_HD/buttons/yellow.png" position="380,10" size="25,25" alphatest="on" />
-                       <widget source="key_red" render="Label" position="30,10" zPosition="1" size="140,25" font="Regular;20" halign="center" valign="center" transparent="1" />
-                       <widget source="key_green" render="Label" position="215,10" zPosition="1" size="140,25" font="Regular;20" halign="center" valign="center" transparent="1" />
-                       <widget source="key_yellow" render="Label" position="400,10" zPosition="1" size="140,25" font="Regular;20" halign="center" valign="center" transparent="1" />
-                       <widget name="config" zPosition="2" position="5,50" size="550,200" scrollbarMode="showOnDemand" transparent="1"/>
+       skin =  """
+               <screen position="center,center" size="560,300" title="LED Brightness Setup">
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="40,10" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="210,10" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/yellow.png" position="380,10" size="140,40" alphatest="on" />
+
+                       <widget source="key_red" render="Label" position="40,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_green" render="Label" position="210,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_yellow" render="Label" position="380,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
+
+                       <widget name="config" zPosition="2" position="5,70" size="550,200" scrollbarMode="showOnDemand" transparent="1"/>
                        <widget name="current_entry" position="130,240" size="300,30" font="Regular;18" halign="center" valign="center"/>
-                       </screen>"""
+               </screen>
+               """
 
        def __init__(self,session):
                Screen.__init__(self,session)
@@ -85,8 +99,6 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
        def displayText(self):
                if self["config"].getCurrent() == self.brightness:
                        self["current_entry"].setText("Touch LED Brightness at Normal state")
-               elif self["config"].getCurrent() == self.brightness_standby:
-                       self["current_entry"].setText("Touch LED Brightness at Standby")
                elif self["config"].getCurrent() == self.brightness_deepstandby:
                        self["current_entry"].setText("Touch LED Brightness at Deep Standby")
                elif self["config"].getCurrent() == self.blinkingtime:
@@ -115,11 +127,9 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
        def createSetup(self):
                self.list = []
                self.brightness = getConfigListEntry(_("Normal state"), config.plugins.brightnesssetup.brightness)
-               self.brightness_standby = getConfigListEntry(_("Standby"), config.plugins.brightnesssetup.brightnessstandby)
                self.brightness_deepstandby = getConfigListEntry(_("Deep Standby"), config.plugins.brightnesssetup.brightnessdeepstandby)
                self.blinkingtime = getConfigListEntry(_("Blinking time"), config.plugins.brightnesssetup.blinkingtime)
                self.list.append( self.brightness )
-               self.list.append( self.brightness_standby )
                self.list.append( self.brightness_deepstandby )
                self.list.append( self.blinkingtime )
                self["config"].list = self.list
@@ -127,10 +137,10 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
 
        def setCurrentValue(self):
                if self["config"].getCurrent() == self.blinkingtime:
-                       eDBoxLCD.getInstance().setLED(1 ,LEDOption.BRIGHTNESS)
-                       eDBoxLCD.getInstance().setLED(self["config"].getCurrent()[1].value ,LEDOption.BLINKINGTIME)
+                       ledsetup.setLED(1 ,LEDOption.BRIGHTNESS)
+                       ledsetup.setLED(self["config"].getCurrent()[1].value ,LEDOption.BLINKINGTIME)
                else:
-                       eDBoxLCD.getInstance().setLED(self["config"].getCurrent()[1].value ,LEDOption.BRIGHTNESS)
+                       ledsetup.setLED(self["config"].getCurrent()[1].value ,LEDOption.BRIGHTNESS)
 
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
@@ -144,9 +154,9 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
                brightness = config.plugins.brightnesssetup.brightness.value
                brightnessstandby = config.plugins.brightnesssetup.brightnessdeepstandby.value
                blinkingtime = config.plugins.brightnesssetup.blinkingtime.value
-               eDBoxLCD.getInstance().setLED(brightness ,LEDOption.BRIGHTNESS)
-               eDBoxLCD.getInstance().setLED(brightnessstandby ,LEDOption.DEEPSTANDBY)
-               eDBoxLCD.getInstance().setLED(blinkingtime ,LEDOption.BLINKINGTIME)
+               ledsetup.setLED(brightness ,LEDOption.BRIGHTNESS)
+               ledsetup.setLED(brightnessstandby ,LEDOption.DEEPSTANDBY)
+               ledsetup.setLED(blinkingtime ,LEDOption.BLINKINGTIME)
 
        def keySave(self):
                if self["config"].isChanged():
@@ -155,12 +165,17 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
 
        def keyDefault(self):
                config.plugins.brightnesssetup.brightness.setValue(1)
-               config.plugins.brightnesssetup.brightnessstandby.setValue(1)
                config.plugins.brightnesssetup.brightnessdeepstandby.setValue(5)
                config.plugins.brightnesssetup.blinkingtime.setValue(5)
                for entry in self["config"].getList():
                        self["config"].l.invalidateEntry(self["config"].getList().index(entry))
 
+               if self["config"].getCurrent() == self.blinkingtime:
+                       self.setCurrentValue()
+               else:
+                       ledsetup.setLED(5 ,LEDOption.BLINKINGTIME)
+                       ledsetup.setLED(self["config"].getCurrent()[1].value ,LEDOption.BRIGHTNESS)
+
        def cancelConfirm(self, result):
                if not result:
                        return
@@ -175,4 +190,3 @@ def main(session, **kwargs):
 def Plugins(**kwargs):
        return [PluginDescriptor(name=_("LED Brightness Setup"), description="Setup LED brightness and blink interval", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
 
-ledbrightnesssetupstandby = LEDBrightnessSetupStandby()