3 # Copyright (C) 2011-2012 Simon Ruderich
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 if (scalar @ARGV != 1 and (scalar @ARGV != 2 or not $ARGV[0] =~ /-[st]/)) {
24 print STDERR "Usage: $0 [-s | -t] <path/to/device>\n";
26 print STDERR "Normally this is /sys/devices/platform/*.\n";
29 if (scalar @ARGV == 1) {
30 @ARGV = ('', $ARGV[0]);
33 my $temperature_path = "$ARGV[1]/temp1_input";
34 my $critical_path = "$ARGV[1]/temp1_crit";
36 # No temperature information available.
37 if (not -e $temperature_path or not -e $critical_path) {
38 print STDERR "'$temperature_path' or '$critical_path' not found.\n";
42 my $screen_mode = ($ARGV[0] eq '-s');
43 my $tmux_mode = ($ARGV[0] eq '-t');
49 open $file, '<', $temperature_path or die $!;
50 $temperature = <$file>;
51 close $file or die $!;
52 open $file, '<', $critical_path or die $!;
54 close $file or die $!;
56 my $value = int($temperature / 1000);
57 my $risk = ($critical - $temperature)/$critical;
59 # GNU screen mode with colors.
63 $color = 'br r'; # bold reverse
64 } elsif ($risk < 0.1) {
66 } elsif ($risk < 0.2) {
72 print "\005{+$color}$value\005{-}\n";
75 } elsif ($tmux_mode) {
80 $style = 'reverse'; # blink doesn't work for me
81 } elsif ($risk < 0.1) {
83 } elsif ($risk < 0.2) {
89 print "#[fg=$color,$style]$value#[default]\n";