aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components
diff options
context:
space:
mode:
authorghost <andreas.monzner@multimedia-labs.de>2010-01-05 19:01:59 +0100
committerghost <andreas.monzner@multimedia-labs.de>2010-01-05 19:01:59 +0100
commitc352487661e7927d0068ef8fa69765055ff488d8 (patch)
tree90066f095c2fddcba46511358c7ae1d40e992ee3 /lib/python/Components
parent8c0e6b4a527f5666195683b7cc28c278a636da0d (diff)
parent48070d1e3868f6c7e5d61002f2b707249be5d016 (diff)
downloadenigma2-c352487661e7927d0068ef8fa69765055ff488d8.tar.gz
enigma2-c352487661e7927d0068ef8fa69765055ff488d8.zip
Merge remote branch 'remotes/origin/fantempplugin'
Diffstat (limited to 'lib/python/Components')
-rw-r--r--lib/python/Components/Converter/Makefile.am2
-rw-r--r--lib/python/Components/Converter/SensorToText.py14
-rw-r--r--lib/python/Components/FanControl.py74
-rwxr-xr-xlib/python/Components/Makefile.am2
-rw-r--r--lib/python/Components/Sensors.py72
-rw-r--r--lib/python/Components/Sources/Makefile.am2
-rw-r--r--lib/python/Components/Sources/Sensor.py31
7 files changed, 194 insertions, 3 deletions
diff --git a/lib/python/Components/Converter/Makefile.am b/lib/python/Components/Converter/Makefile.am
index 75c8a08e..3b6fd3e8 100644
--- a/lib/python/Components/Converter/Makefile.am
+++ b/lib/python/Components/Converter/Makefile.am
@@ -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
index 00000000..fb156faf
--- /dev/null
+++ b/lib/python/Components/Converter/SensorToText.py
@@ -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
index 00000000..cc133ac0
--- /dev/null
+++ b/lib/python/Components/FanControl.py
@@ -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
diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am
index 34710fa1..b5ef0688 100755
--- a/lib/python/Components/Makefile.am
+++ b/lib/python/Components/Makefile.am
@@ -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
index 00000000..8898a030
--- /dev/null
+++ b/lib/python/Components/Sensors.py
@@ -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
diff --git a/lib/python/Components/Sources/Makefile.am b/lib/python/Components/Sources/Makefile.am
index 6ef8cac6..436d31be 100644
--- a/lib/python/Components/Sources/Makefile.am
+++ b/lib/python/Components/Sources/Makefile.am
@@ -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
index 00000000..e927bbf4
--- /dev/null
+++ b/lib/python/Components/Sources/Sensor.py
@@ -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)