Merge pull request #6 from ZeroChaos-/switch

shellcheck switch
dev
Marc 2019-12-13 22:02:32 +00:00 committed by GitHub
commit d12bb3221a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -1,25 +1,25 @@
#!/bin/bash
function setup() {
echo $1 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio$1/direction
echo "${1}" > /sys/class/gpio/export
echo in > "/sys/class/gpio/gpio${1}/direction"
}
function check_gpio() {
if [ ! -d /sys/class/gpio/gpio$1 ]; then
setup $1
if [ ! -d "/sys/class/gpio/gpio${1}" ]; then
setup "${1}"
fi
state=$(cat /sys/class/gpio/gpio$1/value)
echo $state
state=$(cat "/sys/class/gpio/gpio${1}/value")
echo "${state}"
}
gpio0=$(check_gpio 0)
gpio2=$(check_gpio 2)
if [ $gpio0 -eq "0" ] && [ $gpio2 -eq "0" ]; then
if [ "${gpio0}" -eq "0" ] && [ "${gpio2}" -eq "0" ]; then
echo "switch1"
elif [ $gpio0 -eq "0" ]; then
elif [ "${gpio0}" -eq "0" ]; then
echo "switch3"
elif [ $gpio2 -eq "0" ]; then
elif [ "${gpio2}" -eq "0" ]; then
echo "switch2"
fi