Merge branch 'vuplus_experimental' of /opt/repository/enigma2 into vuplus_experimental
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / ManualFancontrol / InstandbyOn.py
1 from Components.config import config, ConfigSubList, ConfigSubsection
2 import NavigationInstance
3 from enigma import iRecordableService
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSlider
6 from enigma import eTimer
7
8 config.plugins.simplefancontrols = ConfigSubsection()
9 config.plugins.simplefancontrols.standbymode = ConfigSelection(default = "yes", choices = [
10         ("no", _("no")), ("yes", _("yes"))])
11 config.plugins.simplefancontrols.pwmvalue = ConfigSlider(default = 10, increment = 5, limits = (0, 255))
12
13 class instandbyOn:
14         def __init__(self):
15                 self.fanoffmode = 'OFF'
16                 self.default_pwm_value_onRecordings = 5
17                 config.misc.standbyCounter.addNotifier(self.standbyBegin, initial_call = False)
18                 if config.plugins.simplefancontrols.pwmvalue.value == 0:
19                         self.fanoffmode = 'ON'
20                 self.InitTimer = eTimer()
21                 if self.initConfig not in self.InitTimer.callback:
22                         self.InitTimer.callback.append(self.initConfig)
23                 print "<SimpleFancontrol> init : Timer loop start!!"
24                 self.InitTimer.startLongTimer(3)
25                 print "<SimpleFancontrol> init :  self.fanoffmode : ", self.fanoffmode
26                 print "<SimpleFancontrol> init :  config.plugins.simplefancontrols.pwmvalue.value : ", config.plugins.simplefancontrols.pwmvalue.value
27
28         def initConfig(self):
29                 print "<SimpleFancontrol>Try initConfig..."
30                 if NavigationInstance.instance is None:
31                         self.InitTimer.startLongTimer(1)
32                 else:
33                         if config.plugins.simplefancontrols.pwmvalue.value == 0:
34                                 NavigationInstance.instance.record_event.append(self.getRecordEvent_onFanOFF)
35                                 recordings = NavigationInstance.instance.getRecordings()
36                                 print "<SimpleFancontrol> initConfig :  recordings : ", recordings
37                                 if recordings:
38                                         self.setPWM(self.default_pwm_value_onRecordings)
39                                 else:
40                                         self.setPWM(0)
41                         else:
42                                 self.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
43
44         def standbyBegin(self, configElement):
45                         print "<SimpleFancontrol> standbyBegin : config.plugins.fancontrols.standbymode.value : ", config.plugins.simplefancontrols.standbymode.value
46                         print "<SimpleFancontrol> standbyBegin : self.fanoffmode : ", self.fanoffmode
47                         if config.plugins.simplefancontrols.standbymode.value == "yes" and config.plugins.simplefancontrols.pwmvalue > 0:
48                                 from Screens.Standby import inStandby
49                                 inStandby.onClose.append(self.StandbyEnd)
50                                 NavigationInstance.instance.record_event.append(self.getRecordEvent)
51                                 recordings = NavigationInstance.instance.getRecordings()
52                                 if not recordings:
53                                         self.setPWM(0)
54
55         def StandbyEnd(self):
56                         print "<SimpleFancontrol> Standby End"
57                         NavigationInstance.instance.record_event.remove(self.getRecordEvent)
58                         if self.getPWM() == 0:
59                                 self.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
60
61         def getRecordEvent(self, recservice, event):
62                         recordings = len(NavigationInstance.instance.getRecordings())
63                         print "<SimpleFancontrol> recordings : %d , event : %d" % (recordings,event)
64                         if event == iRecordableService.evEnd:
65                                 print "<SimpleFancontrol> getRecordEvent : evEnd"
66                                 if recordings == 0:
67                                         self.setPWM(0)
68                         elif event == iRecordableService.evStart:
69                                 print "<SimpleFancontrol> getRecordEvent : evStart"
70                                 if self.getPWM() == 0:
71                                         self.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
72
73         def getPWM(self):
74                 f = open("/proc/stb/fp/fan_pwm", "r")
75                 value = int(f.readline().strip(), 16)
76                 f.close()
77                 print "<SimpleFancontrol> getPWM : %d "%value
78                 return value
79
80         def setPWM(self, value):
81                 print "<SimpleFancontrol> setPWM to : %d"%value
82                 f = open("/proc/stb/fp/fan_pwm", "w")
83                 f.write("%x" % value)
84                 f.close()
85
86         def appendRecordEventCallback(self):
87                 print "<SimpleFancontrol> appendRecordEventCallback "
88                 NavigationInstance.instance.record_event.append(self.getRecordEvent_onFanOFF)
89                 recordings = NavigationInstance.instance.getRecordings()
90                 if recordings:
91                         instandbyon.setPWM(self.default_pwm_value_onRecordings)
92
93         def removeRecordEventCallback(self):
94                 print "<SimpleFancontrol> removeRecordEventCallback "
95                 NavigationInstance.instance.record_event.remove(self.getRecordEvent_onFanOFF)
96
97         def getRecordEvent_onFanOFF(self, recservice, event):
98                 recordings = len(NavigationInstance.instance.getRecordings())
99                 print "<SimpleFancontrol_> recordings : %d , event : %d" % (recordings,event)
100                 if event == iRecordableService.evEnd:
101                         print "<SimpleFancontrol_> getRecordEvent : evEnd"
102                         if recordings == 0:
103                                 self.setPWM(0)
104                 elif event == iRecordableService.evStart:
105                         print "<SimpleFancontrol_> getRecordEvent : evStart"
106                         if self.getPWM() == 0:
107                                 self.setPWM(self.default_pwm_value_onRecordings)
108
109 instandbyon = instandbyOn()
110