#!/bin/bash

#usage ./cam_att_script

source ../config/dir_tree

CAM=$1
GS=$2
CAM=${CAM##-}
GS=${GS##-}

#Which camera?
if [ "$CAM" = '' ];then
CAM=`zenity --list \
    --text "Select an attribute" \
    --column "" --column "Camera" --column "Option" \
    --print-column=3 \
    --hide-column=3 \
    '' "Mono" "m" \
    '' "Color" "c"`
fi

#Get or set?
if [ "$GS" = '' ];then
GS=`zenity --list \
    --text "Do you want to read or set attributes?" \
    --column "" --column "" --column "Option" \
    --print-column=3 \
    --hide-column=3 \
    '' "Set" "s" \
    '' "Read" "g"`
fi

#Which attribute
ATT=`zenity --list \
    --height=400 \
    --text "Select an attribute" \
    --column "" --column "Attribute" --column "Option" \
    --print-column=3 \
    --hide-column=3 \
    '' "Start Acquistion" "Start" \
    '' "Stop Acquisition" "Stop" \
    '' "Exposure Value" "ExposureValue" \
    '' "Frame Rate" "FrameRate" \
    '' "Gain" "Gain" \
    '' "Trigger Mode" "FrameStartTriggerMode" \
    '' "Region Y" "RegionY"`
#Binning
#height

#Which value
#For starting and stopping aquisition
if [ "$ATT" = "Start" ]; then
	ATTVAL=""
fi
if [ "$ATT" = "Stop" ]; then
	ATTVAL=""
fi

#for Exposure Value
if [ "$ATT" = "ExposureValue" ]; then
    if [ "$GS" = "s" ]; then
	ATTVAL=`zenity --entry \
	    --title="Set Exposure" \
	    --text="Enter Exposure Value"`
    else
	ATTVAL="0"
    fi
fi

#for Frame Rate
if [ "$ATT" = "FrameRate" ]; then
    if [ "$GS" = "s" ]; then
	ATTVAL=`zenity --entry \
	    --title="Set FrameRate" \
	    --text="Enter Frame Rate (fps)"`
    else
	ATTVAL="0"
    fi
fi

#for Gain
if [ "$ATT" = "Gain" ]; then
    if [ "$GS" = "s" ]; then
	ATTVAL=`zenity --entry \
	    --title="Set Gain (1-10)" \
	    --text="Enter Gain"`
    else
	ATTVAL="0"
    fi
fi

#for Trigger MOde
if [ "$ATT" = "FrameStartTriggerMode" ]; then
    if [ "$GS" = "s" ]; then
       ATTVAL=`zenity --list \
	   --text "Select a Trigger Mode" \
	   --column "" --column "Attribute Value" --column "Option" \
	   --print-column=3 \
	   --hide-column=3 \
	   --height=300 \
	   '' "Freerun" "Freerun" \
	   '' "FixedRate" "FixedRate" \
	   '' "SyncIn1" "SyncIn1" \
	   '' "SyncIn2" "SyncIn2"`
    else
	ATTVAL="FixedRate"
    fi
fi

echo $ATT
#For region Y
if [ "$ATT" = "RegionY" ]; then
    if [ "$GS" = "s" ]; then
      	ATTVAL=`zenity --entry \
	    --title="Region Y (1-10)" \
	    --text="Enter the top value of the Y pixel in subregion"`
    else
	ATTVAL="1"
    fi
fi



CMD="./cam-attributes -$CAM -$GS --$ATT $ATTVAL"

echo $CMD

$CMD
