-
Notifications
You must be signed in to change notification settings - Fork 294
/
pwm-fan.sh
executable file
·64 lines (53 loc) · 1.44 KB
/
pwm-fan.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
if [ ! -d /sys/class/pwm/pwmchip0 ]; then
echo "this model does not support pwm."
exit 1
fi
if [ ! -d /sys/class/pwm/pwmchip0/pwm0 ]; then
echo -n 0 > /sys/class/pwm/pwmchip0/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip0/pwm0 ];
do
sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip0/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
echo -n 0 > /sys/class/pwm/pwmchip0/pwm0/enable
fi
echo -n 1000000 > /sys/class/pwm/pwmchip0/pwm0/period
echo -n 1 > /sys/class/pwm/pwmchip0/pwm0/enable
# max speed run 5s
echo -n 500000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
sleep 5
echo -n 500000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
# declare -a CpuTemps=(55000 43000 38000 32000)
# declare -a PwmDutyCycles=(1000 20000 30000 45000)
declare -a CpuTemps=(75000 63000 58000 52000)
declare -a PwmDutyCycles=(500000 650000 800000 950000)
declare -a Percents=(100 75 50 25)
DefaultDuty=999990
DefaultPercents=0
while true
do
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
INDEX=0
FOUNDTEMP=0
DUTY=$DefaultDuty
PERCENT=$DefaultPercents
for i in 0 1 2 3; do
if [ $temp -gt ${CpuTemps[$i]} ]; then
INDEX=$i
FOUNDTEMP=1
break
fi
done
if [ ${FOUNDTEMP} == 1 ]; then
DUTY=${PwmDutyCycles[$i]}
PERCENT=${Percents[$i]}
fi
echo -n $DUTY > /sys/class/pwm/pwmchip0/pwm0/duty_cycle;
# echo "temp: $temp, duty: $DUTY, ${PERCENT}%"
# cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq
sleep 2s;
done