-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp2fan-controler.sh
executable file
·136 lines (114 loc) · 2.84 KB
/
temp2fan-controler.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
# Variables
PATH_CONFIG="/etc/temp2fan.conf"
PATH_APPLESMC="/sys/devices/platform/applesmc.768/"
CURRENT_MAX_TEMP="$(sensors | grep T | grep + | tr -d '+' | tr -d ' ' | cut -d '=' -f2 | tr -d 'C' | cut -d ':' -f 2 | cut -d '.' -f 1 | sort -nr | head -1)"
FAN_NUMBERS="$(ls -1 /sys/devices/platform/applesmc.768/fan*_input | wc -l )"
CONTROLER_MODE="$( cat ${PATH_CONFIG} | grep -i controler_model | tr -d ' ' | cut -d '=' -f 2 )"
set_fan_write_mode () {
for fan in /sys/devices/platform/applesmc.768/fan*_manual
do
echo 1 > $fan
done
}
set_max_and_min_rpm_variable () {
i=1
for fan in ${PATH_APPLESMC}fan*_min
do
echo "$((FAN_${i}_MIN_RPM = "$(cat $fan)"))" 1> /dev/null
((i = i + 1))
done
i=1
for fan in ${PATH_APPLESMC}fan*_max
do
echo "$((FAN_${i}_MAX_RPM = "$(cat $fan)"))" 1> /dev/null
((i = i + 1))
done
}
calculate_fan_rpm_based_on_porcentage () {
# $1 -> percentage
# $2 > fan number
fanPrefix="FAN_${2}"
minSuffix="_MIN_RPM"
maxSuffix="_MAX_RPM"
if [ $1 -le 0 ] || [ $1 -gt 100 ]
then
echo "$(( $fanPrefix$minSuffix ))"
else
echo "$(( (( ( $1 * ( $fanPrefix$maxSuffix - $fanPrefix$minSuffix )) / 100) + $fanPrefix$minSuffix ) ))"
fi
}
set_new_rpm () {
# $1 -> percentage
# apply same percentage to all fans
i=1
for fan in ${PATH_APPLESMC}fan*_output
do
calculate_fan_rpm_based_on_porcentage $1 $i > $fan
((i = i + 1))
done
}
#controler models
discrete_controler_temp2fan () {
if [ $CURRENT_MAX_TEMP -le 65 ]
then
echo -n "Fans set at: min. "
set_new_rpm 0
fi
if [ $CURRENT_MAX_TEMP -gt 65 ] && [ $CURRENT_MAX_TEMP -le 70 ]
then
echo -n "Fans set at: 25%. "
set_new_rpm 25
fi
if [ $CURRENT_MAX_TEMP -gt 70 ] && [ $CURRENT_MAX_TEMP -le 75 ]
then
echo -n "Fans set at: 50%. "
set_new_rpm 50
fi
if [ $CURRENT_MAX_TEMP -gt 75 ] && [ $CURRENT_MAX_TEMP -le 80 ]
then
echo -n "Fans set at: 75%. "
set_new_rpm 75
fi
if [ $CURRENT_MAX_TEMP -gt 80 ] && [ $CURRENT_MAX_TEMP -le 85 ]
then
echo -n "Fans set at: 85%. "
set_new_rpm 85
fi
if [ $CURRENT_MAX_TEMP -gt 85 ]
then
echo -n "Fans set at: 100%. "
set_new_rpm 100
fi
}
# This is a linear controler for 0% rpm at 65C and 100% at 85C
linear_controler_temp2fan () {
if [ $CURRENT_MAX_TEMP -lt 65 ]
then
echo -n "Fans set at: 0%. "
set_new_rpm 0
fi
if [ $CURRENT_MAX_TEMP -gt 85 ]
then
echo -n "Fans set at: 100%. "
set_new_rpm 100
fi
echo -n "Fans set at: $(( 5 * $CURRENT_MAX_TEMP - 325 ))%. "
set_new_rpm "$(( 5 * $CURRENT_MAX_TEMP - 325 ))"
}
# MAIN EXECUTION
set_max_and_min_rpm_variable
set_fan_write_mode
case $CONTROLER_MODE in
1)
discrete_controler_temp2fan
;;
2)
linear_controler_temp2fan
;;
*)
discrete_controler_temp2fan
;;
esac
echo ''
exit 0