Last active
July 26, 2023 19:14
-
-
Save Juma7C9/8292006 to your computer and use it in GitHub Desktop.
Start/stop fans on Asus Zenbook UX32A
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 | |
# fan.sh - Script to stop and restart (setting to auto) fans on Asus Zenbook UX32A | |
# (should work also on other UX-series models - see http://goo.gl/BKcWm1) | |
# Requires acpi_call kernel module - see https://github.com/mkottman/acpi_call/) | |
# USAGE: fan.sh auto|stop|full | |
# Copyright (C) 2014-2023 Juma7C9 | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software Foundation, | |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
acpi_call=/proc/acpi/call | |
base_string='\_SB.PCI0.LPCB.EC0.SFNV' | |
start_string="${base_string} 0 0" | |
stop_1_string="${base_string} 1 0x00" | |
stop_2_string="${base_string} 2 0x00" | |
full_1_string="${base_string} 1 0xFF" | |
full_2_string="${base_string} 2 0xFF" | |
debug="False" | |
info() { | |
if [ "${debug}" == "True" ]; then | |
echo "[INFO] $1" | |
fi | |
} | |
if [ ! -f $acpi_call ] | |
then | |
if [[ $UID = 0 ]] | |
then | |
info 'Running `modprobe acpi_call`' | |
modprobe acpi_call | |
else | |
echo "[ERROR] '$acpi_call' not found. Try \`modprobe acpi_call\`." | |
exit 1 | |
fi | |
fi | |
if [ ! -f $acpi_call ] | |
then | |
echo "[ERROR] '$acpi_call still' not found. Try running \`dkms autoinstall -k KERNEL_VERSION\`." | |
exit 1 | |
fi | |
call() { | |
string=$1 | |
if [[ $UID = 0 ]] | |
then | |
echo $string > $acpi_call | |
rtn=`cat $acpi_call | tr -d '\0'` | |
else | |
echo $string | sudo tee $acpi_call >/dev/null | |
rtn=`sudo cat $acpi_call | tr -d '\0'` | |
fi | |
info "String '$string' called." | |
if [ `echo "$rtn" | cut -b-3` != '0x0' ] | |
then | |
info "Something has likely gone wrong." | |
fi | |
info "Return value is '$rtn'" | |
} | |
case $1 in | |
auto) | |
call "$start_string" | |
;; | |
stop) | |
call "$stop_1_string" | |
call "$stop_2_string" | |
;; | |
full) | |
call "$full_1_string" | |
call "$full_2_string" | |
;; | |
[0-9A-F]*) | |
call "${base_string} 1 0x$1" | |
call "${base_string} 2 0x$1" | |
;; | |
*) | |
echo "[ERROR] Usage: $0 auto|stop|full" | |
esac | |
exit 0 |
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
[Unit] | |
Description=fancontrol.sh service | |
[Service] | |
ExecStart=/usr/bin/fancontrol.sh | |
Restart=always | |
RestartSec=30 | |
[Install] | |
WantedBy=multi-user.target |
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 | |
INTERVAL="10s" | |
INPUT_DRIVER="coretemp" | |
FAN_CMD="/usr/bin/fan.sh" | |
# Find correct input temperature path | |
for hwmon in `ls /sys/class/hwmon/`; do | |
driver=$(</sys/class/hwmon/$hwmon/name) | |
if [ "$driver" == "$INPUT_DRIVER" ]; then | |
break | |
fi | |
done | |
TEMP_PATH="/sys/class/hwmon/$hwmon/temp1_input" | |
CURVE=lin_curve | |
lin_curve() { | |
m=11 | |
q=-640 | |
echo "obase=16; r = $m * $1 + $q; if ( r<48 ) 0 else r" | bc | |
} | |
while true; do | |
temp="$(( $(cat $TEMP_PATH) / 1000 ))" | |
${FAN_CMD} "$($CURVE $temp)" | |
sleep "${INTERVAL}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment