#!/bin/sh

###################################################################
# Program: grabpics
# Purpose: Grab pictures from my Olympus C960-zoom 
# Author : Stuart Winter <stuart@polplex.co.uk>
# Date...: 11-May-2003
###################################################################
#
# Please note: These are not intended to be full programs/scripts
#              but rather a quick script to get the job done.
#              If you improve these please feel free to submit
#              your new version to me!
###################################################################

DIR=/root/digicampics

# Find camera.  We'll say the machine has 4 serial ports 
# although it probably only has 2.
SERIALPORT=
echo -n "Probing for camera ... "
for ((cnt=0; cnt<=4; cnt++)); do
    photopc -ql/dev/ttyS${cnt} list >/dev/null 2>&1
    if [ $? -eq 0 ]; then
       SERIALPORT=${cnt} # we found a camera 
       echo "/dev/ttyS${cnt}"
       cnt=4 # break out of for
    fi
done
# No camera found?
if [ -z "${SERIALPORT}" ]; then
   echo "unable to find camera on any ttyS0 - ttyS4"
   exit 2
fi

total_pics="$( photopc -l/dev/ttyS${SERIALPORT} list 2>/dev/null | grep -c .JPG )"
if [ "${total_pics}" -eq 0 ]; then
   echo "No JPEGs found on the camera"
   exit 3
fi

echo "Total number of pictures: ${total_pics}"
photopc -f3 -l/dev/ttyS${SERIALPORT} -s115200 image all ${DIR}/

echo "To erase pictures: photopc -l/dev/ttyS${SERIALPORT} -s115200 erase all"

#exit


