Created
November 25, 2014 00:17
-
-
Save andydude/606202d79502e98d1036 to your computer and use it in GitHub Desktop.
Reimplemtnation of i8kmon in Bash because Tcl sucks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set config(0) {{- 0} -1 56 -1 56} | |
#set config(1) {{- 1} 47 75 47 75} | |
#set config(2) {{- 2} 65 128 65 128} | |
## config | |
I8KCTL_FAN="i8kctl fan" | |
I8KCTL_TEMP="i8kctl temp" | |
## status | |
STATE_0="- 0" | |
STATE_1="- 1" | |
STATE_2="- 2" | |
STATE_0_LO="-1" | |
STATE_1_LO="60" | |
STATE_2_LO="65" | |
STATE_0_HI="70" | |
STATE_1_HI="75" | |
STATE_2_HI="128" | |
STATE="$($I8KCTL_FAN | cut -d' ' -f2)" | |
TEMP=0 | |
function get_state_pair() { | |
state="$1" | |
case $state in | |
(0) | |
echo $STATE_0 | |
;; | |
(1) | |
echo $STATE_1 | |
;; | |
(2) | |
echo $STATE_2 | |
;; | |
esac | |
} | |
function get_state_config() { | |
extrema="$1" | |
state="$2" | |
case $state in | |
(0) | |
if [ $extrema = hi ]; then | |
echo $STATE_0_HI | |
else | |
echo $STATE_0_LO | |
fi | |
;; | |
(1) | |
if [ $extrema = hi ]; then | |
echo $STATE_1_HI | |
else | |
echo $STATE_1_LO | |
fi | |
;; | |
(2) | |
if [ $extrema = hi ]; then | |
echo $STATE_2_HI | |
else | |
echo $STATE_2_LO | |
fi | |
;; | |
esac | |
} | |
function fan_control () { | |
should_set_fan=false | |
TEMP=$($I8KCTL_TEMP) | |
if [ $STATE -lt 3 -a $TEMP -lt 128 -a $TEMP -ge "$(get_state_config hi $STATE)" ]; then | |
STATE="$(expr $STATE + 1)" | |
should_set_fan=true | |
fi | |
if [ $STATE -gt 0 -a $TEMP -gt 0 -a $TEMP -le $(get_state_config lo $STATE) ]; then | |
STATE="$(expr $STATE - 1)" | |
should_set_fan=true | |
fi | |
if $should_set_fan; then | |
echo "calling set_fan on " $STATE | |
set_fan $STATE | |
fi | |
} | |
function set_fan () { | |
state=$1 | |
state_pair="$(get_state_pair $STATE)" | |
echo "running: " i8kfan $state_pair | |
$I8KCTL_FAN $state_pair | |
$I8KCTL_TEMP | |
} | |
while true; do | |
fan_control | |
sleep 3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment