1#!/bin/sh -e
2#
3#    fan_speed: speed of the cpu or case fan
4#
5#    Copyright (C) 2009 Canonical Ltd.
6#    Copyright (C) 2011-2014 Dustin Kirkland
7#
8#    Authors: Dustin Kirkland <kirkland@byobu.org>
9#
10#    This program is free software: you can redistribute it and/or modify
11#    it under the terms of the GNU General Public License as published by
12#    the Free Software Foundation, version 3 of the License.
13#
14#    This program is distributed in the hope that it will be useful,
15#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17#    GNU General Public License for more details.
18#
19#    You should have received a copy of the GNU General Public License
20#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22__fan_speed_detail() {
23	# Nothing interesting to say here about fan speed
24	return
25}
26
27__fan_speed() {
28	local i="" speed=0
29	# Let's check a few different probes for fan speed
30	# This seems to cover most of them:
31	for i in $FAN /sys/class/hwmon/*/*/fan1_input /sys/class/hwmon/*/device/hwmon/*/fan1_input; do
32		[ -f "$i" ] || continue
33		read speed < "$i"
34		if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
35			color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
36			return 0
37		fi
38	done
39
40	# But others (e.g. Dell Inspirons) seem to be here:
41	if [ -r /proc/i8k ]; then
42		local line=""
43		read line < /proc/i8k
44		set -- $line
45		for speed in $7 $8; do
46			if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
47				# I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
48				# use `modprobe i8k fan_mult=1` to disable if unneeded,
49				# resulting in nonsensical speeds
50				[ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
51				color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
52				return 0
53			fi
54		done
55	fi
56}
57
58# vi: syntax=sh ts=4 noexpandtab
59