updated hc4_fancontrol to version 0.2.0
This commit is contained in:
parent
64890504aa
commit
e8822a14f3
|
@ -10,46 +10,59 @@ VERSION="0.2.0"
|
|||
LICENSE="GPLv3"
|
||||
|
||||
# Configuration
|
||||
THRESHOLD=42000
|
||||
DISTANCE=2000
|
||||
INTERVAL=30
|
||||
STEPS=(120 160 210 255)
|
||||
THRESHOLD=45000
|
||||
DISTANCE=1000
|
||||
INTERVAL=10
|
||||
STEPS=(80 120 160 210 255)
|
||||
FAN="/sys/class/hwmon/hwmon2/pwm1"
|
||||
|
||||
# Get all temperature readings and return the highest value
|
||||
function get_temp() {
|
||||
local TEMP=($(cat /sys/devices/virtual/thermal/thermal_zone*/temp))
|
||||
for I in ${TEMP[@]}; do
|
||||
echo "temp: $I"
|
||||
local TEMPS=($(cat /sys/devices/virtual/thermal/thermal_zone*/temp))
|
||||
local RESULT=${TEMPS[0]};
|
||||
for TEMP in ${TEMPS[@]}; do
|
||||
if [ $TEMP -gt $RESULT ]; then
|
||||
RESULT=$TEMP
|
||||
fi
|
||||
done
|
||||
echo $RESULT
|
||||
}
|
||||
|
||||
# set fan mode to manual
|
||||
# Get current fan speed
|
||||
function get_speed() {
|
||||
local SPEED=$(cat $FAN)
|
||||
echo $SPEED
|
||||
}
|
||||
|
||||
# Set new fan speed
|
||||
function set_speed() {
|
||||
local CURRENT_SPEED=$(get_speed)
|
||||
local NEW_SPEED=$1
|
||||
if [ $CURRENT_SPEED -ne $NEW_SPEED ]; then
|
||||
echo $NEW_SPEED > $FAN
|
||||
sleep 3
|
||||
fi
|
||||
}
|
||||
|
||||
# Set fan mode to manual
|
||||
echo "disabled" | tee /sys/class/thermal/thermal_zone{0,1}/mode > /dev/null
|
||||
|
||||
# set fan speed to max if either cpu or ram is above $THRESHOLD
|
||||
# Run loop
|
||||
while true; do
|
||||
TOOHOT=0
|
||||
FANSPEED=$(cat $FAN)
|
||||
TEMP=($(cat /sys/devices/virtual/thermal/thermal_zone{0,1}/temp))
|
||||
for i in ${TEMP[@]}; do
|
||||
if [ $i -gt $THRESHOLD ]; then
|
||||
TOOHOT=255
|
||||
fi
|
||||
done
|
||||
if [ $TOOHOT -eq 0 ]; then
|
||||
if [ $FANSPEED -ne $TOOHOT ]; then
|
||||
echo 170 > $FAN; sleep 2
|
||||
echo 120 > $FAN; sleep 2
|
||||
echo $TOOHOT > $FAN
|
||||
fi
|
||||
TEMP=$(get_temp)
|
||||
SPEED=$(get_speed)
|
||||
NEW_THRESHOLD=$THRESHOLD
|
||||
if [ $TEMP -gt $THRESHOLD ]; then
|
||||
for STEP in ${STEPS[@]}; do
|
||||
if [ $TEMP -gt $NEW_THRESHOLD ]; then
|
||||
NEW_THRESHOLD=$((NEW_THRESHOLD + DISTANCE))
|
||||
if [ $SPEED -lt $STEP ]; then
|
||||
set_speed $STEP
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
if [ $FANSPEED -ne $TOOHOT ]; then
|
||||
echo 120 > $FAN; sleep 2
|
||||
echo 170 > $FAN; sleep 2
|
||||
echo $TOOHOT > $FAN
|
||||
fi
|
||||
set_speed 0
|
||||
fi
|
||||
# debug output
|
||||
#echo "temp=${TEMP[@]},speed=$FANSPEED, toohot=$TOOHOT"
|
||||
sleep $INTERVAL
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue