Skip to content

Instantly share code, notes, and snippets.

@Juma7C9
Created July 26, 2023 19:10
Show Gist options
  • Save Juma7C9/e11dcd3143a7cf5b583cd96ed9b4ff6f to your computer and use it in GitHub Desktop.
Save Juma7C9/e11dcd3143a7cf5b583cd96ed9b4ff6f to your computer and use it in GitHub Desktop.
Simple script to control pwm fans using a defined curve; requires a companion script to actually send the correct command to the fan controller.
#!/bin/bash
INTERVAL="10s"
INPUT_DRIVER="coretemp"
#TEMP_PATH="/sys/class/hwmon/hwmon3/temp1_input"
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