#!/bin/bash
#
#   Version 1.1
#
#   Copyright 2016-2018 Lee Djavaherian
#
#   This file is part of TrillSat.
#
#   TrillSat is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   TrillSat is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with TrillSat.  If not, see <http://www.gnu.org/licenses/>.
###################################################################################

cd /trillsat
cat trillsat.c | sed 's/CHIP-NAME-INSERTED-FROM-SCRIPT/HUCKLEBERRY/' > huckleberry.c
avr-gcc -mmcu=attiny1634 -Os huckleberry.c -o huckleberry.o
sudo avr-objcopy -j .text -j .data -O ihex huckleberry.o huckleberry.hex
echo "Burn Huckleberry Flash.  First, I need to shut down haptic interrupt on Sawyer. Press Enter to continue."
read x
i2ctransfer -y 1 w2@0x51 0x72 0x00
sleep 1
i2ctransfer -y 1 r1@0x51
echo "If result is 0xff, command is success."
echo "Burn Huckleberry Flash.  Press Enter to start burn."
read x
sudo avrdude -pt1634 -c linuxgpio -U flash:w:huckleberry.hex:i -C /trillsat/trillsat_huck_avrdude.conf
gpio -g mode 2 alt0
gpio -g mode 3 alt0
echo "Now I need to re-enable haptic interrupt on Sawyer. Press Enter to continue."
read x
i2ctransfer -y 1 w2@0x51 0x72 0x01
sleep 1
i2ctransfer -y 1 r1@0x51
echo "If result is 0xff, command is success."
sudo i2cdetect -y 1


