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