9 from enigma import eTimer, eSize
12 from Components.config import configfile, config, ConfigSubsection, ConfigNumber, ConfigInteger, ConfigSlider, ConfigSelection, ConfigYesNo, ConfigText
13 from Components.config import getConfigListEntry
14 from Components.Label import Label
15 from Components.Sources.StaticText import StaticText
16 from Components.Sources.Progress import Progress
18 # Startup/shutdown notification
19 from Tools import Notifications
20 from Sensors import sensors
21 from time import gmtime, strftime
25 from Plugins.Plugin import PluginDescriptor
28 from Screens.Screen import Screen
29 from Components.ConfigList import ConfigListScreen
30 from Screens.MessageBox import MessageBox
31 from Screens.Console import Console
32 from Screens import Standby
33 from Screens.MessageBox import MessageBox
34 from Screens.Standby import TryQuitMainloop
37 from Components.ActionMap import ActionMap
38 from Components.ActionMap import NumberActionMap
39 from Components.Harddisk import harddiskmanager
41 def main(session,**kwargs):
43 session.open(FanControl2Plugin)
45 FClog("Pluginexecution failed")
47 def mainMonitor(session,**kwargs):
49 session.open(FanControl2Monitor)
51 FClog("Pluginexecution failed")
54 return (1 if wert<=0 else wert)
56 def skal(x, x1, x2, y1, y2):
59 m = (y2 - y1) / Test0(x2 - x1)
64 print "[FanControl2]",wert
65 while len(FC2Log) > config.plugins.FanControl.LogCount.value:
67 FC2Log.append(strftime("%H:%M:%S ") + wert)
68 if config.plugins.FanControl.EnableEventLog.value:
69 if Free(config.plugins.FanControl.LogPath.value):
71 f = open(config.plugins.FanControl.LogPath.value + "FC2events.txt","a")
73 f.write(strftime("%H:%M:%S ") + wert + "\r\n")
77 FC2Log.append(strftime("%H:%M:%S ") + "Event-Log-Error")
81 if strftime("%M")!=DataMinute and config.plugins.FanControl.EnableDataLog.value:
82 DataMinute = strftime("%M")
83 if Free(config.plugins.FanControl.LogPath.value):
85 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","a")
87 f.write(strftime("%Y.%m.%d %H:%M"))
88 for count in range(6):
89 f.write(";" + str(FC2werte[count]).replace(".",_(".")))
90 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
91 tempcount = len(templist)
92 for count in range(tempcount):
93 f.write(";" + str(sensors.getSensorValue(count)))
98 FC2Log.append(strftime("%H:%M:%S ") + "Event-Log-Error")
101 if not os.path.exists(dir):
104 return (s.f_bsize * s.f_bavail / 1024 / 1024) > 10
106 def getVoltage(fanid):
107 f = open("/proc/stb/fp/fan_vlt", "r")
108 value = int(f.readline().strip(), 16)
112 def setVoltage(fanid, value):
115 f = open("/proc/stb/fp/fan_vlt", "w")
116 f.write("%x" % value)
120 f = open("/proc/stb/fp/fan_pwm", "r")
121 value = int(f.readline().strip(), 16)
125 def setPWM(fanid, value):
128 f = open("/proc/stb/fp/fan_pwm", "w")
129 f.write("%x" % value)
133 config.plugins.FanControl = ConfigSubsection()
134 config.plugins.FanControl.Fan = ConfigSelection(choices = [("disabled", _("disabled")), ("aus", _("Control disabled")), ("3pin", _("3Pin")), ("4pin", _("4Pin"))], default = "disabled")
135 config.plugins.FanControl.StandbyOff = ConfigSelection(choices = [("false", _("no")), ("true", _("yes")), ("trueRec", _("yes, Except for Recording or HDD"))], default="false")
136 config.plugins.FanControl.minRPM = ConfigSlider(default = 500, increment = 50, limits = (0, 1000))
137 config.plugins.FanControl.maxRPM = ConfigSlider(default = 3000, increment = 50, limits = (500, 6000))
138 config.plugins.FanControl.temp = ConfigSlider(default = 40, increment = 1, limits = (30, 50))
139 config.plugins.FanControl.tempmax = ConfigSlider(default = 50, increment = 1, limits = (35, 55))
140 config.plugins.FanControl.pwm = ConfigSlider(default = 130, increment = 5, limits = (0, 255))
141 config.plugins.FanControl.vlt = ConfigSlider(default = 255, increment = 5, limits = (0, 255))
142 config.plugins.FanControl.ShowError = ConfigSelection(choices = [("false", _("do nothing")), ("true", _("display Info")), ("shutdown", _("Box Shutdown"))], default="true")
143 config.plugins.FanControl.ShutdownTemp = ConfigInteger(default = 65,limits = (50, 80))
144 config.plugins.FanControl.AddOverheat = ConfigInteger(default = 0,limits = (0, 9))
145 config.plugins.FanControl.DisableDMM = ConfigYesNo(default = False)
146 config.plugins.FanControl.LogCount = ConfigInteger(default = 40,limits = (40, 999))
147 config.plugins.FanControl.LogPath = ConfigText(default="/tmp/", fixed_size=False)
148 config.plugins.FanControl.DeleteData = ConfigSelection(choices = [("0", _("no")), ("2", "2"), ("3", "3"), ("7", "7"), ("14", "14"), ("30", "30")], default="0")
149 config.plugins.FanControl.EnableDataLog = ConfigYesNo(default = False)
150 config.plugins.FanControl.EnableEventLog = ConfigYesNo(default = False)
151 config.plugins.FanControl.CheckHDDTemp = ConfigSelection(choices = [("false", _("no")), ("true", _("yes")), ("auto", _("auto")), ("never", _("never"))], default="auto")
152 config.plugins.FanControl.MonitorInExtension = ConfigYesNo(default = True)
153 config.plugins.FanControl.Multi = ConfigSelection(choices = [(1, "RPM"), (2, "RPM/2")], default = 2)
157 f = open("/proc/stb/fp/fan_speed", "r")
158 value = int(f.readline().strip()[:-4])
164 value = int(value / config.plugins.FanControl.Multi.value)
169 if os.path.exists("/proc/stb/info/model"):
170 f = open("/proc/stb/info/model")
177 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
178 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
181 if text.find("#Disabled by FC2 config.misc.standbyCounter.addNotifier") is not -1:
186 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
187 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
190 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "w")
191 text=text.replace("config.misc.standbyCounter.addNotifier","#Disabled by FC2 config.misc.standbyCounter.addNotifier")
192 text=FCfile.write(text)
194 FClog("DMM-fancontrol disabled - please restart E2")
197 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
198 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
201 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "w")
202 text=text.replace("#Disabled by FC2 config.misc.standbyCounter.addNotifier","config.misc.standbyCounter.addNotifier")
203 text=FCfile.write(text)
206 class FanControl2Test(ConfigListScreen,Screen):
208 <screen position="center,center" size="630,300" title="Fan Control 2 - Test" >
209 <widget source="TextTest1" render="Label" position="5,20" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
210 <widget source="TextTest2" render="Label" position="5,50" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
211 <widget source="TextTest3" render="Label" position="5,80" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
212 <widget source="TextTest4" render="Label" position="5,130" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
213 <widget source="TextTest5" render="Label" position="5,160" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
214 <widget source="TextTest6" render="Label" position="5,190" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
215 <widget source="TextTest7" render="Label" position="5,220" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
219 def __init__(self, session, args = 0):
220 self.session = session
221 Screen.__init__(self, session)
223 self.timer = eTimer()
224 self.timer.callback.append(self.DoTest)
225 self.timer.start(1000, True)
227 self["TextTest1"] = StaticText()
228 self["TextTest2"] = StaticText()
229 self["TextTest3"] = StaticText()
230 self["TextTest4"] = StaticText()
231 self["TextTest5"] = StaticText()
232 self["TextTest6"] = StaticText()
233 self["TextTest7"] = StaticText()
235 self["TextTest1"].setText(_("please wait (until 3min)..."))
237 self["actions"] = ActionMap(["OkCancelActions"],
240 "cancel": self.cancel
244 while GetFanRPM() < 100 and self.i < 255:
245 setVoltage(self.id,self.i)
250 while GetFanRPM() > 100 and self.i > 0:
251 setVoltage(self.id,self.i)
262 SaveFan = config.plugins.FanControl.Fan.value
263 config.plugins.FanControl.Fan.value = "aus"
264 if SaveFan == "4pin":
267 while GetFanRPM() < 100 and self.i < 255:
268 setPWM(self.id,self.i)
272 self.last=GetFanRPM()
273 self["TextTest1"].setText(_("Min Fan Start %d rpm at PWM=%d") % (self.last, self.i))
274 while GetFanRPM() > 100 and self.i > 1:
275 setPWM(self.id,self.i)
278 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else (("!!>%d" % config.plugins.FanControl.minRPM.value)))
279 self["TextTest2"].setText(_("Min Fan Stop %d rpm at PWM=%d (%s)") % (self.last, self.i, ok))
283 self.rpm = GetFanRPM()
284 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= self.rpm else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
285 self["TextTest3"].setText(_("Max Fan %d rpm at PWM=255 (%s)") % (self.rpm, ok))
287 self["TextTest4"].setText(_("Extended Control Range"))
290 self.rpm = GetFanRPM()
292 setVoltage(self.id,0)
296 self.last=GetFanRPM()
297 self["TextTest5"].setText(_("Min Fan Start %d rpm at VLT=%d and PWM=0") % (self.last, self.i))
299 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else (("!!>%d" % config.plugins.FanControl.minRPM.value)))
300 self["TextTest6"].setText(_("Min Fan Stop %d rpm at VLT=%d and PWM=0 (%s)") % (self.last, self.i, ok))
303 setVoltage(self.id,255)
305 self.rpm = GetFanRPM()
306 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= self.rpm else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
307 self["TextTest7"].setText(_("Max Fan %d rpm at PWM=255 and VLT=255 (%s)") % (self.rpm, ok))
309 if SaveFan == "3pin":
310 setVoltage(self.id,0)
314 self.last=GetFanRPM()
315 self["TextTest1"].setText(_("Min Fan Start %d rpm at VLT=%d") % (self.last, self.i))
317 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else ("!!>%d" % (config.plugins.FanControl.minRPM.value)))
318 self["TextTest2"].setText(_("Min Fan Stop %d rpm at VLT=%d (%s)") % (self.last, self.i, ok))
320 setVoltage(self.id,255)
322 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= GetFanRPM() else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
323 self["TextTest3"].setText(_("Max Fan %d rpm at VLT=255 (%s)") % (GetFanRPM(), ok))
325 setVoltage(self.id,SaveAktVLT)
326 setPWM(self.id,SaveAktPWM)
327 config.plugins.FanControl.Fan.value = SaveFan
330 self.close(False,self.session)
332 class FanControl2Monitor(Screen, ConfigListScreen):
334 <screen position="center,center" size="600,260" title="Fan Control 2 - Monitor">
336 <widget source="TxtTemp0" render="Label" position="5,30" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
337 <widget source="TxtTemp1" render="Label" position="5,50" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
338 <widget source="TxtTemp2" render="Label" position="5,70" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
339 <widget source="TxtTemp3" render="Label" position="5,90" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
340 <widget source="TxtTemp4" render="Label" position="5,110" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
341 <widget source="TxtTemp5" render="Label" position="5,130" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
342 <widget source="TxtTemp6" render="Label" position="5,150" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
343 <widget source="TxtTemp7" render="Label" position="5,170" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
344 <widget source="TxtHDD" render="Label" position="5,190" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
345 <widget source="TxtFan" render="Label" position="5,210" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
346 <widget name="TxtMinTemp" position="260,20" size="50,12" zPosition="1" font="Regular;12" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
347 <widget source="TxtFC2Temp" render="Label" position="398,20" size="50,12" zPosition="1" font="Regular;17" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
348 <widget name="TxtMaxTemp" position="535,20" size="50,12" zPosition="1" font="Regular;12" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
349 <widget source="ProTemp0" render="Progress" position="260,40" size="325,5" borderWidth="1" />
350 <widget source="ProTemp1" render="Progress" position="260,60" size="325,5" borderWidth="1" />
351 <widget source="ProTemp2" render="Progress" position="260,80" size="325,5" borderWidth="1" />
352 <widget source="ProTemp3" render="Progress" position="260,100" size="325,5" borderWidth="1" />
353 <widget source="ProTemp4" render="Progress" position="260,120" size="325,5" borderWidth="1" />
354 <widget source="ProTemp5" render="Progress" position="260,140" size="325,5" borderWidth="1" />
355 <widget source="ProTemp6" render="Progress" position="260,160" size="325,5" borderWidth="1" />
356 <widget source="ProTemp7" render="Progress" position="260,180" size="325,5" borderWidth="1" />
357 <widget source="ProHDD" render="Progress" position="260,200" size="325,5" borderWidth="1" />
358 <widget source="ProFan" render="Progress" position="260,220" size="325,5" borderWidth="1" />
362 def __init__(self, session, args = None):
363 Screen.__init__(self, session)
365 self.temp_timer = eTimer()
366 self.temp_timer.callback.append(self.updateTemp)
368 for count in range(8):
369 self["ProTemp%d" % count] = Progress()
370 self["TxtTemp%d" % count] = StaticText("")
371 self["ProHDD"] = Progress()
372 self["TxtHDD"] = StaticText("")
373 self["ProFan"] = Progress()
374 self["TxtFan"] = StaticText("")
375 self["TxtFC2Temp"] = StaticText("")
376 self["TxtMinTemp"] = Label("30")
377 self["TxtMaxTemp"] = Label("55")
379 self["actions"] = ActionMap(["OkCancelActions", "EPGSelectActions"],
382 "cancel": self.cancel,
386 self.onLayoutFinish.append(self.updateTemp)
388 def updateTemp(self):
389 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
390 tempcount = len(templist)
391 for count in range(tempcount):
392 tt = sensors.getSensorValue(count)
393 self["ProTemp%d" % count].value = int((tt-30)*100/(55-30))
394 if sensors.getSensorName(count) == "undefined":
395 self["TxtTemp%d" % count].setText(_("%s %02d C") % (TempName[count], tt))
397 self["TxtTemp%d" % count].setText(_("%s %02d C") % (sensors.getSensorName(count), tt))
398 if harddiskmanager.HDDCount() > 0:
400 self["ProHDD"].value = int((max(AktHDD)-30)*100/(55-30))
401 self["TxtHDD"].setText(_("%s %02d C") % ("HDD", max(AktHDD)))
402 elif config.plugins.FanControl.CheckHDDTemp.value !="never":
403 self["TxtHDD"].setText(_("press Info for HDD-Temp"))
404 self["TxtFan"].setText(_("Current rpm %4d") % (AktRPM))
405 self["ProFan"].value = int((AktRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
407 self["TxtFC2Temp"].setText("%4.1f" % AktTemp)
408 self.temp_timer.start(2000, True)
411 self.close(False,self.session)
414 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value !="never":
416 for hdd in harddiskmanager.HDDList():
417 if hdd[1].isSleeping():
418 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
420 class FanControl2SpezialSetup(Screen, ConfigListScreen):
422 <screen position="center,center" size="600,320" title="Fan Control 2 - Setup" >
423 <widget name="config" position="10,20" size="580,290" scrollbarMode="showOnDemand" />
426 def __init__(self, session, args = None):
427 Screen.__init__(self, session)
429 config.plugins.FanControl.DisableDMM.value = isDMMdisabled()
430 self.HDDmode = config.plugins.FanControl.CheckHDDTemp.value
431 self.MonitorMode = config.plugins.FanControl.MonitorInExtension.value
434 self.list.append(getConfigListEntry(_("Action in case of Fan failure"), config.plugins.FanControl.ShowError))
435 self.list.append(getConfigListEntry(_("Box shutdown at Temperature (C)"), config.plugins.FanControl.ShutdownTemp))
436 self.list.append(getConfigListEntry(_("increases overheating protection to (C)"), config.plugins.FanControl.AddOverheat))
437 self.list.append(getConfigListEntry(_("read HDD-Temperature in HDD-Standby-Mode"), config.plugins.FanControl.CheckHDDTemp))
438 self.list.append(getConfigListEntry(_("disable DMM-FanControl"), config.plugins.FanControl.DisableDMM))
439 self.list.append(getConfigListEntry(_("Show Monitor in Extension-Menu"), config.plugins.FanControl.MonitorInExtension))
440 self.list.append(getConfigListEntry(_("Number of WebIF-Log-Entries"), config.plugins.FanControl.LogCount))
441 self.list.append(getConfigListEntry(_("Logging path"), config.plugins.FanControl.LogPath))
442 self.list.append(getConfigListEntry(_("Enable Data Logging"), config.plugins.FanControl.EnableDataLog))
443 self.list.append(getConfigListEntry(_("Auto-Delete Data older than (Days)"), config.plugins.FanControl.DeleteData))
444 self.list.append(getConfigListEntry(_("Enable Event Logging"), config.plugins.FanControl.EnableEventLog))
445 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
447 self["actions"] = ActionMap(["OkCancelActions"],
450 "cancel": self.cancel
454 ConfigListScreen.keyOK(self)
456 from Screens.LocationBox import LocationBox
457 sel = self["config"].getCurrent()[1]
458 if sel == config.plugins.FanControl.LogPath:
459 self.session.openWithCallback(self.dirSelected, LocationBox, text = _("Choose path"), filename = "", currDir = self["config"].getCurrent()[1].value, minFree = 50)
461 self.session.open(MessageBox, "Error:\n" + str(e), MessageBox.TYPE_ERROR)
463 def dirSelected(self, dir):
464 if dir is not None and dir != "?":
467 config.plugins.FanControl.LogPath.value = dir
470 global disableHDDread
471 if config.plugins.FanControl.LogPath.value[-1:] != "/":
472 config.plugins.FanControl.LogPath.value += "/"
474 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
475 if not isDMMdisabled() and config.plugins.FanControl.DisableDMM.value:
478 if isDMMdisabled() and not config.plugins.FanControl.DisableDMM.value:
481 if config.plugins.FanControl.CheckHDDTemp.value == "auto" and config.plugins.FanControl.CheckHDDTemp.value != self.HDDmode:
482 disableHDDread = True
483 if config.plugins.FanControl.MonitorInExtension.value != self.MonitorMode:
486 for x in self["config"].list:
491 restartbox = self.session.openWithCallback(self.restartGUI,MessageBox,_("GUI needs a restart to apply the changes.\nDo you want to Restart the GUI now?"), MessageBox.TYPE_YESNO)
492 restartbox.setTitle(_("Restart GUI now?"))
494 self.close(False,self.session)
496 def selectionChanged(self):
497 if not config.plugins.FanControl.EnableDataLog.value:
499 if config.plugins.FanControl.LogPath.value[-1:] != "/":
500 config.plugins.FanControl.LogPath.value += "/"
501 if not os.path.exists(config.plugins.FanControl.LogPath.value + "FC2data.csv") and Free(config.plugins.FanControl.LogPath.value):
503 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","w")
509 FClog("Data-Log-Error")
511 def restartGUI(self, answer):
513 self.session.open(TryQuitMainloop, 3)
517 class FanControl2Plugin(ConfigListScreen,Screen):
519 <screen position="center,center" size="600,440" title="Fan Control 2">
520 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
521 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
522 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
523 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
524 <ePixmap pixmap="skin_default/buttons/key_info.png" position="560,0" zPosition="4" size="35,25" transparent="1" alphatest="on" />
525 <ePixmap pixmap="skin_default/buttons/key_menu.png" position="560,20" zPosition="4" size="35,25" transparent="1" alphatest="on" />
526 <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
527 <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
528 <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
529 <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
530 <widget source="Version" render="Label" position="5,420" size="60,20" zPosition="1" font="Regular;11" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
532 <widget name="config" position="10,50" size="580,200" scrollbarMode="showOnDemand" />
533 <ePixmap position="20,260" size="560,3" pixmap="skin_default/div-h.png" transparent="1" alphatest="on" />
534 <widget source="introduction" render="Label" position="5,262" size="580,30" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
535 <ePixmap position="20,290" size="560,3" pixmap="skin_default/div-h.png" transparent="1" alphatest="on" />
536 <widget source="TxtTemp" render="Label" position="5,330" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
537 <widget source="TxtZielRPM" render="Label" position="5,350" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
538 <widget source="TxtRPM" render="Label" position="5,370" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
539 <widget source="TxtVLT" render="Label" position="5,390" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
540 <widget source="TxtPWM" render="Label" position="5,410" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
541 <widget source="PixTemp" render="Progress" position="210,340" size="375,5" borderWidth="1" />
542 <widget source="PixZielRPM" render="Progress" position="210,360" size="375,5" borderWidth="1" />
543 <widget source="PixRPM" render="Progress" position="210,380" size="375,5" borderWidth="1" />
544 <widget source="PixVLT" render="Progress" position="210,400" size="375,5" borderWidth="1" />
545 <widget source="PixPWM" render="Progress" position="210,420" size="375,5" borderWidth="1" />
548 def __init__(self, session, args = 0):
551 self.session = session
552 Screen.__init__(self, session)
554 self.fan_timer = eTimer()
555 self.fan_timer.callback.append(self.updateFanStatus)
558 self.list.append(getConfigListEntry(_("Fan type"), config.plugins.FanControl.Fan))
559 self.list.append(getConfigListEntry(_("Fan off in Standby"), config.plugins.FanControl.StandbyOff))
560 self.list.append(getConfigListEntry(_("min Speed rpm"), config.plugins.FanControl.minRPM))
561 self.list.append(getConfigListEntry(_("max Speed rpm"), config.plugins.FanControl.maxRPM))
562 self.list.append(getConfigListEntry(_("Static temp C"), config.plugins.FanControl.temp))
563 self.list.append(getConfigListEntry(_("End temperature C"), config.plugins.FanControl.tempmax))
564 self.list.append(getConfigListEntry(_("Initial Voltage"), config.plugins.FanControl.vlt))
565 self.list.append(getConfigListEntry(_("Initial PWM"), config.plugins.FanControl.pwm))
566 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
567 LastVLT = config.plugins.FanControl.vlt.value
568 LastPWM = config.plugins.FanControl.pwm.value
570 self["red"] = StaticText(_("Cancel"))
571 self["green"] = StaticText(_("Save"))
572 self["yellow"] = StaticText(_("Check"))
573 self["blue"] = StaticText(_("Help"))
574 self["introduction"] = StaticText()
575 self["Version"] = StaticText(Version)
576 self["TxtTemp"] = StaticText()
577 self["TxtZielRPM"] = StaticText()
578 self["TxtRPM"] = StaticText()
579 self["TxtVLT"] = StaticText()
580 self["TxtPWM"] = StaticText()
581 self["PixTemp"] = Progress()
582 self["PixZielRPM"] = Progress()
583 self["PixRPM"] = Progress()
584 self["PixVLT"] = Progress()
585 self["PixPWM"] = Progress()
587 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "MenuActions", "EPGSelectActions"],
590 "cancel": self.cancel,
593 "yellow": self.pruefen,
595 "menu": self.SetupMenu,
599 if not self.selectionChanged in self["config"].onSelectionChanged:
600 self["config"].onSelectionChanged.append(self.selectionChanged)
601 self.selectionChanged()
602 self.onLayoutFinish.append(self.updateFanStatus)
604 def selectionChanged(self):
610 self["introduction"].setText(_("Current value: %s") % (self.getCurrentValue()))
611 if self["config"].getCurrentIndex() > 4:
612 if LastVLT != config.plugins.FanControl.vlt.value or LastPWM !=config.plugins.FanControl.pwm.value:
613 LastVLT = config.plugins.FanControl.vlt.value
614 LastPWM = config.plugins.FanControl.pwm.value
618 setVoltage(id,LastVLT)
621 d = config.plugins.FanControl.tempmax.value - config.plugins.FanControl.temp.value
623 if config.plugins.FanControl.temp.value + d < 55:
624 config.plugins.FanControl.tempmax.value=config.plugins.FanControl.temp.value+5
626 config.plugins.FanControl.temp.value=config.plugins.FanControl.tempmax.value-5
628 def getCurrentValue(self):
629 return str(self["config"].getCurrent()[1].getText())
631 def updateFanStatus(self):
637 if config.plugins.FanControl.Fan.value == "disabled":
643 self["TxtTemp"].setText(_("Temperature C %4.1f") % (AktTemp))
644 self["TxtZielRPM"].setText(_("Target rpm %4d") % (ZielRPM))
645 self["TxtRPM"].setText(_("Current rpm %4d") % (AktRPM))
646 self["TxtVLT"].setText(_("Voltage %03d") % (AktVLT))
647 self["TxtPWM"].setText(_("PWM %03d") % (AktPWM))
648 self["PixTemp"].value = int((AktTemp-config.plugins.FanControl.temp.value)*100/Test0(config.plugins.FanControl.tempmax.value-config.plugins.FanControl.temp.value))
649 self["PixZielRPM"].value = int((ZielRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
650 self["PixRPM"].value = int((AktRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
651 self["PixVLT"].value = int(AktVLT/2.55)
652 self["PixPWM"].value = int(AktPWM/2.55)
653 self.fan_timer.start(2000, True)
656 for x in self["config"].list:
658 self.close(True,self.session)
661 for x in self["config"].list:
663 self.close(False,self.session)
666 self.session.open(FanControl2Test)
669 self.session.open(FanControl2Monitor)
672 self.session.open(Console,_("Information"),["cat /usr/lib/enigma2/python/Plugins/Extensions/FanControl2/%s" % _("readme.txt")])
675 self.session.open(FanControl2SpezialSetup)
678 if config.plugins.FanControl.DeleteData.value == "0" or config.plugins.FanControl.EnableDataLog.value == False:
681 FClog("Auto-Delete Data")
682 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","a")
687 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","r")
692 DT = DT[0].split(" ")
693 DD = DT[0].split(".")
694 DD48h = datetime.date(int(DD[0]),int(DD[1]),int(DD[2])) - datetime.timedelta(int(config.plugins.FanControl.DeleteData.value))
695 Dfind = "%04d.%02d.%02d %s" % (DD48h.year,DD48h.month,DD48h.day,DT[1])
698 fw = open(config.plugins.FanControl.LogPath.value + "FC2data.csv.tmp","w")
700 for line in f.readlines():
706 if os.path.exists(config.plugins.FanControl.LogPath.value + "FC2data.csv"):
707 os.remove(config.plugins.FanControl.LogPath.value + "FC2data.csv")
708 os.rename(config.plugins.FanControl.LogPath.value + "FC2data.csv.tmp",config.plugins.FanControl.LogPath.value + "FC2data.csv")
710 FClog("Error Delete Data")
712 def getstatusoutput(cmd):
713 pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
716 if sts is None: sts = 0
717 if text[-1:] == '\n': text = text[:-1]
721 global disableHDDread
722 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value !="never":
723 disableHDDread = False
724 for hdd in harddiskmanager.HDDList():
725 FClog("%s %s Mode:%s" % (hdd[1].model(), hdd[1].getDeviceName(), config.plugins.FanControl.CheckHDDTemp.value))
726 if config.plugins.FanControl.CheckHDDTemp.value == "auto":
727 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
729 (stat,wert)=ReadHDDtemp(hdd[1].getDeviceName())
731 (stat,wert)=getstatusoutput("smartctl --smart=on %s" % hdd[1].getDeviceName())
732 FClog("HDD Temperature not readable")
734 (stat,wert)=getstatusoutput("hdparm -C %s" % hdd[1].getDeviceName())
735 if wert.find("standby")>0:
736 FClog("HDD supports Temp reading without Spinup")
738 if hdd[1].isSleeping():
739 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
740 FClog("HDD not supports Temp reading without Spinup -> Disabled")
741 disableHDDread = True
744 return getstatusoutput("smartctl -A %s | grep \"194 Temp\" | grep Always" % D)
746 def GetHDDtemp(OneTime):
749 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value != "never" or OneTime == True:
750 for hdd in harddiskmanager.HDDList():
751 sleeptime = int((time.time() - hdd[1].last_access))
752 # FClog("HDD Temp reading %s %s %ds %s" % (config.plugins.FanControl.CheckHDDTemp.value, disableHDDread, sleeptime, hdd[1].isSleeping()))
753 if config.plugins.FanControl.CheckHDDTemp.value == "true" or (config.plugins.FanControl.CheckHDDTemp.value == "auto" and not disableHDDread) or ((not hdd[1].isSleeping()) and sleeptime < 120) or OneTime == True:
754 (stat,wert)=ReadHDDtemp(hdd[1].getDeviceName())
757 AktHDD.append(int(wert[wert.find("Always")+6:].replace(" ","").replace("-","")[:2]))
762 FClog("HDD Temp %dC" % (AktHDD[-1]))
768 for hdd in harddiskmanager.HDDList():
769 if not hdd[1].isSleeping():
773 def FC2systemStatus():
775 R = " -" if S>0 else " "
784 class FanControl2(Screen):
785 skin = """ <screen position="100,100" size="300,300" title="FanControl2" > </screen>"""
787 def __init__(self,session):
789 Screen.__init__(self,session)
790 self.session = session
793 self.targetTemp = 50.0
797 self.dontshutdown = False
799 if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class.org"):
800 os.rename("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class.org","/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class")
801 if not isDMMdisabled() and config.plugins.FanControl.DisableDMM.value:
807 self.timer = eTimer()
808 if self.query not in self.timer.callback:
809 self.timer.callback.append(self.query)
810 self.timer.startLongTimer(10)
811 config.misc.standbyCounter.addNotifier(self.standbyQuery, initial_call = False)
813 def FC2AskShutdown(self):
814 if not self.dontshutdown:
815 self.dontshutdown = True
816 self.session.openWithCallback(self.FC2DoShutdown, MessageBox, _("FanControl2 emergency, Box Shutdown now?"),type = MessageBox.TYPE_YESNO,timeout = 60)
818 def FC2DoShutdown(self,retval):
820 if Standby.inTryQuitMainloop == False:
821 self.session.open(Standby.TryQuitMainloop, 1)
825 if self.query in self.timer.callback:
826 self.timer.callback.remove(self.query)
832 ti = [0,0,0,0,0,0,0,0,0,0]
833 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
834 tempcount = len(templist)
835 for count in range(tempcount):
836 tt = sensors.getSensorValue(count)
841 for count in range(tempcount):
842 if m2 < ti[count] and count != mi:
846 return (m1 + m2) / 2.0
849 self.Range = self.maxTemp - self.targetTemp
850 x = AktTemp - self.targetTemp
851 rpm = skal(x, 0, self.Range, self.FanMin, self.FanMax)
854 def standbyQuery(self, configElement):
855 Standby.inStandby.onClose.append(self.query)
860 global istStandbySave
875 if config.plugins.FanControl.Fan.value == "disabled":
876 self.timer.startLongTimer(10)
878 self.targetTemp = config.plugins.FanControl.temp.value
879 self.maxTemp = config.plugins.FanControl.tempmax.value
880 self.Fan = config.plugins.FanControl.Fan.value
881 self.Vlt = config.plugins.FanControl.vlt.value
886 AktTemp = self.CurrTemp()
887 Recording = self.session.nav.RecordTimer.isRecording()
888 if AktTemp >= config.plugins.FanControl.ShutdownTemp.value:
889 FClog("Emergency Shutdown")
890 self.FC2AskShutdown()
891 if harddiskmanager.HDDCount() > 0:
892 self.HDDidle = HDDsSleeping()
893 if int(strftime("%S")) < 10 and strftime("%M")[-1:] == "0":
895 if strftime("%H:%M") == "00:00":
898 if not Standby.inStandby:
906 if (Standby.inStandby) and (not Overheat) and ((config.plugins.FanControl.StandbyOff.value == "true") or ((config.plugins.FanControl.StandbyOff.value == "trueRec") and (not Recording and self.HDDidle))):
907 FClog("Fan Off Temp: %d %s" % (AktTemp,FC2systemStatus()))
910 FC2werte[0] = AktTemp
914 # FC2werte[4] = str(AktHDD)[1:-1].replace(",","")
915 FC2werte[4] = max(AktHDD) if len(AktHDD) > 0 else 0
918 OverheatTemp = self.maxTemp + config.plugins.FanControl.AddOverheat.value
921 if OverheatTemp > 65:
923 if AktTemp > OverheatTemp:
927 if (Overheat and AktTemp < self.maxTemp-3) or not Standby.inStandby:
929 AktVLTtmp = getVoltage(id)
930 if Standby.inStandby and Standby.inStandby == istStandbySave and RPMdiff == 1:
933 if RPMdiff < 150 or tmp < 300 or self.Fan == "3pin":
936 if config.plugins.FanControl.minRPM.value - RPMdiff < 300:
937 RPMdiff = config.plugins.FanControl.minRPM.value - 300
938 FClog("RPM-Range shifted -%drpm" % RPMdiff)
939 if not Standby.inStandby:
941 self.FanMin = config.plugins.FanControl.minRPM.value - RPMdiff
942 self.FanMax = config.plugins.FanControl.maxRPM.value - RPMdiff
943 if Standby.inStandby != istStandbySave or AktVLT != AktVLTtmp:
944 istStandbySave = Standby.inStandby
946 setVoltage(id,AktVLT)
950 if (AktVLT + AktPWM) == 0:
952 if FirstStart == True:
955 setVoltage(id,self.Vlt)
956 setPWM(id,config.plugins.FanControl.pwm.value)
957 AktRPMtmp = GetFanRPM()
958 if RPMread>0 and RPMread<3:
959 self.timer.start(400, True)
964 FClog("Vlt:%d Pwm:%d Fan:%s %s" % (AktVLT,AktPWM,self.Fan,FC2systemStatus()))
965 FC2werte[0] = AktTemp
969 FC2werte[4] = max(AktHDD) if len(AktHDD) > 0 else 0
971 if int(strftime("%M")) == 0:
972 FC2stunde[int(strftime("%H"))] = "%4.1f<BR>%d" % (AktTemp,AktRPM)
974 ZielRPM = self.cycle()
975 if (FanOffWait and OverheatTimer < 30) or (Overheat and OverheatTimer < 60):
976 ZielRPM = self.FanMin
978 FClog("FanStartTimeout set MinRPM (%d)" % (OverheatTimer))
981 FClog(_("currentRPM:%d targetRPM:%d Temp:%4.1f") % (AktRPM,ZielRPM,AktTemp))
982 if ZielRPM > 0 and AktRPM == 0:
987 if config.plugins.FanControl.ShowError.value == "true":
988 Notifications.AddNotification(MessageBox, _("Fan is not working!"), type=MessageBox.TYPE_INFO, timeout=5)
989 if config.plugins.FanControl.ShowError.value == "shutdown":
990 self.FC2AskShutdown()
993 if self.Fan == "4pin":
994 if AktPWM < 255 and AktPWM > 0 and AktVLT != self.Vlt:
995 AktVLT = (AktVLT-1 if AktVLT > self.Vlt else AktVLT+1)
996 setVoltage(id,AktVLT)
997 if AktRPM+29 < ZielRPM:
998 AktPWM = (AktPWM+5 if ZielRPM-AktRPM > 100 else AktPWM+1)
1000 if AktPWM >= 255 and AktVLT < 255:
1002 setVoltage(id,AktVLT)
1003 elif AktRPM-19 > ZielRPM:
1004 AktPWM = (AktPWM-5 if AktRPM-ZielRPM > 100 else AktPWM-1)
1007 if AktPWM < 0 and AktVLT > 5:
1009 setVoltage(id,AktVLT)
1010 if AktVLT > self.Vlt:
1014 elif self.Fan == "3pin":
1015 if AktRPM+29 < ZielRPM:
1016 AktVLT = (AktVLT+5 if ZielRPM-AktRPM > 100 else AktVLT+1)
1017 setVoltage(id,AktVLT)
1018 elif AktRPM-19 > ZielRPM:
1019 AktVLT = (AktVLT-5 if AktRPM-ZielRPM > 100 else AktVLT-1)
1020 setVoltage(id,AktVLT)
1023 FClog("Control Error")
1024 import traceback, sys
1025 traceback.print_exc(file=sys.stdout)
1026 # FClog(str(time.time() - tt ))
1027 self.timer.startLongTimer(10)
1029 def autostart(reason, **kwargs):
1031 from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild
1032 from FC2webSite import FC2web, FC2webLog, FC2webChart
1033 from twisted.web import static
1034 root = static.File("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data")
1036 root.putChild("", FC2web())
1037 root.putChild("log", FC2webLog())
1038 root.putChild("chart", FC2webChart())
1039 addExternalChild( ("fancontrol", root) )
1040 if reason == 0 and kwargs.has_key("session"):
1041 session = kwargs["session"]
1042 session.open(FanControl2)
1044 def Plugins(**kwargs):
1046 PluginDescriptor(name="Fan Control",
1047 description="Fan Control 2",
1048 where = [PluginDescriptor.WHERE_SESSIONSTART,
1049 PluginDescriptor.WHERE_AUTOSTART],
1051 PluginDescriptor(name="Fan Control",
1052 description="Fan Control 2",
1053 where = PluginDescriptor.WHERE_PLUGINMENU,
1054 icon = "plugin.png",
1056 if config.plugins.FanControl.MonitorInExtension.value:
1057 list.append(PluginDescriptor(
1058 name="Fan Control 2 - Monitor",
1059 description="Fan Control 2",
1060 where = PluginDescriptor.WHERE_EXTENSIONSMENU,
1061 icon = "plugin.png",