From 139a79c36b2362dd5bc730427399f0394d7c30a6 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 28 Jul 2021 12:48:03 +0200 Subject: [PATCH] Create GPIO and PWM paths in SATA_HAT script --- scripts/SATA-hat.sh | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/scripts/SATA-hat.sh b/scripts/SATA-hat.sh index ac721b9..8d879e1 100755 --- a/scripts/SATA-hat.sh +++ b/scripts/SATA-hat.sh @@ -1,56 +1,60 @@ #!/bin/sh -BASE_PATH=/sys/class/gpio +BASE_PATH=/sys/class +GPIO_PATH="$BASE_PATH"/gpio +PWM_PATH="$BASE_PATH"/pwm # GPIO pins SATA0=26 SATA1=25 +# PWM pins CPU_FAN=12 +HDD_FAN=13 # Values LOW=0 HIGH=1 export_pin() { - if [ ! -e $BASE_PATH/gpio"$1" ]; then - echo "$1" >$BASE_PATH/export - fi + if [ ! -e $GPIO_PATH/gpio"$1" ]; then + echo "$1" >$GPIO_PATH/export + fi } unexport_pin() { - if [ -e $BASE_PATH/gpio"$1" ]; then - echo "$1" >$BASE_PATH/unexport - fi + if [ -e $GPIO_PATH/gpio"$1" ]; then + echo "$1" >$GPIO_PATH/unexport + fi } set_mode() { - export_pin "$1" - echo "out" >$BASE_PATH/gpio"$1"/direction - echo "$2" >$BASE_PATH/gpio"$1"/value - if [ "$3" = "clean" ]; then - unexport_pin "$1" - fi + export_pin "$1" + echo "out" >$GPIO_PATH/gpio"$1"/direction + echo "$2" >$GPIO_PATH/gpio"$1"/value + if [ "$3" = "clean" ]; then + unexport_pin "$1" + fi } turn_on() { - set_mode $SATA0 $HIGH - sleep 1 - set_mode $SATA1 $HIGH - set_mode $CPU_FAN $LOW + set_mode $SATA0 $HIGH + sleep 1 + set_mode $SATA1 $HIGH + set_mode $CPU_FAN $HIGH } turn_off() { - set_mode $SATA0 $LOW clean - set_mode $SATA1 $LOW clean - set_mode $CPU_FAN $LOW clean + set_mode $SATA0 $LOW clean + set_mode $SATA1 $LOW clean + set_mode $CPU_FAN $LOW clean } trap turn_off INT if [ "$1" = "on" ]; then - turn_on + turn_on else - turn_off + turn_off fi exit 0