aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/FanControl.py
blob: 7a402272473317b1a471c7300d8886e1d3bb637d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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()):
			default_vlt = self.getVoltage(fanid)
			default_pwm = self.getPWM(fanid)
			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()