Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / LEDBrightnessSetup / plugin.py
index 04e2a08..9d29a46 100755 (executable)
@@ -8,7 +8,7 @@ from Plugins.Plugin import PluginDescriptor
 from Screens.MessageBox import MessageBox
 from Tools.Directories import fileExists
 from enigma import eTimer
-from enigma import eDBoxLCD
+import fcntl
 
 config.plugins.brightnesssetup = ConfigSubsection()
 config.plugins.brightnesssetup.brightness = ConfigSlider(default = 1, increment = 1, limits = (0,15))
@@ -20,28 +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()
 
        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().setLEDDefault(brightness, brightnessstandby, 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)
@@ -108,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)
@@ -125,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():
@@ -141,6 +170,12 @@ class LEDBrightnessSetup(Screen,ConfigListScreen):
                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
@@ -155,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()