Files
orangepi_coolfan/manual_wiringOP/example-script

51 lines
979 B
Bash

#!/bin/sh
# Physical | V | Mode | Name | wPi | GPIO
# 8 | 0 | OUT | TXD.3 | 3 | 13
readonly FAN_PIN=3
readonly FAN_START=44000
readonly FAN_STOP=35000
readonly SLEEP_TIME=10
FAN_STATE=0
setup()
{
gpio export $FAN_PIN out
gpio write $FAN_PIN 0
}
cleanup()
{
gpio write $FAN_PIN 0
gpio unexport $FAN_PIN
rm /var/run/coolfan.pid
exit 0
}
setFanState()
{
if [ $(gpio read $FAN_PIN) != $1 ] ; then
gpio write $FAN_PIN $1
fi
}
setup
trap cleanup 15
echo $$ > /var/run/coolfan.pid
while :; do
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
if [ "$TEMP" -ge "$FAN_START" ] && [ $FAN_STATE != 1 ] ; then
FAN_STATE=1
setFanState $FAN_STATE
echo "FAN ON; TEMP: $TEMP"
else
if [ "$TEMP" -le "$FAN_STOP" ] && [ $FAN_STATE != 0 ] ; then
FAN_STATE=0
setFanState $FAN_STATE
echo "FAN OFF; TEMP: $TEMP"
fi
fi
sleep $SLEEP_TIME
done