Update script, added script with using wiringOP

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2022-09-05 15:20:53 +07:00
parent b6a8f074b9
commit ecab2ac640
5 changed files with 52 additions and 6 deletions

View File

@@ -2,17 +2,17 @@
# Physical | V | Mode | Name | wPi | GPIO
# 8 | 0 | OUT | TXD.3 | 3 | 13
readonly FAN_PIN=13
readonly FAN_PIN="13"
readonly FAN_PATH=/sys/class/gpio/gpio${FAN_PIN}
readonly MSG_ON='Fan ON!'
readonly MSG_OFF='Fan OFF!'
readonly MSG_ON="Fan ON!"
readonly MSG_OFF="Fan OFF!"
old_state=$(cat $FAN_PATH/value)
initialize()
setup()
{
echo $FAN_PIN > /sys/class/gpio/export
echo 'out' > $FAN_PATH/direction
echo "out" > $FAN_PATH/direction
echo 0 > $FAN_PATH/value
}

View File

@@ -12,7 +12,7 @@ cleanup()
trap cleanup 15
/usr/bin/coolfan-control initialize
/usr/bin/coolfan-control setup
while :; do
echo $$ > /var/run/coolfan.pid

View File

@@ -0,0 +1,46 @@
#!/bin/sh
# Physical | V | Mode | Name | wPi | GPIO
# 8 | 0 | OUT | TXD.3 | 3 | 13
readonly FAN_PIN="3"
readonly MSG_ON="Fan ON!"
readonly MSG_OFF="Fan OFF!"
setup()
{
gpio export $FAN_PIN
gpio mode $FAN_PIN out
gpio write $FAN_PIN 0
old_state=$(gpio read $FAN_PIN)
}
cleanup()
{
gpio write $FAN_PIN 0
gpio unexport $FAN_PIN
}
on()
{
gpio write $FAN_PIN 1
}
off()
{
gpio write $FAN_PIN 0
}
case $1 in
on|off) "$1";;
esac
cur_state=$(gpio read $FAN_PIN)
if [ "$old_state" != "$cur_state" ] && [ -z "$2" ]; then
if [ "$cur_state" = 0 ]; then
echo $MSG_OFF
else
echo $MSG_ON
fi
fi