2020-01-24 02:44:17 +00:00
|
|
|
#!/bin/sh
|
2019-12-11 21:11:53 +00:00
|
|
|
|
2023-08-03 18:11:48 +00:00
|
|
|
OFFSET=480
|
2023-08-02 20:36:25 +00:00
|
|
|
|
|
|
|
GPIO0=$(($OFFSET))
|
|
|
|
GPIO2=$((2 + $OFFSET))
|
|
|
|
|
2020-01-24 02:44:17 +00:00
|
|
|
setup() {
|
2019-12-13 02:53:50 +00:00
|
|
|
echo "${1}" > /sys/class/gpio/export
|
|
|
|
echo in > "/sys/class/gpio/gpio${1}/direction"
|
2019-12-11 21:11:53 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 02:44:17 +00:00
|
|
|
check_gpio() {
|
2019-12-13 02:53:50 +00:00
|
|
|
if [ ! -d "/sys/class/gpio/gpio${1}" ]; then
|
|
|
|
setup "${1}"
|
2019-12-11 21:11:53 +00:00
|
|
|
fi
|
2019-12-13 02:53:50 +00:00
|
|
|
state=$(cat "/sys/class/gpio/gpio${1}/value")
|
|
|
|
echo "${state}"
|
2019-12-11 21:11:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 20:36:25 +00:00
|
|
|
gpio0=$(check_gpio $GPIO0)
|
|
|
|
gpio2=$(check_gpio $GPIO2)
|
2019-12-11 21:11:53 +00:00
|
|
|
|
2019-12-13 18:48:50 +00:00
|
|
|
if [ "${gpio0}" -eq "0" ] && [ "${gpio2}" -eq "0" ]; then
|
2019-12-11 21:11:53 +00:00
|
|
|
echo "switch1"
|
2019-12-13 18:48:50 +00:00
|
|
|
elif [ "${gpio0}" -eq "0" ]; then
|
2019-12-11 21:11:53 +00:00
|
|
|
echo "switch3"
|
2019-12-13 18:48:50 +00:00
|
|
|
elif [ "${gpio2}" -eq "0" ]; then
|
2019-12-11 21:11:53 +00:00
|
|
|
echo "switch2"
|
|
|
|
fi
|