Robert,

You were correct high level is better for now. It's been a long while since 
working
with 'c'.  Went the way of a bash script. Works well see below. Even 
supports --help.

---Code Start--
#!/bin/bash
#
# 4-7-2020 Ken
#
# cmd [state|label|on|off|in|out] gpio #
# Example : cmd state 112
#
if [ "$1" == "--help" ]
   then
    echo -e "\ngpio relay cape tool. 4-7-2020 KenUnix\n"
    echo "state  Get state of gpio number"
    echo "label  Display associated P number"
    echo "on     Set relay # to on"
    echo "off    Turn relay off"
    echo -e "out    Set gpio to out\n"
    echo "Example: cmd status 115 Will display the state of gpio 115"
    echo -e "         cmd on 20      Will turn relay 1 on for gpio 20\n"
    exit
fi

case $2 in
    20|7|112|115) ;;
    *) echo "Invalid gpio $2"
       echo "Vaild numbers are 20, 7, 112 or 115"
           echo -e "Relay 1 20, relay 2 7, relay 3 112, relay 4 115\007"
       exit 1 ;;
esac

case $1 in
   "state")
      direction=`cat /sys/class/gpio/gpio$2/direction`
      echo -n "Direction $direction, State "
      state=`cat /sys/class/gpio/gpio$2/value`
      if [ "$state" == "0" ]; then echo "off"; fi
      if [ "$state" == "1" ]; then echo "on"; fi
      exit ;;
   "label")
      echo -n "Physical header pin number "
      cat /sys/class/gpio/gpio$2/label ;
      exit ;;
   "on")
      echo 1 >/sys/class/gpio/gpio$2/value
      exit ;;
   "off")
      echo 0 >/sys/class/gpio/gpio$2/value
      exit ;;
   "out")
      echo "out" > /sys/class/gpio/gpio$2/direction ;
      exit ;;
   "in")
      echo "in" > /sys/class/gpio/gpio$2/direction ;
      exit ;;
   *) echo -e "Invalid operation $1. Try cmd --help\007" ; exit 1 ;;
esac
--Code End--

Maybe someone else may find this useful.

Ken

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/3b534de4-dbf1-468c-9067-d6636ec732f7%40googlegroups.com.

Reply via email to