#!/bin/bash 

#  No Copyright
#
#  The person who associated a work with this deed has dedicated the work to the
#  public domain by waiving all of his or her rights to the work worldwide under
#  copyright law, including all related and neighboring rights, to the extent
#  allowed by law.
#
#  You can copy, modify, distribute and perform the work, even for commercial
#  purposes, all without asking permission.
#
#  See https://creativecommons.org/share-your-work/public-domain/cc0/ for more
#  information on the license


#  This is the source code for a momentary / latching switch for guitar effect pedal,
#  made by Maarten Tromp <maarten@geekabit.nl> 2018-04-28
#
#  More info on the project:
#  https://www.geekabit.nl/projects/momentary-latching-switch/


FILENAME=switch
#PART=2313
PART=t2313

if [ -z "$FILENAME.asm" ]; then
        echo "asm file missing"
        exit 1
fi

avra $FILENAME.asm
retval=$?
rm -f *.cof *.obj

if [ $retval -ne 0 ]; then
	echo "$0: error during assembly" 2>&1
	exit 1
fi


if [ -z "$FILENAME.hex" ]; then
        echo "hex file missing"
        exit 1
fi

sudo avrdude -c usbasp -p $PART -U flash:w:$FILENAME.hex:i
retval=$?
rm -f *.hex

if [ $retval -ne 0 ]; then
	echo "$0: error during programming" 2>&1
	exit 1
fi

exit 0


# end of file
