#!/bin/bash

set -x

OCTOSCRIPT=/usr/local/bin/octoscript

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

sleep 1

$OCTOSCRIPT home xy
sleep 2
$OCTOSCRIPT jogx 75
# Display Clean Nozzle image and wait for screen tap
qiv --readonly --no_statusbar  --fullscreen --cycle ~/Pictures/clean_nozzle.png

