#!/bin/bash

#!/bin/bash
#
# octoscript-startup - run initial printer setup sequences
#
# (C) 2014 Aleph Objects, Inc. <code@alephobjects.com>
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

set -x
TEMP=61
BEDTEMP=45
OCTOSCRIPT=/usr/local/bin/octoscript

$OCTOSCRIPT connect

STATE=`$OCTOSCRIPT operation`
i=0
while [[ -z $STATE ]] ; do echo -e "\nOctoprint isn't running" ;
  let i=$i+1
    if [ $i -gt 30 ]
      then echo -e "\nStill not running after 30 seconds, aborting..."
      exit
   fi
  sleep 1
  STATE=`$OCTOSCRIPT operation`
done

STATE=`$OCTOSCRIPT operation`
i=0
while [ $STATE != "Operational" ]
do echo -e "\nOctoprint isn't operational" ;
  let i=$i+1
    if [ $i -gt 30 ]
      then echo -e "\nStill not operational after 30 seconds, aborting..."
      exit
   fi
  sleep 1
  STATE=`$OCTOSCRIPT operation`
done

$OCTOSCRIPT bedtemp $BEDTEMP &
$OCTOSCRIPT temp $TEMP &

# Really need MAX endstops for Z here...
$OCTOSCRIPT home xy 
sleep 3
$OCTOSCRIPT jog 150 150 0

