#!/bin/sh

if [ $1 = "source" ]; then
  echo "sourcing and exiting..."
. $HOME/esp/esp-idf/export.sh
  exit
fi

. $HOME/esp/esp-idf/export.sh
echo "cleaning up..."
idf.py fullclean
echo "done cleaning."
echo "building..."
idf.py build
echo "done building."
echo "flashing..."
idf.py -p /dev/ttyACM0 flash
echo "done flashing."
read -n 1 input -p "monitor serial output? [y/n]"
if [ $input = y ]; then
  echo "monitoring..."
  idf.py -p /dev/ttyACM0 monitor
else if [ $input = n ]; then
  exit
else
  echo "yes or no dude..."
fi
