From 69f1ecd819f50ae5a191a9c497cb083cbd3eb7b3 Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Mon, 18 Jan 2016 01:03:09 -0500 Subject: [PATCH 1/2] Removes superfluous sudo. This will simply need to be run with sudo (or as root). --- bin/setgpio | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/setgpio b/bin/setgpio index a86aa06..432b261 100755 --- a/bin/setgpio +++ b/bin/setgpio @@ -12,33 +12,33 @@ if [[ -n $NINJA_HARDWARE_TYPE ]]; then echo -e "\x07" > /sys/kernel/debug/omap_mux/gpmc_ad6 fi if [ "$NINJA_HARDWARE_TYPE" == "BBB" ] || [ "$NINJA_HARDWARE_TYPE" == "BBW" ]; then - sudo echo "$NINJA_CAPE_DETECT_GPIO" > /sys/class/gpio/export; + echo "$NINJA_CAPE_DETECT_GPIO" > /sys/class/gpio/export; if [[ -n $NINJA_CAPE_V11V12_RESETGPIO ]]; then - sudo echo "$NINJA_CAPE_V11V12_RESETGPIO" > /sys/class/gpio/export; + echo "$NINJA_CAPE_V11V12_RESETGPIO" > /sys/class/gpio/export; fi if [[ -n $NINJA_CAPE_V121_RESETGPIO ]]; then - sudo echo "$NINJA_CAPE_V121_RESETGPIO" > /sys/class/gpio/export; + echo "$NINJA_CAPE_V121_RESETGPIO" > /sys/class/gpio/export; fi elif [ "$NINJA_HARDWARE_TYPE" == "RPI" ]; then if [[ -n $NINJA_CRUST_V10_RESETGPIO ]]; then - sudo echo "$NINJA_CRUST_V10_RESETGPIO" > /sys/class/gpio/export; + echo "$NINJA_CRUST_V10_RESETGPIO" > /sys/class/gpio/export; fi fi sleep 1; if [ "$NINJA_HARDWARE_TYPE" == "BBB" ] || [ "$NINJA_HARDWARE_TYPE" == "BBW" ]; then - sudo echo "in" > /sys/class/gpio/gpio$NINJA_CAPE_DETECT_GPIO/direction; + echo "in" > /sys/class/gpio/gpio$NINJA_CAPE_DETECT_GPIO/direction; if [[ -n $NINJA_CAPE_V11V12_RESETGPIO ]]; then - sudo echo "out" > /sys/class/gpio/gpio$NINJA_CAPE_V11V12_RESETGPIO/direction; - sudo chown -R ubuntu /sys/class/gpio/gpio$NINJA_CAPE_V11V12_RESETGPIO/value + echo "out" > /sys/class/gpio/gpio$NINJA_CAPE_V11V12_RESETGPIO/direction; + chown -R ubuntu /sys/class/gpio/gpio$NINJA_CAPE_V11V12_RESETGPIO/value fi if [[ -n $NINJA_CAPE_V121_RESETGPIO ]]; then - sudo echo "out" > /sys/class/gpio/gpio$NINJA_CAPE_V121_RESETGPIO/direction; - sudo chown -R ubuntu /sys/class/gpio/gpio$NINJA_CAPE_V121_RESETGPIO/value + echo "out" > /sys/class/gpio/gpio$NINJA_CAPE_V121_RESETGPIO/direction; + chown -R ubuntu /sys/class/gpio/gpio$NINJA_CAPE_V121_RESETGPIO/value fi elif [ "$NINJA_HARDWARE_TYPE" == "RPI" ]; then if [[ -n $NINJA_CRUST_V10_RESETGPIO ]]; then - sudo echo "out" > /sys/class/gpio/gpio$NINJA_CRUST_V10_RESETGPIO/direction; - sudo chown -R pi /sys/class/gpio/gpio$NINJA_CRUST_V10_RESETGPIO/value + echo "out" > /sys/class/gpio/gpio$NINJA_CRUST_V10_RESETGPIO/direction; + chown -R pi /sys/class/gpio/gpio$NINJA_CRUST_V10_RESETGPIO/value fi fi fi From c307e36c948f2f0c34903e22b0859b6bdc68dafa Mon Sep 17 00:00:00 2001 From: Hilmar Lapp Date: Mon, 18 Jan 2016 01:20:34 -0500 Subject: [PATCH 2/2] Prevents write errors due to resource busy. --- bin/setgpio | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/setgpio b/bin/setgpio index 432b261..3c642f8 100755 --- a/bin/setgpio +++ b/bin/setgpio @@ -12,15 +12,17 @@ if [[ -n $NINJA_HARDWARE_TYPE ]]; then echo -e "\x07" > /sys/kernel/debug/omap_mux/gpmc_ad6 fi if [ "$NINJA_HARDWARE_TYPE" == "BBB" ] || [ "$NINJA_HARDWARE_TYPE" == "BBW" ]; then - echo "$NINJA_CAPE_DETECT_GPIO" > /sys/class/gpio/export; - if [[ -n $NINJA_CAPE_V11V12_RESETGPIO ]]; then + if [ ! -d /sys/class/gpio/gpio$NINJA_CAPE_DETECT_GPIO ] ; then + echo "$NINJA_CAPE_DETECT_GPIO" > /sys/class/gpio/export; + fi + if [ -n "$NINJA_CAPE_V11V12_RESETGPIO" ] && [ ! -d /sys/class/gpio/gpio$NINJA_CAPE_V11V12_RESETGPIO ] ; then echo "$NINJA_CAPE_V11V12_RESETGPIO" > /sys/class/gpio/export; fi - if [[ -n $NINJA_CAPE_V121_RESETGPIO ]]; then + if [ -n "$NINJA_CAPE_V121_RESETGPIO" ] && [ ! -d /sys/class/gpio/gpio$NINJA_CAPE_V121_RESETGPIO ] ; then echo "$NINJA_CAPE_V121_RESETGPIO" > /sys/class/gpio/export; fi elif [ "$NINJA_HARDWARE_TYPE" == "RPI" ]; then - if [[ -n $NINJA_CRUST_V10_RESETGPIO ]]; then + if [ -n "$NINJA_CRUST_V10_RESETGPIO" ] && [ ! -d /sys/class/gpio/gpio$NINJA_CRUST_V10_RESETGPIO ] ; then echo "$NINJA_CRUST_V10_RESETGPIO" > /sys/class/gpio/export; fi fi