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, eTimer, iPlayableService, eServiceCenter, iServiceInformation
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSlider
6 from Components.Harddisk import harddiskmanager
7
8 config.plugins.manualfancontrols = ConfigSubsection()
9 config.plugins.manualfancontrols.standbymode = ConfigSelection(default = "yes", choices = [
10         ("no", _("no")), ("yes", _("yes"))])
11 config.plugins.manualfancontrols.pwmvalue = ConfigSlider(default = 10, increment = 5, limits = (0, 255))
12 config.plugins.manualfancontrols.checkperiod = ConfigSelection(default = "10", choices = [
13                 ("5", "5 " + _("seconds")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
14                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
15                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes"))])
16
17 instandbyOn_playingpvr = False
18
19 class instandbyOn:
20         def __init__(self):
21                 self.fanoffmode = 'OFF'
22                 self.minimum_pwm = 5
23                 self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
24                 self.checkStstusTimer = eTimer()
25                 self.checkStstusTimer.callback.append(self.checkStstus)
26                 if config.plugins.manualfancontrols.pwmvalue.value == 0:
27                         self.fanoffmode = 'ON'
28                 if self.fanoffmode == 'ON':
29                         self.checkStatusLoopStart()
30
31                 config.misc.standbyCounter.addNotifier(self.standbyBegin, initial_call = False)
32                 print "<ManualFancontrol> init :  self.fanoffmode : ", self.fanoffmode
33                 print "<ManualFancontrol> init :  config.plugins.manualfancontrols.pwmvalue.value : ", config.plugins.manualfancontrols.pwmvalue.value
34
35         def checkStatusLoopStart(self):
36                 print "<ManualFancontrol> checkStatusLoopStart"
37                 self.checkStstusTimer.start(int(config.plugins.manualfancontrols.checkperiod.value) * 1000)
38
39         def checkStatusLoopStop(self):
40                 print "<ManualFancontrol> checkStatusLoopStop"
41                 self.checkStstusTimer.stop()
42
43         def checkStstus(self):
44                 from Screens.Standby import inStandby
45                 print "<ManualFancontrol> checkStstus, fanoffmode : %s, "%self.fanoffmode,"inStandby : ",inStandby and True or False
46                 if self.fanoffmode is 'ON' : # pwmvalue is '0'
47                         if self.isRecording() or self.isHDDActive():
48                                 self.setPWM(self.minimum_pwm)
49                         else:
50                                 self.setPWM(0)
51                 elif inStandby : # standby mode but pwm > 0
52                         if self.isRecording() or self.isHDDActive():
53                                 self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
54                         else:
55                                 self.setPWM(0)
56                 elif self.getPWM() != config.plugins.manualfancontrols.pwmvalue.value : # normal mode
57                         self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
58
59         def standbyBegin(self, configElement):
60                 print "<ManualFancontrol> Standby Begin"
61                 if config.plugins.manualfancontrols.standbymode.value == "yes" and self.fanoffmode is "OFF":
62                         from Screens.Standby import inStandby
63                         inStandby.onClose.append(self.StandbyEnd)
64                         self.addRecordEventCB()
65                         self.checkStatusLoopStart()
66                         self.checkStstus()
67
68         def StandbyEnd(self):
69                 print "<ManualFancontrol> Standby End"
70                 if self.fanoffmode is "OFF":
71                         self.removeRecordEventCB()
72                         self.checkStatusLoopStop()
73                 self.checkStstus()
74
75         def addRecordEventCB(self):
76                 print "<ManualFancontrol> addRecordEventCB"
77                 if self.getRecordEvent not in NavigationInstance.instance.record_event:
78                         NavigationInstance.instance.record_event.append(self.getRecordEvent)
79
80         def removeRecordEventCB(self):
81                 print "<ManualFancontrol> removeRecordEventCB"
82                 if self.getRecordEvent in NavigationInstance.instance.record_event:
83                         NavigationInstance.instance.record_event.remove(self.getRecordEvent)
84
85         def getRecordEvent(self, recservice, event):
86                 if event == iRecordableService.evEnd or event == iRecordableService.evStart:
87                         self.checkStstus()
88
89         def isRecording(self):
90                 recordings = NavigationInstance.instance.getRecordings()
91                 print "<ManualFancontrol_> recordings : ",len(recordings)
92                 if recordings :
93                         return True
94                 else:
95                         return False
96
97         def isHDDActive(self): # remake certainly
98                 for hdd in harddiskmanager.HDDList():
99                         if not hdd[1].isSleeping():
100                                 print "<ManualFancontrol_> %s is not Sleeping"%hdd[0]
101                                 return True
102                 print "<ManualFancontrol_> All HDDs are Sleeping"
103                 return False
104
105         def getPWM(self):
106                 f = open("/proc/stb/fp/fan_pwm", "r")
107                 value = int(f.readline().strip(), 16)
108                 f.close()
109                 print "<ManualFancontrol> getPWM : %d "%value
110                 return value
111
112         def setPWM(self, value):
113                 print "<ManualFancontrol> setPWM to : %d"%value
114                 f = open("/proc/stb/fp/fan_pwm", "w")
115                 f.write("%x" % value)
116                 f.close()
117
118 instandbyon = instandbyOn()
119