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="/media/hdd/", 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)
156 f = open("/proc/stb/fp/fan_speed", "r")
157 value = int(f.readline().strip()[:-4])
163 value = int(value / 2)
168 if os.path.exists("/proc/stb/info/model"):
169 f = open("/proc/stb/info/model")
176 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
177 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
180 if text.find("#Disabled by FC2 config.misc.standbyCounter.addNotifier") is not -1:
185 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
186 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
189 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "w")
190 text=text.replace("config.misc.standbyCounter.addNotifier","#Disabled by FC2 config.misc.standbyCounter.addNotifier")
191 text=FCfile.write(text)
193 FClog("DMM-fancontrol disabled - please restart E2")
196 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
197 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "r")
200 FCfile = open("/usr/lib/enigma2/python/Components/FanControl.py", "w")
201 text=text.replace("#Disabled by FC2 config.misc.standbyCounter.addNotifier","config.misc.standbyCounter.addNotifier")
202 text=FCfile.write(text)
205 class FanControl2Test(ConfigListScreen,Screen):
207 <screen position="center,center" size="630,300" title="Fan Control 2 - Test" >
208 <widget source="TextTest1" render="Label" position="5,20" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
209 <widget source="TextTest2" render="Label" position="5,50" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
210 <widget source="TextTest3" render="Label" position="5,80" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
211 <widget source="TextTest4" render="Label" position="5,130" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
212 <widget source="TextTest5" render="Label" position="5,160" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
213 <widget source="TextTest6" render="Label" position="5,190" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
214 <widget source="TextTest7" render="Label" position="5,220" size="620,30" zPosition="10" font="Regular;20" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
218 def __init__(self, session, args = 0):
219 self.session = session
220 Screen.__init__(self, session)
222 self.timer = eTimer()
223 self.timer.callback.append(self.DoTest)
224 self.timer.start(1000, True)
226 self["TextTest1"] = StaticText()
227 self["TextTest2"] = StaticText()
228 self["TextTest3"] = StaticText()
229 self["TextTest4"] = StaticText()
230 self["TextTest5"] = StaticText()
231 self["TextTest6"] = StaticText()
232 self["TextTest7"] = StaticText()
234 self["TextTest1"].setText(_("please wait (until 3min)..."))
236 self["actions"] = ActionMap(["OkCancelActions"],
239 "cancel": self.cancel
243 while GetFanRPM() < 100 and self.i < 255:
244 setVoltage(self.id,self.i)
249 while GetFanRPM() > 100 and self.i > 0:
250 setVoltage(self.id,self.i)
261 SaveFan = config.plugins.FanControl.Fan.value
262 config.plugins.FanControl.Fan.value = "aus"
263 if SaveFan == "4pin":
266 while GetFanRPM() < 100 and self.i < 255:
267 setPWM(self.id,self.i)
271 self.last=GetFanRPM()
272 self["TextTest1"].setText(_("Min Fan Start %d rpm at PWM=%d") % (self.last, self.i))
273 while GetFanRPM() > 100 and self.i > 1:
274 setPWM(self.id,self.i)
277 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else (("!!>%d" % config.plugins.FanControl.minRPM.value)))
278 self["TextTest2"].setText(_("Min Fan Stop %d rpm at PWM=%d (%s)") % (self.last, self.i, ok))
282 self.rpm = GetFanRPM()
283 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= self.rpm else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
284 self["TextTest3"].setText(_("Max Fan %d rpm at PWM=255 (%s)") % (self.rpm, ok))
286 self["TextTest4"].setText(_("Extended Control Range"))
289 self.rpm = GetFanRPM()
291 setVoltage(self.id,0)
295 self.last=GetFanRPM()
296 self["TextTest5"].setText(_("Min Fan Start %d rpm at VLT=%d and PWM=0") % (self.last, self.i))
298 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else (("!!>%d" % config.plugins.FanControl.minRPM.value)))
299 self["TextTest6"].setText(_("Min Fan Stop %d rpm at VLT=%d and PWM=0 (%s)") % (self.last, self.i, ok))
302 setVoltage(self.id,255)
304 self.rpm = GetFanRPM()
305 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= self.rpm else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
306 self["TextTest7"].setText(_("Max Fan %d rpm at PWM=255 and VLT=255 (%s)") % (self.rpm, ok))
308 if SaveFan == "3pin":
309 setVoltage(self.id,0)
313 self.last=GetFanRPM()
314 self["TextTest1"].setText(_("Min Fan Start %d rpm at VLT=%d") % (self.last, self.i))
316 ok = ("OK" if config.plugins.FanControl.minRPM.value >= self.last else ("!!>%d" % (config.plugins.FanControl.minRPM.value)))
317 self["TextTest2"].setText(_("Min Fan Stop %d rpm at VLT=%d (%s)") % (self.last, self.i, ok))
319 setVoltage(self.id,255)
321 ok = ("OK" if config.plugins.FanControl.maxRPM.value <= GetFanRPM() else ("!!<%d" % (config.plugins.FanControl.maxRPM.value)))
322 self["TextTest3"].setText(_("Max Fan %d rpm at VLT=255 (%s)") % (GetFanRPM(), ok))
324 setVoltage(self.id,SaveAktVLT)
325 setPWM(self.id,SaveAktPWM)
326 config.plugins.FanControl.Fan.value = SaveFan
329 self.close(False,self.session)
331 class FanControl2Monitor(Screen, ConfigListScreen):
333 <screen position="center,center" size="600,260" title="Fan Control 2 - Monitor">
335 <widget source="TxtTemp0" render="Label" position="5,30" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
336 <widget source="TxtTemp1" render="Label" position="5,50" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
337 <widget source="TxtTemp2" render="Label" position="5,70" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
338 <widget source="TxtTemp3" render="Label" position="5,90" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
339 <widget source="TxtTemp4" render="Label" position="5,110" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
340 <widget source="TxtTemp5" render="Label" position="5,130" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
341 <widget source="TxtTemp6" render="Label" position="5,150" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
342 <widget source="TxtTemp7" render="Label" position="5,170" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
343 <widget source="TxtHDD" render="Label" position="5,190" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
344 <widget source="TxtFan" render="Label" position="5,210" size="250,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
345 <widget name="TxtMinTemp" position="260,20" size="50,12" zPosition="1" font="Regular;12" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
346 <widget source="TxtFC2Temp" render="Label" position="398,20" size="50,12" zPosition="1" font="Regular;17" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
347 <widget name="TxtMaxTemp" position="535,20" size="50,12" zPosition="1" font="Regular;12" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
348 <widget source="ProTemp0" render="Progress" position="260,40" size="325,5" borderWidth="1" />
349 <widget source="ProTemp1" render="Progress" position="260,60" size="325,5" borderWidth="1" />
350 <widget source="ProTemp2" render="Progress" position="260,80" size="325,5" borderWidth="1" />
351 <widget source="ProTemp3" render="Progress" position="260,100" size="325,5" borderWidth="1" />
352 <widget source="ProTemp4" render="Progress" position="260,120" size="325,5" borderWidth="1" />
353 <widget source="ProTemp5" render="Progress" position="260,140" size="325,5" borderWidth="1" />
354 <widget source="ProTemp6" render="Progress" position="260,160" size="325,5" borderWidth="1" />
355 <widget source="ProTemp7" render="Progress" position="260,180" size="325,5" borderWidth="1" />
356 <widget source="ProHDD" render="Progress" position="260,200" size="325,5" borderWidth="1" />
357 <widget source="ProFan" render="Progress" position="260,220" size="325,5" borderWidth="1" />
361 def __init__(self, session, args = None):
362 Screen.__init__(self, session)
364 self.temp_timer = eTimer()
365 self.temp_timer.callback.append(self.updateTemp)
367 for count in range(8):
368 self["ProTemp%d" % count] = Progress()
369 self["TxtTemp%d" % count] = StaticText("")
370 self["ProHDD"] = Progress()
371 self["TxtHDD"] = StaticText("")
372 self["ProFan"] = Progress()
373 self["TxtFan"] = StaticText("")
374 self["TxtFC2Temp"] = StaticText("")
375 self["TxtMinTemp"] = Label("30")
376 self["TxtMaxTemp"] = Label("55")
378 self["actions"] = ActionMap(["OkCancelActions", "EPGSelectActions"],
381 "cancel": self.cancel,
385 self.onLayoutFinish.append(self.updateTemp)
387 def updateTemp(self):
388 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
389 tempcount = len(templist)
390 for count in range(tempcount):
391 tt = sensors.getSensorValue(count)
392 self["ProTemp%d" % count].value = int((tt-30)*100/(55-30))
393 if sensors.getSensorName(count) == "undefined":
394 self["TxtTemp%d" % count].setText(_("%s %02d C") % (TempName[count], tt))
396 self["TxtTemp%d" % count].setText(_("%s %02d C") % (sensors.getSensorName(count), tt))
397 if harddiskmanager.HDDCount() > 0:
399 self["ProHDD"].value = int((max(AktHDD)-30)*100/(55-30))
400 self["TxtHDD"].setText(_("%s %02d C") % ("HDD", max(AktHDD)))
401 elif config.plugins.FanControl.CheckHDDTemp.value !="never":
402 self["TxtHDD"].setText(_("press Info for HDD-Temp"))
403 self["TxtFan"].setText(_("Current rpm %4d") % (AktRPM))
404 self["ProFan"].value = int((AktRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
406 self["TxtFC2Temp"].setText("%4.1f" % AktTemp)
407 self.temp_timer.start(2000, True)
410 self.close(False,self.session)
413 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value !="never":
415 for hdd in harddiskmanager.HDDList():
416 if hdd[1].isSleeping():
417 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
419 class FanControl2SpezialSetup(Screen, ConfigListScreen):
421 <screen position="center,center" size="600,320" title="Fan Control 2 - Setup" >
422 <widget name="config" position="10,20" size="580,290" scrollbarMode="showOnDemand" />
425 def __init__(self, session, args = None):
426 Screen.__init__(self, session)
428 config.plugins.FanControl.DisableDMM.value = isDMMdisabled()
429 self.HDDmode = config.plugins.FanControl.CheckHDDTemp.value
430 self.MonitorMode = config.plugins.FanControl.MonitorInExtension.value
433 self.list.append(getConfigListEntry(_("Action in case of Fan failure"), config.plugins.FanControl.ShowError))
434 self.list.append(getConfigListEntry(_("Box shutdown at Temperature (C)"), config.plugins.FanControl.ShutdownTemp))
435 self.list.append(getConfigListEntry(_("increases overheating protection to (C)"), config.plugins.FanControl.AddOverheat))
436 self.list.append(getConfigListEntry(_("read HDD-Temperature in HDD-Standby-Mode"), config.plugins.FanControl.CheckHDDTemp))
437 self.list.append(getConfigListEntry(_("disable DMM-FanControl"), config.plugins.FanControl.DisableDMM))
438 self.list.append(getConfigListEntry(_("Show Monitor in Extension-Menu"), config.plugins.FanControl.MonitorInExtension))
439 self.list.append(getConfigListEntry(_("Number of WebIF-Log-Entries"), config.plugins.FanControl.LogCount))
440 self.list.append(getConfigListEntry(_("Logging path"), config.plugins.FanControl.LogPath))
441 self.list.append(getConfigListEntry(_("Enable Data Logging"), config.plugins.FanControl.EnableDataLog))
442 self.list.append(getConfigListEntry(_("Auto-Delete Data older than (Days)"), config.plugins.FanControl.DeleteData))
443 self.list.append(getConfigListEntry(_("Enable Event Logging"), config.plugins.FanControl.EnableEventLog))
444 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
446 self["actions"] = ActionMap(["OkCancelActions"],
449 "cancel": self.cancel
453 ConfigListScreen.keyOK(self)
455 from Screens.LocationBox import LocationBox
456 sel = self["config"].getCurrent()[1]
457 if sel == config.plugins.FanControl.LogPath:
458 self.session.openWithCallback(self.dirSelected, LocationBox, text = _("Choose path"), filename = "", currDir = self["config"].getCurrent()[1].value, minFree = 50)
460 self.session.open(MessageBox, "Error:\n" + str(e), MessageBox.TYPE_ERROR)
462 def dirSelected(self, dir):
463 if dir is not None and dir != "?":
466 config.plugins.FanControl.LogPath.value = dir
469 global disableHDDread
470 if config.plugins.FanControl.LogPath.value[-1:] != "/":
471 config.plugins.FanControl.LogPath.value += "/"
473 if os.path.exists("/usr/lib/enigma2/python/Components/FanControl.py"):
474 if not isDMMdisabled() and config.plugins.FanControl.DisableDMM.value:
477 if isDMMdisabled() and not config.plugins.FanControl.DisableDMM.value:
480 if config.plugins.FanControl.CheckHDDTemp.value == "auto" and config.plugins.FanControl.CheckHDDTemp.value != self.HDDmode:
481 disableHDDread = True
482 if config.plugins.FanControl.MonitorInExtension.value != self.MonitorMode:
485 for x in self["config"].list:
490 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)
491 restartbox.setTitle(_("Restart GUI now?"))
493 self.close(False,self.session)
495 def selectionChanged(self):
496 if not config.plugins.FanControl.EnableDataLog.value:
498 if config.plugins.FanControl.LogPath.value[-1:] != "/":
499 config.plugins.FanControl.LogPath.value += "/"
500 if not os.path.exists(config.plugins.FanControl.LogPath.value + "FC2data.csv") and Free(config.plugins.FanControl.LogPath.value):
502 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","w")
508 FCLog("Data-Log-Error")
510 def restartGUI(self, answer):
512 self.session.open(TryQuitMainloop, 3)
516 class FanControl2Plugin(ConfigListScreen,Screen):
518 <screen position="center,center" size="600,440" title="Fan Control 2">
519 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
520 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
521 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
522 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
523 <ePixmap pixmap="skin_default/buttons/key_info.png" position="560,0" zPosition="4" size="35,25" transparent="1" alphatest="on" />
524 <ePixmap pixmap="skin_default/buttons/key_menu.png" position="560,20" zPosition="4" size="35,25" transparent="1" alphatest="on" />
525 <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
526 <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
527 <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
528 <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
529 <widget source="Version" render="Label" position="5,420" size="60,20" zPosition="1" font="Regular;11" halign="left" valign="center" backgroundColor="#25062748" transparent="1" />
531 <widget name="config" position="10,50" size="580,200" scrollbarMode="showOnDemand" />
532 <ePixmap position="20,260" size="560,3" pixmap="skin_default/div-h.png" transparent="1" alphatest="on" />
533 <widget source="introduction" render="Label" position="5,262" size="580,30" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
534 <ePixmap position="20,290" size="560,3" pixmap="skin_default/div-h.png" transparent="1" alphatest="on" />
535 <widget source="TxtTemp" render="Label" position="5,330" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
536 <widget source="TxtZielRPM" render="Label" position="5,350" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
537 <widget source="TxtRPM" render="Label" position="5,370" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
538 <widget source="TxtVLT" render="Label" position="5,390" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
539 <widget source="TxtPWM" render="Label" position="5,410" size="200,25" zPosition="1" font="Regular;17" halign="right" valign="center" backgroundColor="#25062748" transparent="1" />
540 <widget source="PixTemp" render="Progress" position="210,340" size="375,5" borderWidth="1" />
541 <widget source="PixZielRPM" render="Progress" position="210,360" size="375,5" borderWidth="1" />
542 <widget source="PixRPM" render="Progress" position="210,380" size="375,5" borderWidth="1" />
543 <widget source="PixVLT" render="Progress" position="210,400" size="375,5" borderWidth="1" />
544 <widget source="PixPWM" render="Progress" position="210,420" size="375,5" borderWidth="1" />
547 def __init__(self, session, args = 0):
550 self.session = session
551 Screen.__init__(self, session)
553 self.fan_timer = eTimer()
554 self.fan_timer.callback.append(self.updateFanStatus)
557 self.list.append(getConfigListEntry(_("Fan type"), config.plugins.FanControl.Fan))
558 self.list.append(getConfigListEntry(_("Fan off in Standby"), config.plugins.FanControl.StandbyOff))
559 self.list.append(getConfigListEntry(_("min Speed rpm"), config.plugins.FanControl.minRPM))
560 self.list.append(getConfigListEntry(_("max Speed rpm"), config.plugins.FanControl.maxRPM))
561 self.list.append(getConfigListEntry(_("Static temp C"), config.plugins.FanControl.temp))
562 self.list.append(getConfigListEntry(_("End temperature C"), config.plugins.FanControl.tempmax))
563 self.list.append(getConfigListEntry(_("Initial Voltage"), config.plugins.FanControl.vlt))
564 self.list.append(getConfigListEntry(_("Initial PWM"), config.plugins.FanControl.pwm))
565 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
566 LastVLT = config.plugins.FanControl.vlt.value
567 LastPWM = config.plugins.FanControl.pwm.value
569 self["red"] = StaticText(_("Cancel"))
570 self["green"] = StaticText(_("Save"))
571 self["yellow"] = StaticText(_("Check"))
572 self["blue"] = StaticText(_("Help"))
573 self["introduction"] = StaticText()
574 self["Version"] = StaticText(Version)
575 self["TxtTemp"] = StaticText()
576 self["TxtZielRPM"] = StaticText()
577 self["TxtRPM"] = StaticText()
578 self["TxtVLT"] = StaticText()
579 self["TxtPWM"] = StaticText()
580 self["PixTemp"] = Progress()
581 self["PixZielRPM"] = Progress()
582 self["PixRPM"] = Progress()
583 self["PixVLT"] = Progress()
584 self["PixPWM"] = Progress()
586 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "MenuActions", "EPGSelectActions"],
589 "cancel": self.cancel,
592 "yellow": self.pruefen,
594 "menu": self.SetupMenu,
598 if not self.selectionChanged in self["config"].onSelectionChanged:
599 self["config"].onSelectionChanged.append(self.selectionChanged)
600 self.selectionChanged()
601 self.onLayoutFinish.append(self.updateFanStatus)
603 def selectionChanged(self):
609 self["introduction"].setText(_("Current value: %s") % (self.getCurrentValue()))
610 if self["config"].getCurrentIndex() > 4:
611 if LastVLT != config.plugins.FanControl.vlt.value or LastPWM !=config.plugins.FanControl.pwm.value:
612 LastVLT = config.plugins.FanControl.vlt.value
613 LastPWM = config.plugins.FanControl.pwm.value
617 setVoltage(id,LastVLT)
620 d = config.plugins.FanControl.tempmax.value - config.plugins.FanControl.temp.value
622 if config.plugins.FanControl.temp.value + d < 55:
623 config.plugins.FanControl.tempmax.value=config.plugins.FanControl.temp.value+5
625 config.plugins.FanControl.temp.value=config.plugins.FanControl.tempmax.value-5
627 def getCurrentValue(self):
628 return str(self["config"].getCurrent()[1].getText())
630 def updateFanStatus(self):
636 if config.plugins.FanControl.Fan.value == "disabled":
642 self["TxtTemp"].setText(_("Temperature C %4.1f") % (AktTemp))
643 self["TxtZielRPM"].setText(_("Target rpm %4d") % (ZielRPM))
644 self["TxtRPM"].setText(_("Current rpm %4d") % (AktRPM))
645 self["TxtVLT"].setText(_("Voltage %03d") % (AktVLT))
646 self["TxtPWM"].setText(_("PWM %03d") % (AktPWM))
647 self["PixTemp"].value = int((AktTemp-config.plugins.FanControl.temp.value)*100/Test0(config.plugins.FanControl.tempmax.value-config.plugins.FanControl.temp.value))
648 self["PixZielRPM"].value = int((ZielRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
649 self["PixRPM"].value = int((AktRPM-config.plugins.FanControl.minRPM.value)*100/Test0(config.plugins.FanControl.maxRPM.value-config.plugins.FanControl.minRPM.value))
650 self["PixVLT"].value = int(AktVLT/2.55)
651 self["PixPWM"].value = int(AktPWM/2.55)
652 self.fan_timer.start(2000, True)
655 for x in self["config"].list:
657 self.close(True,self.session)
660 for x in self["config"].list:
662 self.close(False,self.session)
665 self.session.open(FanControl2Test)
668 self.session.open(FanControl2Monitor)
671 self.session.open(Console,_("Information"),["cat /usr/lib/enigma2/python/Plugins/Extensions/FanControl2/%s" % _("readme.txt")])
674 self.session.open(FanControl2SpezialSetup)
677 if config.plugins.FanControl.DeleteData.value == "0" or config.plugins.FanControl.EnableDataLog.value == False:
680 FClog("Auto-Delete Data")
681 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","a")
686 f = open(config.plugins.FanControl.LogPath.value + "FC2data.csv","r")
691 DT = DT[0].split(" ")
692 DD = DT[0].split(".")
693 DD48h = datetime.date(int(DD[0]),int(DD[1]),int(DD[2])) - datetime.timedelta(int(config.plugins.FanControl.DeleteData.value))
694 Dfind = "%04d.%02d.%02d %s" % (DD48h.year,DD48h.month,DD48h.day,DT[1])
697 fw = open(config.plugins.FanControl.LogPath.value + "FC2data.csv.tmp","w")
699 for line in f.readlines():
705 if os.path.exists(config.plugins.FanControl.LogPath.value + "FC2data.csv"):
706 os.remove(config.plugins.FanControl.LogPath.value + "FC2data.csv")
707 os.rename(config.plugins.FanControl.LogPath.value + "FC2data.csv.tmp",config.plugins.FanControl.LogPath.value + "FC2data.csv")
709 FClog("Error Delete Data")
711 def getstatusoutput(cmd):
712 pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
715 if sts is None: sts = 0
716 if text[-1:] == '\n': text = text[:-1]
720 global disableHDDread
721 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value !="never":
722 disableHDDread = False
723 for hdd in harddiskmanager.HDDList():
724 FClog("%s %s Mode:%s" % (hdd[1].model(), hdd[1].getDeviceName(), config.plugins.FanControl.CheckHDDTemp.value))
725 if config.plugins.FanControl.CheckHDDTemp.value == "auto":
726 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
728 (stat,wert)=ReadHDDtemp(hdd[1].getDeviceName())
730 (stat,wert)=getstatusoutput("smartctl --smart=on %s" % hdd[1].getDeviceName())
731 FClog("HDD Temperature not readable")
733 (stat,wert)=getstatusoutput("hdparm -C %s" % hdd[1].getDeviceName())
734 if wert.find("standby")>0:
735 FClog("HDD supports Temp reading without Spinup")
737 if hdd[1].isSleeping():
738 (stat,wert)=getstatusoutput("hdparm -y %s" % hdd[1].getDeviceName())
739 FClog("HDD not supports Temp reading without Spinup -> Disabled")
740 disableHDDread = True
743 return getstatusoutput("smartctl -A %s | grep \"194 Temp\" | grep Always" % D)
745 def GetHDDtemp(OneTime):
748 if harddiskmanager.HDDCount() > 0 and config.plugins.FanControl.CheckHDDTemp.value != "never" or OneTime == True:
749 for hdd in harddiskmanager.HDDList():
750 sleeptime = int((time.time() - hdd[1].last_access))
751 # FClog("HDD Temp reading %s %s %ds %s" % (config.plugins.FanControl.CheckHDDTemp.value, disableHDDread, sleeptime, hdd[1].isSleeping()))
752 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:
753 (stat,wert)=ReadHDDtemp(hdd[1].getDeviceName())
756 AktHDD.append(int(wert[wert.find("Always")+6:].replace(" ","").replace("-","")[:2]))
761 FClog("HDD Temp %dC" % (AktHDD[-1]))
767 for hdd in harddiskmanager.HDDList():
768 if not hdd[1].isSleeping():
772 def FC2systemStatus():
774 R = " -" if S>0 else " "
783 class FanControl2(Screen):
784 skin = """ <screen position="100,100" size="300,300" title="FanControl2" > </screen>"""
786 def __init__(self,session):
788 Screen.__init__(self,session)
789 self.session = session
792 self.targetTemp = 50.0
796 self.dontshutdown = False
798 if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class.org"):
799 os.rename("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class.org","/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data/diagram.class")
800 if not isDMMdisabled() and config.plugins.FanControl.DisableDMM.value:
806 self.timer = eTimer()
807 if self.query not in self.timer.callback:
808 self.timer.callback.append(self.query)
809 self.timer.startLongTimer(10)
810 config.misc.standbyCounter.addNotifier(self.standbyQuery, initial_call = False)
812 def FC2AskShutdown(self):
813 if not self.dontshutdown:
814 self.dontshutdown = True
815 self.session.openWithCallback(self.FC2DoShutdown, MessageBox, _("FanControl2 emergency, Box Shutdown now?"),type = MessageBox.TYPE_YESNO,timeout = 60)
817 def FC2DoShutdown(self,retval):
819 if Standby.inTryQuitMainloop == False:
820 self.session.open(Standby.TryQuitMainloop, 1)
824 if self.query in self.timer.callback:
825 self.timer.callback.remove(self.query)
831 ti = [0,0,0,0,0,0,0,0,0,0]
832 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
833 tempcount = len(templist)
834 for count in range(tempcount):
835 tt = sensors.getSensorValue(count)
840 for count in range(tempcount):
841 if m2 < ti[count] and count != mi:
845 return (m1 + m2) / 2.0
848 self.Range = self.maxTemp - self.targetTemp
849 x = AktTemp - self.targetTemp
850 rpm = skal(x, 0, self.Range, self.FanMin, self.FanMax)
853 def standbyQuery(self, configElement):
854 Standby.inStandby.onClose.append(self.query)
859 global istStandbySave
874 if config.plugins.FanControl.Fan.value == "disabled":
875 self.timer.startLongTimer(10)
877 self.targetTemp = config.plugins.FanControl.temp.value
878 self.maxTemp = config.plugins.FanControl.tempmax.value
879 self.Fan = config.plugins.FanControl.Fan.value
880 self.Vlt = config.plugins.FanControl.vlt.value
885 AktTemp = self.CurrTemp()
886 Recording = self.session.nav.RecordTimer.isRecording()
887 if AktTemp >= config.plugins.FanControl.ShutdownTemp.value:
888 FClog("Emergency Shutdown")
889 self.FC2AskShutdown()
890 if harddiskmanager.HDDCount() > 0:
891 self.HDDidle = HDDsSleeping()
892 if int(strftime("%S")) < 10 and strftime("%M")[-1:] == "0":
894 if strftime("%H:%M") == "00:00":
897 if not Standby.inStandby:
905 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))):
906 FClog("Fan Off Temp: %d %s" % (AktTemp,FC2systemStatus()))
909 FC2werte[0] = AktTemp
913 # FC2werte[4] = str(AktHDD)[1:-1].replace(",","")
914 FC2werte[4] = max(AktHDD) if len(AktHDD) > 0 else 0
917 OverheatTemp = self.maxTemp + config.plugins.FanControl.AddOverheat.value
920 if OverheatTemp > 65:
922 if AktTemp > OverheatTemp:
926 if (Overheat and AktTemp < self.maxTemp-3) or not Standby.inStandby:
928 AktVLTtmp = getVoltage(id)
929 if Standby.inStandby and Standby.inStandby == istStandbySave and RPMdiff == 1:
932 if RPMdiff < 150 or tmp < 300 or self.Fan == "3pin":
935 if config.plugins.FanControl.minRPM.value - RPMdiff < 300:
936 RPMdiff = config.plugins.FanControl.minRPM.value - 300
937 FClog("RPM-Range shifted -%drpm" % RPMdiff)
938 if not Standby.inStandby:
940 self.FanMin = config.plugins.FanControl.minRPM.value - RPMdiff
941 self.FanMax = config.plugins.FanControl.maxRPM.value - RPMdiff
942 if Standby.inStandby != istStandbySave or AktVLT != AktVLTtmp:
943 istStandbySave = Standby.inStandby
945 setVoltage(id,AktVLT)
949 if (AktVLT + AktPWM) == 0:
951 if FirstStart == True:
954 setVoltage(id,self.Vlt)
955 setPWM(id,config.plugins.FanControl.pwm.value)
956 AktRPMtmp = GetFanRPM()
957 if RPMread>0 and RPMread<3:
958 self.timer.start(400, True)
963 FClog("Vlt:%d Pwm:%d Fan:%s %s" % (AktVLT,AktPWM,self.Fan,FC2systemStatus()))
964 FC2werte[0] = AktTemp
968 FC2werte[4] = max(AktHDD) if len(AktHDD) > 0 else 0
970 if int(strftime("%M")) == 0:
971 FC2stunde[int(strftime("%H"))] = "%4.1f<BR>%d" % (AktTemp,AktRPM)
973 ZielRPM = self.cycle()
974 if (FanOffWait and OverheatTimer < 30) or (Overheat and OverheatTimer < 60):
975 ZielRPM = self.FanMin
977 FClog("FanStartTimeout set MinRPM (%d)" % (OverheatTimer))
980 FClog(_("currentRPM:%d targetRPM:%d Temp:%4.1f") % (AktRPM,ZielRPM,AktTemp))
981 if ZielRPM > 0 and AktRPM == 0:
986 if config.plugins.FanControl.ShowError.value == "true":
987 Notifications.AddNotification(MessageBox, _("Fan is not working!"), type=MessageBox.TYPE_INFO, timeout=5)
988 if config.plugins.FanControl.ShowError.value == "shutdown":
989 self.FC2AskShutdown()
992 if self.Fan == "4pin":
993 if AktPWM < 255 and AktPWM > 0 and AktVLT != self.Vlt:
994 AktVLT = (AktVLT-1 if AktVLT > self.Vlt else AktVLT+1)
995 setVoltage(id,AktVLT)
996 if AktRPM+29 < ZielRPM:
997 AktPWM = (AktPWM+5 if ZielRPM-AktRPM > 100 else AktPWM+1)
999 if AktPWM >= 255 and AktVLT < 255:
1001 setVoltage(id,AktVLT)
1002 elif AktRPM-19 > ZielRPM:
1003 AktPWM = (AktPWM-5 if AktRPM-ZielRPM > 100 else AktPWM-1)
1006 if AktPWM < 0 and AktVLT > 5:
1008 setVoltage(id,AktVLT)
1009 if AktVLT > self.Vlt:
1013 elif self.Fan == "3pin":
1014 if AktRPM+29 < ZielRPM:
1015 AktVLT = (AktVLT+5 if ZielRPM-AktRPM > 100 else AktVLT+1)
1016 setVoltage(id,AktVLT)
1017 elif AktRPM-19 > ZielRPM:
1018 AktVLT = (AktVLT-5 if AktRPM-ZielRPM > 100 else AktVLT-1)
1019 setVoltage(id,AktVLT)
1022 FClog("Control Error")
1023 import traceback, sys
1024 traceback.print_exc(file=sys.stdout)
1025 # FClog(str(time.time() - tt ))
1026 self.timer.startLongTimer(10)
1028 def autostart(reason, **kwargs):
1030 from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild
1031 from FC2webSite import FC2web, FC2webLog, FC2webChart
1032 from twisted.web import static
1033 root = static.File("/usr/lib/enigma2/python/Plugins/Extensions/FanControl2/data")
1035 root.putChild("", FC2web())
1036 root.putChild("log", FC2webLog())
1037 root.putChild("chart", FC2webChart())
1038 addExternalChild( ("fancontrol", root) )
1039 if reason == 0 and kwargs.has_key("session"):
1040 session = kwargs["session"]
1041 session.open(FanControl2)
1043 def Plugins(**kwargs):
1045 PluginDescriptor(name="Fan Control",
1046 description="Fan Control 2",
1047 where = [PluginDescriptor.WHERE_SESSIONSTART,
1048 PluginDescriptor.WHERE_AUTOSTART],
1050 PluginDescriptor(name="Fan Control",
1051 description="Fan Control 2",
1052 where = PluginDescriptor.WHERE_PLUGINMENU,
1053 icon = "plugin.png",
1055 if config.plugins.FanControl.MonitorInExtension.value:
1056 list.append(PluginDescriptor(
1057 name="Fan Control 2 - Monitor",
1058 description="Fan Control 2",
1059 where = PluginDescriptor.WHERE_EXTENSIONSMENU,
1060 icon = "plugin.png",