-
Notifications
You must be signed in to change notification settings - Fork 1
/
AsusD541S_FanControl_PowerGovernor.sh
113 lines (97 loc) · 2.26 KB
/
AsusD541S_FanControl_PowerGovernor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
#FAN SETTINGS
SENSORS=(
/sys/class/hwmon/hwmon4/temp2_input # CPU core0
/sys/class/hwmon/hwmon4/temp4_input # CPU core1
)
START_TRIGGER=55000 # Temp when to start fan
STOP_TRIGGER=40000 # Temp when to stop fan
CMD_START="sudo echo 2 | sudo tee /sys/class/hwmon/hwmon3/pwm1_enable"
CMD_STOP="sudo echo 2 | sudo tee /sys/class/hwmon/hwmon3/pwm1"
#GOVERNOR SETTINGS
GOVERNOR_AC=performance # CPU governor when charging
GOVERNOR_DC=powersave # CPU governor when not charging
#OTHER SETTINGS
FREQ=5 # Main loop frequency
#VARIABLES
fan_status=1 # internal flag for FAN status | 0=stopped, 1=running
acPrev=10 # internal flag for Charging status | 0=discharging, 1=charging
#FUNCTIONS
#FAN Functions
function stopFan { # stop fan
if [[ $fan_status -eq 1 ]]
then
fan_status=0
eval $CMD_STOP
echo "Fan stopped" # debug
fi
}
function startFan { # start fan
if [[ $fan_status -eq 0 ]]
then
fan_status=1
eval $CMD_START
echo "Fan started" # debug
fi
}
function getTemp { # get total temp (sum of all sensors / number of sensors)
total=0
for s in ${SENSORS[*]}
do
temp=$(cat $s)
total=$(($total+$temp))
done
echo $(($total/${#SENSORS[*]}))
}
#Governor Functions
function getAC { # Returns AC status (1=charging, 0=discharging)
echo $(cat /sys/class/power_supply/AC0/online)
}
function setGovernor { # Set CPU governor to $1
echo "$1" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo "CPU Governor set to $1" # debug
}
function setGovernorCharge { # Set governor for charging
setGovernor $GOVERNOR_AC
}
function setGovernorDischarge { # Set governor for discharging
setGovernor $GOVERNOR_DC
}
#Main Loop
function main {
stopFan
while true
do
#Get Temperature and Charging status
temp=$(getTemp)
acNow="$(getAC)"
echo "Temperature: $temp - Charging: $acNow" # debug
#Fan control
if [[ $temp -ge $START_TRIGGER ]]
then
startFan
elif [[ $temp -le $STOP_TRIGGER ]]
then
stopFan
fi
#Governor control
if [[ ! $acNow -eq $acPrev ]] # AC state changed
then
if [[ $acNow -eq 1 ]]
then # Charging
setGovernorCharge
elif [[ $acNow -eq 0 ]]
then # Discharging
setGovernorDischarge
fi
acPrev=$acNow
fi
#Sleep
sleep $FREQ
done
}
#EXECUTION
main
#END
startFan
echo "End of script" # debug