2017-02-18 17:38:55 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-02-20 21:50:21 +00:00
|
|
|
|
|
|
|
# [1] If empty pin number
|
|
|
|
#========================================================#
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
|
|
|
echo 127;
|
|
|
|
exit 127;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# [2] Check if valid pin number (integer)
|
|
|
|
#========================================================#
|
|
|
|
test $1 -ge 0 2> /dev/null;
|
|
|
|
|
|
|
|
if [ $? -gt 1 ]; then
|
|
|
|
|
|
|
|
echo 127;
|
|
|
|
exit 127;
|
|
|
|
|
|
|
|
fi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# [3] Activate (if not already)
|
|
|
|
#========================================================#
|
|
|
|
test -d /sys/class/gpio/gpio$1 || echo $1 > /sys/class/gpio/export;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-12 17:19:46 +00:00
|
|
|
# [4] Set mode to IN
|
2017-02-20 21:50:21 +00:00
|
|
|
#========================================================#
|
2017-02-21 14:59:04 +00:00
|
|
|
cat /sys/class/gpio/gpio$1/direction | grep -v "in" && echo "in" > /sys/class/gpio/gpio$1/direction;
|
2017-02-20 21:50:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-12 17:19:46 +00:00
|
|
|
# [5] RETURN VALUE
|
2017-02-20 21:50:21 +00:00
|
|
|
#========================================================#
|
2017-10-12 17:19:46 +00:00
|
|
|
VALUE="`cat /sys/class/gpio/gpio$1/value`";
|
|
|
|
|
|
|
|
echo $VALUE;
|
|
|
|
exit $VALUE;
|