4
# Copyright 2008-2010 Grega Podlesek <grega.podlesek@gmail.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
from sensorinterface import Sensor
24
from sensorinterface import Updater
25
from sensorvalues.tempvalue import TempValue
26
from sensorvalues.rpmvalue import RPMValue
28
i8k_sensors_path = "/proc/i8k"
30
interface_name = "i8k"
32
class I8kSensor(Sensor):
37
def __init__(self, id, name, updater, value):
38
Sensor.__init__(self, id, name, value)
39
self.updater = updater
40
self.interface = interface_name
42
def read_sensor(self):
43
i8k_output = self.updater.get_update()
44
if len(i8k_output) != 10:
48
self.value = i8k_output[self.id]
52
def get_sensors(timeout=1):
53
i8k_output = get_i8kutil_ouput()
54
if len(i8k_output) != 10:
57
updater = Updater(timeout, get_i8kutil_ouput)
61
# If value is < 0, BIOS is not reporting it, and the value is invalid
62
if int(i8k_output[3]) > 0:
63
i8k_sensors.append(I8kSensor(3, "CPU temp", updater, TempValue()))
64
if int(i8k_output[4]) > 0:
65
i8k_sensors.append(I8kSensor(6, "Left fan", updater, RPMValue()))
66
if int(i8k_output[5]) > 0:
67
i8k_sensors.append(I8kSensor(7, "Right fan", updater, RPMValue()))
71
# This happends if one of the above strings is not an int
74
def get_i8kutil_ouput():
76
Return the content of /proc/i8k in a list of the form:
78
1.0 A17 2J59L02 52 2 1 8040 6420 1 2
80
| | | | | | | | | +------- 10. buttons status
81
| | | | | | | | +--------- 9. ac status
82
| | | | | | | +-------------- 8. right fan rpm
83
| | | | | | +------------------- 7. left fan rpm
84
| | | | | +--------------------- 6. right fan status
85
| | | | +----------------------- 5. left fan status
86
| | | +-------------------------- 4. CPU temperature (Celsius)
87
| | +---------------------------------- 3. serial number
88
| +-------------------------------------- 2. BIOS version
89
+------------------------------------------ 1. /proc/i8k format version
91
A negative value, for example -22, indicates that the BIOS doesn't return
92
the corresponding information. This is normal on some models/bioses.
94
The above was copied from i8kutils' README for convenience
97
if os.path.exists(i8k_sensors_path):
99
sensorfile = open(i8k_sensors_path, 'r')
100
except IOError, (errno, errst):
101
print "i8k sensor interface:", "I/O error(%s): %s" % (errno, errst)
103
output = sensorfile.read().split()