Merge commit 'e8eb8e9694379204' into experimental
[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                         fan = ConfigSubsection()
24                         fan.vlt = ConfigSlider(default = 16, increment = 5, limits = (0, 255))
25                         fan.pwm = ConfigSlider(default = 0, increment = 5, limits = (0, 255))
26                         fan.vlt.addNotifier(boundFunction(setVlt, self, fanid))
27                         fan.pwm.addNotifier(boundFunction(setPWM, self, fanid))
28                         config.fans.append(fan)
29                         
30         def getConfig(self, fanid):
31                 return config.fans[fanid]
32         
33         def getFanCount(self):
34                 return self.fancount
35         
36         def hasRPMSensor(self, fanid):
37                 return os.path.exists("/proc/stb/fp/fan_speed")
38         
39         def hasFanControl(self, fanid):
40                 return os.path.exists("/proc/stb/fp/fan_vlt") or os.path.exists("/proc/stb/fp/fan_pwm")
41         
42         def getFanSpeed(self, fanid):
43                 f = open("/proc/stb/fp/fan_speed", "r")
44                 value = int(f.readline().strip()[:-4])
45                 f.close()
46                 return value
47         
48         def getVoltage(self, fanid):
49                 f = open("/proc/stb/fp/fan_vlt", "r")
50                 value = int(f.readline().strip(), 16)
51                 f.close()
52                 return value
53         
54         def setVoltage(self, fanid, value):
55                 if value > 255:
56                         return
57                 f = open("/proc/stb/fp/fan_vlt", "w")
58                 f.write("%x" % value)
59                 f.close()
60                 
61         def getPWM(self, fanid):
62                 f = open("/proc/stb/fp/fan_pwm", "r")
63                 value = int(f.readline().strip(), 16)
64                 f.close()
65                 return value
66         
67         def setPWM(self, fanid, value):
68                 if value > 255:
69                         return
70                 f = open("/proc/stb/fp/fan_pwm", "w")
71                 f.write("%x" % value)
72                 f.close()
73         
74 fancontrol = FanControl()