first working version of TempFanControl plugin with Sensors and FanControl component
[enigma2.git] / lib / python / Components / FanControl.py
1 import os
2
3 from Components.config import config, ConfigSubList, ConfigSubsection, ConfigSlider
4 from Tools.BoundFunction import boundFunction
5
6 class FanControl:
7         # ATM there's only support for one fan
8         def __init__(self):
9                 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"):
10                         self.fancount = 1
11                 else:
12                         self.fancount = 0
13                 self.createConfig()
14
15         def createConfig(self):
16                 def setVlt(fancontrol, fanid, configElement):
17                         fancontrol.setVoltage(fanid, configElement.value)
18                 def setPWM(fancontrol, fanid, configElement):
19                         fancontrol.setPWM(fanid, configElement.value)
20                 
21                 config.fans = ConfigSubList()
22                 for fanid in range(self.getFanCount()):
23                         default_vlt = self.getVoltage(fanid)
24                         default_pwm = self.getPWM(fanid)
25                         fan = ConfigSubsection()
26                         fan.vlt = ConfigSlider(default = default_vlt, increment = 10, limits = (0, 255))
27                         fan.pwm = ConfigSlider(default = default_vlt, increment = 10, limits = (0, 255))
28                         fan.vlt.addNotifier(boundFunction(setVlt, self, fanid))
29                         fan.pwm.addNotifier(boundFunction(setPWM, self, fanid))
30                         config.fans.append(fan)
31                         
32         def getConfig(self, fanid):
33                 return config.fans[fanid]
34         
35         def getFanCount(self):
36                 return self.fancount
37         
38         def hasRPMSensor(self, fanid):
39                 return os.path.exists("/proc/stb/fp/fan_speed")
40         
41         def hasFanControl(self, fanid):
42                 return os.path.exists("/proc/stb/fp/fan_vlt") or os.path.exists("/proc/stb/fp/fan_pwm")
43         
44         def getFanSpeed(self, fanid):
45                 f = open("/proc/stb/fp/fan_speed", "r")
46                 value = int(f.readline().strip()[:-4])
47                 f.close()
48                 return value
49         
50         def getVoltage(self, fanid):
51                 f = open("/proc/stb/fp/fan_vlt", "r")
52                 value = int(f.readline().strip(), 16)
53                 f.close()
54                 return value
55         
56         def setVoltage(self, fanid, value):
57                 if value > 255:
58                         return
59                 f = open("/proc/stb/fp/fan_vlt", "w")
60                 f.write("%x" % value)
61                 f.close()
62                 
63         def getPWM(self, fanid):
64                 f = open("/proc/stb/fp/fan_pwm", "r")
65                 value = int(f.readline().strip(), 16)
66                 f.close()
67                 return value
68         
69         def setPWM(self, fanid, value):
70                 if value > 255:
71                         return
72                 f = open("/proc/stb/fp/fan_pwm", "w")
73                 f.write("%x" % value)
74                 f.close()
75         
76 fancontrol = FanControl()