#!/bin/sh

SHAREDIR="/usr/share/snek"

SNEKHEX="$SHAREDIR/snek-duemilanove-1.13.hex"

action="default"

PORT="/dev/ttyUSB0"

mode=arg

MCU="atmega328p"

for i in "$@"; do
    case "$mode" in
	arg)
	    case "$i" in
		-hex|--hex)
		    mode=hex
		    ;;
		-port|--port)
		    mode=port
		    ;;
		-mcu|--mcu)
		    mode=mcu
		    ;;
		*)
		      echo "Usage: $0 {-hex snek-duemilanove.hex} {-port /dev/ttyUSB0} {-mcu atmega328p}" 1>&2
		      exit 1
		      ;;
	    esac
	    ;;
	hex)
	    SNEKHEX="$i"
	    mode=arg
	    ;;
	port)
	    PORT="$i"
	    mode=arg
	    ;;
	mcu)
	    MCU="$i"
	    mode=arg
	    ;;
    esac
done

avrdude -P $PORT -c arduino -b 115200 -p "$MCU" -D -U flash:w:"${SNEKHEX}"
