#!/bin/sh
#
# Start the robostix
#

# Terminal settings as established with 'sertest -b 38400 /dev/ttyS2'
TTY_SETTINGS="0:0:8bf:0:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0"

start() {
        echo "Starting robostix..."

        /sbin/modprobe proc_gpio

        # Make sure ttyS2 is setup
        echo "AF2 in"  > /proc/gpio/GPIO46
        echo "AF1 out" > /proc/gpio/GPIO47
	stty -F /dev/ttyS2 $TTY_SETTINGS

        # Turn on the robostix '245
        echo "GPIO out clear" > /proc/gpio/GPIO72

        # Turn on the robostix Power
        echo "GPIO out set" > /proc/gpio/GPIO70

        # Take the robostix out of reset
        echo "GPIO out set" > /proc/gpio/GPIO73
}
stop() {
        echo "Stopping robostix..."

        # Put the robostix into reset
        echo "GPIO out clear" > /proc/gpio/GPIO73 
}
restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?

