#!/bin/sh
#
# Script to make pixel live grab for n seconds
#
# Andrew J. Dean 19th Oct, 2000

# Check for appropriate input
if [ ! $1 ] 
	then 
	echo "Usage: $0 exposure(seconds)" 
	exit 1 
fi 

# Check pixel is ready
pixelreply=`pixel status`
if test $pixelreply != "READY"
	then
	echo "PixCel is not Ready, possibly not running"
	exit 1
fi

# set the livegrab exposure to zero
pixelreply=`pixel "exposure 0"`
if test $pixelreply != "0"
    then 
    echo "Could not set exposure to zero"
    exit 1
fi

echo Starting a $1 second live grab
pixelreply=`pixel live`
if ( test $pixelreply != "READING" ) && ( test $pixelreply != "BUSY" )
	then
	echo "Could not start the exposure"
	exit 1
fi

# Wait for the time requested, this command will fail if an invalid option is 
# entered, pixel stop will still be sent
sleep $1

count=0	
while ( test $pixelreply != "READY" )
do
	echo "Sending pixcel the stop command"
	pixelreply=`pixel stop`
	if (test $pixelreply != "READY")
		then
		sleep 3
	fi
	count=`expr $count + 1`	
	if (test $count -eq 20)
		then
		echo "PixCel refuses to be stopped, something has gone wrong!"
		exit 1
	fi
done

echo "Exposure completed"
# beep
exit 0







