ManualFancontrol : add fanOFF mode (PWM 0), and so on
authorChang.H.S <jhs@dev3>
Thu, 7 Jul 2011 08:36:18 +0000 (17:36 +0900)
committerChang.H.S <jhs@dev3>
Thu, 7 Jul 2011 11:48:42 +0000 (20:48 +0900)
lib/python/Plugins/SystemPlugins/ManualFancontrol/InstandbyOn.py
lib/python/Plugins/SystemPlugins/ManualFancontrol/plugin.py

index b7eb5ae..696c08f 100755 (executable)
@@ -2,22 +2,52 @@ from Components.config import config, ConfigSubList, ConfigSubsection
 import NavigationInstance
 from enigma import iRecordableService
 from Components.ConfigList import ConfigListScreen
-from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger, ConfigSlider
+from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSlider
+from enigma import eTimer
 
 config.plugins.simplefancontrols = ConfigSubsection()
-config.plugins.simplefancontrols.standbymode = ConfigSelection(default = "on", choices = [
-       ("off", _("off")), ("on", _("on"))])
-config.plugins.simplefancontrols.recordingmode = ConfigSelection(default = "on", choices = [
-       ("off", _("no")), ("on", _("yes"))])
-config.plugins.simplefancontrols.pwmvalue = ConfigSlider(default = 100, increment = 5, limits = (5, 255))
+config.plugins.simplefancontrols.standbymode = ConfigSelection(default = "yes", choices = [
+       ("no", _("no")), ("yes", _("yes"))])
+config.plugins.simplefancontrols.pwmvalue = ConfigSlider(default = 100, increment = 5, limits = (0, 255))
 
 class instandbyOn:
        def __init__(self):
+               self.fanoffmode = 'OFF'
+               self.default_pwm_value_onRecordings = 5
                config.misc.standbyCounter.addNotifier(self.standbyBegin, initial_call = False)
+               if config.plugins.simplefancontrols.pwmvalue.value == 0:
+                       self.fanoffmode = 'ON'
+               self.InitTimer = eTimer()
+               if self.initConfig not in self.InitTimer.callback:
+                       self.InitTimer.callback.append(self.initConfig)
+               print "<SimpleFancontrol> init : Timer loop start!!"
+               self.InitTimer.startLongTimer(3)
+               print "<SimpleFancontrol> init :  self.fanoffmode : ", self.fanoffmode
+               print "<SimpleFancontrol> init :  config.plugins.simplefancontrols.pwmvalue.value : ", config.plugins.simplefancontrols.pwmvalue.value
+
+       def initConfig(self):
+               print "<SimpleFancontrol>Try initConfig..."
+               if NavigationInstance.instance is None:
+                       self.InitTimer.startLongTimer(1)
+               else:
+                       if config.plugins.simplefancontrols.pwmvalue.value == 0:
+                               currentPWM = self.getPWM()
+                               NavigationInstance.instance.record_event.append(self.getRecordEvent_onFanOFF)
+                               recordings = NavigationInstance.instance.getRecordings()
+                               print "<SimpleFancontrol> initConfig :  recordings : ", recordings
+                               if recordings and currentPWM != self.default_pwm_value_onRecordings:
+                                       self.setPWM(self.default_pwm_value_onRecordings)
+                               elif not recordings and currentPWM > 0:
+                                       self.setPWM(0)
+                               else:
+                                       print "<SimpleFancontrol> initConfig : setPWM pass"
+                       elif self.getPWM() != config.plugins.simplefancontrols.pwmvalue.value:
+                               self.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
 
        def standbyBegin(self, configElement):
-                       print "<SimpleFancontrol> config.plugins.fancontrols.standbymode.value : ", config.plugins.simplefancontrols.standbymode.value
-                       if config.plugins.simplefancontrols.standbymode.value == "on":
+                       print "<SimpleFancontrol> standbyBegin : config.plugins.fancontrols.standbymode.value : ", config.plugins.simplefancontrols.standbymode.value
+                       print "<SimpleFancontrol> standbyBegin : self.fanoffmode : ", self.fanoffmode
+                       if config.plugins.simplefancontrols.standbymode.value == "yes" and config.plugins.simplefancontrols.pwmvalue > 0:
                                from Screens.Standby import inStandby
                                inStandby.onClose.append(self.StandbyEnd)
                                NavigationInstance.instance.record_event.append(self.getRecordEvent)
@@ -56,5 +86,28 @@ class instandbyOn:
                f.write("%x" % value)
                f.close()
 
+       def appendRecordEventCallback(self):
+               print "<SimpleFancontrol> appendRecordEventCallback "
+               NavigationInstance.instance.record_event.append(self.getRecordEvent_onFanOFF)
+               recordings = NavigationInstance.instance.getRecordings()
+               if recordings:
+                       instandbyon.setPWM(self.default_pwm_value_onRecordings)
+
+       def removeRecordEventCallback(self):
+               print "<SimpleFancontrol> removeRecordEventCallback "
+               NavigationInstance.instance.record_event.remove(self.getRecordEvent_onFanOFF)
+
+       def getRecordEvent_onFanOFF(self, recservice, event):
+               recordings = len(NavigationInstance.instance.getRecordings())
+               print "<SimpleFancontrol_> recordings : %d , event : %d" % (recordings,event)
+               if event == iRecordableService.evEnd:
+                       print "<SimpleFancontrol_> getRecordEvent : evEnd"
+                       if recordings == 0:
+                               self.setPWM(0)
+               elif event == iRecordableService.evStart:
+                       print "<SimpleFancontrol_> getRecordEvent : evStart"
+                       if self.getPWM() == 0:
+                               self.setPWM(self.default_pwm_value_onRecordings)
+
 instandbyon = instandbyOn()
 
index 4574e0f..a8def15 100755 (executable)
@@ -6,6 +6,7 @@ from Screens.MessageBox import MessageBox
 from Components.Sources.StaticText import StaticText
 from Plugins.Plugin import PluginDescriptor
 from Plugins.SystemPlugins.ManualFancontrol.InstandbyOn import instandbyon
+import NavigationInstance
 
 class ManualFancontrol(Screen,ConfigListScreen):
        skin = """
@@ -20,8 +21,6 @@ class ManualFancontrol(Screen,ConfigListScreen):
 
        def __init__(self,session):
                Screen.__init__(self,session)
-               print "init"
-               self.setup_title="TestSetupTitle"
                self.session = session
                self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
                {
@@ -35,50 +34,100 @@ class ManualFancontrol(Screen,ConfigListScreen):
                self["key_red"] = StaticText(_("Cancel"))
                self["key_green"] = StaticText(_("Save"))
                self["current"] = StaticText(_(" "))
-               self.createSetup()
+               self.configSetup()
+               self.backup_pwm = instandbyon.getPWM()
+               self.OnRecording = False
+
+       def isRecording(self):
+               recordings = NavigationInstance.instance.getRecordings()
+               if recordings :
+                       return True
+               else:
+                       return False
 
        def displayCurrentValue(self):
-               cur = self["config"].getCurrent()[0]
-               val = self["config"].getCurrent()[1].value
-               currrent_val = cur+" : "+str(val)
+               currrent_val = self["config"].getCurrent()[0]+" : "+str(self["config"].getCurrent()[1].value)
                self["current"].setText(_(currrent_val))
                print currrent_val
 
        def selectionChanged(self):
-               self.displayCurrentValue()
                if self["config"].getCurrent() == self.pwmEntry:
                        instandbyon.setPWM(self["config"].getCurrent()[1].value)
 
        def keyLeft(self):
+               oldpwmvalue=config.plugins.simplefancontrols.pwmvalue.value
                ConfigListScreen.keyLeft(self)
-               self.newConfig()
+               if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 5:
+                       self.createSetup()
+               else:
+                       self.displayCurrentValue()
                self.selectionChanged()
 
        def keyRight(self):
+               oldpwmvalue=config.plugins.simplefancontrols.pwmvalue.value
                ConfigListScreen.keyRight(self)
-               self.newConfig()
+               if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 0:
+                       self.createSetup()
+                       while self["config"].getCurrent() != self.pwmEntry:
+                               self["config"].setCurrentIndex(self["config"].getCurrentIndex()+1)
+               else:
+                       self.displayCurrentValue()
                self.selectionChanged()
 
        def createSetup(self):
                self.list = []
-               self.standbyEntry = getConfigListEntry(_("FanOFF InStanby"), config.plugins.simplefancontrols.standbymode)
-               self.pwmEntry = getConfigListEntry(_("PWM value"), config.plugins.simplefancontrols.pwmvalue)
-               self.list.append( self.standbyEntry )
+               if config.plugins.simplefancontrols.pwmvalue.value > 0:
+                       self.list.append( self.standbyEntry )
                self.list.append( self.pwmEntry )
                self["config"].list = self.list
                self["config"].l.setList(self.list)
+
+       def configSetup(self):
+               self.standbyEntry = getConfigListEntry(_("FanOFF InStanby"), config.plugins.simplefancontrols.standbymode)
+               self.pwmEntry = getConfigListEntry(_("PWM value"), config.plugins.simplefancontrols.pwmvalue)
                if not self.displayCurrentValue in self["config"].onSelectionChanged:
                        self["config"].onSelectionChanged.append(self.displayCurrentValue)
+               self.createSetup()
 
        def newConfig(self):
-               if self["config"].getCurrent() == self.standbyEntry:
+               if self["config"].getCurrent() == self.pwmEntry and config.plugins.simplefancontrols.pwmvalue.value == 0:
                        self.createSetup()
 
        def keySave(self):
+               if instandbyon.fanoffmode is 'OFF' and config.plugins.simplefancontrols.pwmvalue.value == 0:
+                       instandbyon.appendRecordEventCallback()
+                       instandbyon.fanoffmode = 'ON'
+                       print "<SimpleFancontrol> instandbyon.fanoffmode 'OFF' -> 'ON'"
+
+               elif instandbyon.fanoffmode is 'ON' and config.plugins.simplefancontrols.pwmvalue.value != 0:
+                       instandbyon.removeRecordEventCallback()
+                       instandbyon.fanoffmode = 'OFF'
+                       print "<SimpleFancontrol> instandbyon.fanoffmode 'ON' -> 'OFF'"
+               if instandbyon.fanoffmode == 'ON' and self.isRecording() and instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
+                       instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
                ConfigListScreen.keySave(self)
 
+       def cancelConfirm(self, result):
+               if not result:
+                       return
+               for x in self["config"].list:
+                       x[1].cancel()
+               if instandbyon.fanoffmode == 'ON' and self.isRecording():
+                       if instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
+                               instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
+                       else:
+                               pass
+               else:
+                       instandbyon.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
+               self.close()
+
        def keyCancel(self):
-               ConfigListScreen.keyCancel(self)
+               if self["config"].isChanged():
+                       self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
+               else:
+                       if instandbyon.fanoffmode == 'ON' and self.isRecording() and instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
+                               instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
+                       self.close()
 
 def main(session, **kwargs):
        session.open(ManualFancontrol)