Merge branch 'fantempplugin' into experimental
authorthedoc <thedoc@atom.(none)>
Fri, 11 Dec 2009 12:01:26 +0000 (13:01 +0100)
committerthedoc <thedoc@atom.(none)>
Fri, 11 Dec 2009 12:01:26 +0000 (13:01 +0100)
12 files changed:
configure.ac
lib/python/Components/Converter/Makefile.am
lib/python/Components/Converter/SensorToText.py [new file with mode: 0644]
lib/python/Components/FanControl.py [new file with mode: 0644]
lib/python/Components/Makefile.am
lib/python/Components/Sensors.py [new file with mode: 0644]
lib/python/Components/Sources/Makefile.am
lib/python/Components/Sources/Sensor.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Makefile.am
lib/python/Plugins/SystemPlugins/TempFanControl/Makefile.am [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/TempFanControl/__init__.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/TempFanControl/plugin.py [new file with mode: 0644]

index 1bda10e..aa2fa3e 100755 (executable)
@@ -155,6 +155,7 @@ lib/python/Plugins/SystemPlugins/FrontprocessorUpgrade/meta/Makefile
 lib/python/Plugins/SystemPlugins/Hotplug/Makefile
 lib/python/Plugins/SystemPlugins/Hotplug/meta/Makefile
 lib/python/Plugins/SystemPlugins/Makefile
+lib/python/Plugins/SystemPlugins/TempFanControl/Makefile
 lib/python/Plugins/SystemPlugins/NetworkWizard/Makefile
 lib/python/Plugins/SystemPlugins/NetworkWizard/meta/Makefile
 lib/python/Plugins/SystemPlugins/NFIFlash/Makefile
index 75c8a08..3b6fd3e 100644 (file)
@@ -6,4 +6,4 @@ install_PYTHON = \
        ConditionalShowHide.py ServicePosition.py ValueRange.py RdsInfo.py Streaming.py \
        StaticMultiList.py ServiceTime.py MovieInfo.py MenuEntryCompare.py StringListSelection.py \
        ValueBitTest.py TunerInfo.py ConfigEntryTest.py TemplatedMultiContent.py ProgressToText.py \
-       Combine.py
+       Combine.py SensorToText.py
diff --git a/lib/python/Components/Converter/SensorToText.py b/lib/python/Components/Converter/SensorToText.py
new file mode 100644 (file)
index 0000000..fb156fa
--- /dev/null
@@ -0,0 +1,14 @@
+from Components.Converter.Converter import Converter
+
+class SensorToText(Converter, object):
+       def __init__(self, arguments):
+               Converter.__init__(self, arguments)
+        
+       def getText(self):
+               if self.source.getValue() is None:
+                       return ""
+               return "%d %s" % (self.source.getValue(), self.source.getUnit())
+       
+       text = property(getText)
+        
+        
\ No newline at end of file
diff --git a/lib/python/Components/FanControl.py b/lib/python/Components/FanControl.py
new file mode 100644 (file)
index 0000000..cc133ac
--- /dev/null
@@ -0,0 +1,74 @@
+import os
+
+from Components.config import config, ConfigSubList, ConfigSubsection, ConfigSlider
+from Tools.BoundFunction import boundFunction
+
+class FanControl:
+       # ATM there's only support for one fan
+       def __init__(self):
+               if os.path.exists("/proc/stb/fp/fan_vlt") or os.path.exists("/proc/stb/fp/fan_pwm") or os.path.exists("/proc/stb/fp/fan_speed"):
+                       self.fancount = 1
+               else:
+                       self.fancount = 0
+               self.createConfig()
+
+       def createConfig(self):
+               def setVlt(fancontrol, fanid, configElement):
+                       fancontrol.setVoltage(fanid, configElement.value)
+               def setPWM(fancontrol, fanid, configElement):
+                       fancontrol.setPWM(fanid, configElement.value)
+               
+               config.fans = ConfigSubList()
+               for fanid in range(self.getFanCount()):
+                       fan = ConfigSubsection()
+                       fan.vlt = ConfigSlider(default = 16, increment = 5, limits = (0, 255))
+                       fan.pwm = ConfigSlider(default = 0, increment = 5, limits = (0, 255))
+                       fan.vlt.addNotifier(boundFunction(setVlt, self, fanid))
+                       fan.pwm.addNotifier(boundFunction(setPWM, self, fanid))
+                       config.fans.append(fan)
+                       
+       def getConfig(self, fanid):
+               return config.fans[fanid]
+       
+       def getFanCount(self):
+               return self.fancount
+       
+       def hasRPMSensor(self, fanid):
+               return os.path.exists("/proc/stb/fp/fan_speed")
+       
+       def hasFanControl(self, fanid):
+               return os.path.exists("/proc/stb/fp/fan_vlt") or os.path.exists("/proc/stb/fp/fan_pwm")
+       
+       def getFanSpeed(self, fanid):
+               f = open("/proc/stb/fp/fan_speed", "r")
+               value = int(f.readline().strip()[:-4])
+               f.close()
+               return value
+       
+       def getVoltage(self, fanid):
+               f = open("/proc/stb/fp/fan_vlt", "r")
+               value = int(f.readline().strip(), 16)
+               f.close()
+               return value
+       
+       def setVoltage(self, fanid, value):
+               if value > 255:
+                       return
+               f = open("/proc/stb/fp/fan_vlt", "w")
+               f.write("%x" % value)
+               f.close()
+               
+       def getPWM(self, fanid):
+               f = open("/proc/stb/fp/fan_pwm", "r")
+               value = int(f.readline().strip(), 16)
+               f.close()
+               return value
+       
+       def setPWM(self, fanid, value):
+               if value > 255:
+                       return
+               f = open("/proc/stb/fp/fan_pwm", "w")
+               f.write("%x" % value)
+               f.close()
+       
+fancontrol = FanControl()
\ No newline at end of file
index 34710fa..b5ef068 100755 (executable)
@@ -19,4 +19,4 @@ install_PYTHON = \
        Element.py Playlist.py ParentalControl.py ParentalControlList.py \
        Ipkg.py SelectionList.py Scanner.py SystemInfo.py DreamInfoHandler.py \
        Task.py language_cache.py Console.py ResourceManager.py TuneTest.py \
-       Keyboard.py
+       Keyboard.py Sensors.py FanControl.py
diff --git a/lib/python/Components/Sensors.py b/lib/python/Components/Sensors.py
new file mode 100644 (file)
index 0000000..8898a03
--- /dev/null
@@ -0,0 +1,72 @@
+from Components.FanControl import fancontrol
+
+class Sensors:
+       # (type, name, unit, directory)
+       TYPE_TEMPERATURE = 0
+       # (type, name, unit, fanid)
+       TYPE_FAN_RPM = 1
+       
+       def __init__(self):
+               # (type, name, unit, sensor_specific_dict/list)
+               self.sensors_list = []
+               self.addSensors()
+               
+       def getSensorsCount(self, type = None):
+               if type is None:
+                       return len(self.sensors_list)
+               count = 0
+               for sensor in self.sensors_list:
+                       if sensor[0] == type:
+                               count += 1
+               return count
+       
+       # returns a list of sensorids of type "type"
+       def getSensorsList(self, type = None):
+               if type is None:
+                       return range(len(self.sensors_list))
+               list = []
+               for sensorid in range(len(self.sensors_list)):
+                       if self.sensors_list[sensorid][0] == type:
+                               list.append(sensorid)
+               return list
+       
+       
+       def getSensorType(self, sensorid):
+               return self.sensors_list[sensorid][0]
+       
+       def getSensorName(self, sensorid):
+               return self.sensors_list[sensorid][1]
+       
+       def getSensorValue(self, sensorid):
+               value = -1
+               sensor = self.sensors_list[sensorid]
+               if sensor[0] == self.TYPE_TEMPERATURE:
+                       f = open("%s/value" % sensor[3], "r")
+                       value = int(f.readline().strip())
+                       f.close()
+               elif sensor[0] == self.TYPE_FAN_RPM:
+                       value = fancontrol.getFanSpeed(sensor[3])
+               return value
+       
+       def getSensorUnit(self, sensorid):
+               return self.sensors_list[sensorid][2]
+
+       def addSensors(self):
+               import os
+               if os.path.exists("/proc/stb/sensors"):
+                       for dirname in os.listdir("/proc/stb/sensors"):
+                               if dirname.find("temp", 0, 4) == 0:
+                                       f = open("/proc/stb/sensors/%s/name" % dirname, "r")
+                                       name = f.readline().strip()
+                                       f.close()
+                                       
+                                       f = open("/proc/stb/sensors/%s/unit" % dirname, "r")
+                                       unit = f.readline().strip()
+                                       f.close()
+                                       
+                                       self.sensors_list.append((self.TYPE_TEMPERATURE, name, unit, "/proc/stb/sensors/%s" % dirname))
+               for fanid in range(fancontrol.getFanCount()):
+                       if fancontrol.hasRPMSensor(fanid):
+                               self.sensors_list.append((self.TYPE_FAN_RPM, _("Fan %d") % (fanid + 1), "rpm", fanid))
+       
+sensors = Sensors()
\ No newline at end of file
index 6ef8cac..436d31b 100644 (file)
@@ -4,4 +4,4 @@ install_PYTHON = \
        __init__.py Clock.py EventInfo.py Source.py List.py CurrentService.py \
        FrontendStatus.py Boolean.py Config.py ServiceList.py RdsDecoder.py StreamService.py \
        StaticText.py CanvasSource.py ServiceEvent.py Event.py FrontendInfo.py TunerInfo.py \
-       RecordState.py Progress.py
+       RecordState.py Progress.py Sensor.py
diff --git a/lib/python/Components/Sources/Sensor.py b/lib/python/Components/Sources/Sensor.py
new file mode 100644 (file)
index 0000000..e927bbf
--- /dev/null
@@ -0,0 +1,31 @@
+from Components.Sensors import sensors
+
+from enigma import eTimer
+
+from Source import Source
+
+class SensorSource(Source):
+       def __init__(self, update_interval = 500, sensorid = None):
+               self.update_interval = update_interval
+               self.sensorid = sensorid
+               Source.__init__(self)
+
+               if sensorid is not None:
+                       self.update_timer = eTimer()
+                       self.update_timer.callback.append(self.updateValue)
+                       self.update_timer.start(self.update_interval)
+
+       def getValue(self):
+               if self.sensorid is not None:
+                       return sensors.getSensorValue(self.sensorid)
+               return None
+       
+       def getUnit(self):
+               return sensors.getSensorUnit(self.sensorid)
+
+       def updateValue(self):
+               self.changed((self.CHANGED_POLL,))
+
+       def destroy(self):
+               if self.sensorid is not None:
+                       self.update_timer.callback.remove(self.updateValue)
index a8b187d..9cc538f 100755 (executable)
@@ -3,7 +3,8 @@ installdir = $(pkglibdir)/python/Plugins/SystemPlugins
 SUBDIRS = SoftwareManager FrontprocessorUpgrade PositionerSetup Satfinder \
        SkinSelector SatelliteEquipmentControl Videomode VideoTune Hotplug \
        DefaultServicesScanner NFIFlash DiseqcTester CommonInterfaceAssignment \
-       CrashlogAutoSubmit CleanupWizard VideoEnhancement WirelessLan NetworkWizard
+       CrashlogAutoSubmit CleanupWizard VideoEnhancement WirelessLan NetworkWizard \
+       TempFanControl
 
 install_PYTHON =       \
        __init__.py
diff --git a/lib/python/Plugins/SystemPlugins/TempFanControl/Makefile.am b/lib/python/Plugins/SystemPlugins/TempFanControl/Makefile.am
new file mode 100644 (file)
index 0000000..78ff11c
--- /dev/null
@@ -0,0 +1,5 @@
+installdir = $(LIBDIR)/enigma2/python/Plugins/SystemPlugins/TempFanControl
+
+install_PYTHON = \
+       __init__.py \
+       plugin.py
diff --git a/lib/python/Plugins/SystemPlugins/TempFanControl/__init__.py b/lib/python/Plugins/SystemPlugins/TempFanControl/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lib/python/Plugins/SystemPlugins/TempFanControl/plugin.py b/lib/python/Plugins/SystemPlugins/TempFanControl/plugin.py
new file mode 100644 (file)
index 0000000..5dfacd8
--- /dev/null
@@ -0,0 +1,155 @@
+from Components.ActionMap import ActionMap
+from Components.Sensors import sensors
+from Components.Sources.Sensor import SensorSource
+from Components.Sources.StaticText import StaticText
+from Components.ConfigList import ConfigListScreen
+from Components.config import getConfigListEntry
+
+from Screens.Screen import Screen
+
+from Plugins.Plugin import PluginDescriptor
+from Components.FanControl import fancontrol
+
+class TempFanControl(Screen, ConfigListScreen):
+       skin = """
+               <screen position="90,100" size="570,420" title="Fan Control" >
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
+                       <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
+                       <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
+                       <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
+                       
+                       <widget name="config" position="10,50" size="550,90" scrollbarMode="showOnDemand" />
+                       
+                       <widget source="SensorTempText0" render="Label" position="10,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp0" render="Label" position="100,150" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText1" render="Label" position="10,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp1" render="Label" position="100,170" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText2" render="Label" position="10,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp2" render="Label" position="100,190" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText3" render="Label" position="10,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp3" render="Label" position="100,210" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText4" render="Label" position="10,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp4" render="Label" position="100,230" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText5" render="Label" position="10,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp5" render="Label" position="100,250" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText6" render="Label" position="10,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp6" render="Label" position="100,270" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorTempText7" render="Label" position="10,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorTemp7" render="Label" position="100,290" zPosition="1" size="100,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       
+                       <widget source="SensorFanText0" render="Label" position="290,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan0" render="Label" position="380,150" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText1" render="Label" position="290,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan1" render="Label" position="380,170" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText2" render="Label" position="290,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan2" render="Label" position="380,190" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText3" render="Label" position="290,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan3" render="Label" position="380,210" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText4" render="Label" position="290,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan4" render="Label" position="380,230" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText5" render="Label" position="290,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan5" render="Label" position="380,250" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText6" render="Label" position="290,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan6" render="Label" position="380,270" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+                       <widget source="SensorFanText7" render="Label" position="290,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
+                       <widget source="SensorFan7" render="Label" position="380,290" zPosition="1" size="150,20" font="Regular;19" halign="right">
+                               <convert type="SensorToText"></convert>
+                       </widget>
+               </screen>"""
+       
+       def __init__(self, session, args = None):
+               Screen.__init__(self, session)
+               
+               templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
+               tempcount = len(templist)
+               fanlist = sensors.getSensorsList(sensors.TYPE_FAN_RPM)
+               fancount = len(fanlist)
+               
+               self["red"] = StaticText(_("Cancel"))
+               self["green"] = StaticText(_("OK"))
+               self["yellow"] = StaticText("")
+               self["blue"] = StaticText("")   
+               
+               for count in range(8):
+                       if count < tempcount:
+                               id = templist[count]
+                               self["SensorTempText%d" % count] = StaticText(sensors.getSensorName(id))                
+                               self["SensorTemp%d" % count] = SensorSource(sensorid = id)
+                       else:
+                               self["SensorTempText%d" % count] = StaticText("")
+                               self["SensorTemp%d" % count] = SensorSource()
+                               
+                       if count < fancount:
+                               id = fanlist[count]
+                               self["SensorFanText%d" % count] = StaticText(sensors.getSensorName(id))         
+                               self["SensorFan%d" % count] = SensorSource(sensorid = id)
+                       else:
+                               self["SensorFanText%d" % count] = StaticText("")
+                               self["SensorFan%d" % count] = SensorSource()
+               
+               self.list = []
+               for count in range(fancontrol.getFanCount()):
+                       self.list.append(getConfigListEntry(_("Fan %d Voltage") % (count + 1), fancontrol.getConfig(count).vlt))
+                       self.list.append(getConfigListEntry(_("Fan %d PWM") % (count + 1), fancontrol.getConfig(count).pwm))
+               ConfigListScreen.__init__(self, self.list, session = self.session)
+               #self["config"].list = self.list
+               #self["config"].setList(self.list)
+               
+               self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
+               {
+                       "ok": self.save,
+                       "cancel": self.revert,
+                       "red": self.revert,
+                       "green": self.save
+               }, -1)
+               
+       def save(self):
+               fancontrol.getConfig(0).vlt.save()
+               fancontrol.getConfig(0).pwm.save()
+               self.close()
+               
+       def revert(self):
+               fancontrol.getConfig(0).vlt.load()
+               fancontrol.getConfig(0).pwm.load()
+               self.close()
+
+def main(session, **kwargs):
+       session.open(TempFanControl)
+
+def Plugins(**kwargs):
+       return PluginDescriptor(name = "Temperature and Fan control", description = _("Temperature and Fan control"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main)
+       
\ No newline at end of file