#ifndef CamJoysticks_INCLUDED
	#define CamJoysticks_INCLUDED

#include <bncs_script_helper.h>

#ifdef WIN32
	#ifdef DOEXPORT_SCRIPT
		#define EXPORT_SCRIPT __declspec(dllexport) 
	#else
		#define EXPORT_SCRIPT 
	#endif
#else 
	#define EXPORT_SCRIPT
#endif
 
class CamJoysticks : public bncs_script_helper
{
public:
	CamJoysticks( bncs_client_callback * parent, const char* path );
	virtual ~CamJoysticks();

	void buttonCallback( buttonNotify *b );
	int revertiveCallback( revertiveNotify * r );
	void databaseCallback( revertiveNotify * r );
	bncs_string parentCallback( parentNotify *p );
	void timerCallback( int );
	
private:
#define JOYSTICKS 10

	bncs_string m_myParam;
	bncs_string m_instance;
	
	bncs_config myVals;

	bncs_string Tally_Off;			// State for camera mimic block when camera has Inactive Tally 
	bncs_string Tally_On;			// State for camera mimic block when camera has Active Tally
	bncs_string defaultSourceName;	// Name of default source used when no joystick pressed
	bncs_string currentSourceName;	// Name of SDI source currently routed to vision monitor
	bncs_stringlist ccuList;
	bncs_string stateHi, stateLo;	// Hold the names of the statesheet settings for joystick pressed and released
	
	bncs_string pkgdata;			// Temporary storage used by tally revertive processing
	bncs_string p1, p2;				// Temporary storage used by tally revertive processing

	bool stickPressed;				// Set true if any of the joysticks are pressed
	bool sdiRegistered;				// Set true when SDI router register has been actioned
	bool gpiRegistered;				// Set true when GPI router has been registered
	bool tallyRegistered;			// Set true when Tally Infodriver has been registered
	bool wfmCopy;					// Set true if joystick selections should be copied to the waveform monitor
	bool firstPoll;					// Used to establish if the initial wfm monitor source has been found
	bool pollTimer;					// Shows first poll timer is running. Used by destructor code
	bool awaitTally;				// Flag that is cleared once tally infodriver has replied
	bool awaitGPI;					// Flag that is cleared once GPI device has replied
	bool opMode;					// Set true when all revertives needed for process activity are received
	bool tally1;					// Used during inital startup
	bool tally2;					// Used during inital startup
	bool sdi1;						// Used during inital startup
	bool sdi2;						// Used during inital startup
	bool jsr[JOYSTICKS];			// Used during startup to check all GPI revertives received

	int sdSDIdriver;				// Matrix driver number of SDI router
	int tallyInfodriver;			// Driver ID for the tally infodriver
	int matrixDestination;			// Output crosspoint no. that feeds Vision Monitor
	int wfmDestination;				// Output crosspoint no. that feeds Waveform Monitor
	int gpiDriverID;				// GPI driver number of GPI interface that has joystick tallies
	int gpiSlotFirst;				// GPI connection number for the first joystick
	int gpiSlotLast;				// GPI connection number for the last joystick

	int defaultSDIsourceID;			// SD-SDI source number routed when no joystick is pressed
	int currentSDIsourceID;			// SD-SDI source currently routed to the vision monitor
	int defWfmSource;				// SD-SDI source that was routed to waveform monitor before COPY mode activated
	int sum;						// Used by the routine that checks for a pressed joystick
	int idx;						// Used by "joystick pressed" function in evaluating leftmost pressed joystick
	int dummy;						// Used when getDev returns a device, but we do not need that data.

	int myCams[JOYSTICKS+1];
	int jstick[JOYSTICKS];			// Array of current joystick gpi settings. Values are 0 and 1

	// Local support functions
	void ccuRoute(void);

};


#endif // CamJoysticks_INCLUDED