From ecab2ac64072cdf57f97f2e52885f31351e5305e Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Mon, 5 Sep 2022 15:20:53 +0700 Subject: [PATCH] Update script, added script with using wiringOP Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- {script => clean_bash}/coolfan-control | 10 ++--- script/coolfan-start => coolfan-start | 2 +- script/coolfan-stop => coolfan-stop | 0 script/coolfan.service => coolfan.service | 0 using_wiringOP/coolfan-control | 46 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 6 deletions(-) rename {script => clean_bash}/coolfan-control (84%) rename script/coolfan-start => coolfan-start (92%) rename script/coolfan-stop => coolfan-stop (100%) rename script/coolfan.service => coolfan.service (100%) create mode 100644 using_wiringOP/coolfan-control diff --git a/script/coolfan-control b/clean_bash/coolfan-control similarity index 84% rename from script/coolfan-control rename to clean_bash/coolfan-control index 5fd72c3..47952b8 100644 --- a/script/coolfan-control +++ b/clean_bash/coolfan-control @@ -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 } diff --git a/script/coolfan-start b/coolfan-start similarity index 92% rename from script/coolfan-start rename to coolfan-start index ed4beb1..0a85b40 100644 --- a/script/coolfan-start +++ b/coolfan-start @@ -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 diff --git a/script/coolfan-stop b/coolfan-stop similarity index 100% rename from script/coolfan-stop rename to coolfan-stop diff --git a/script/coolfan.service b/coolfan.service similarity index 100% rename from script/coolfan.service rename to coolfan.service diff --git a/using_wiringOP/coolfan-control b/using_wiringOP/coolfan-control new file mode 100644 index 0000000..bf8c0f6 --- /dev/null +++ b/using_wiringOP/coolfan-control @@ -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