#if !defined(AFX_CONTROLDLG_H__017F6F99_67AB_11D3_80B1_00C04F60EB8B__INCLUDED_)
#define AFX_CONTROLDLG_H__017F6F99_67AB_11D3_80B1_00C04F60EB8B__INCLUDED_

#include "Pantilt.h"	// Added by ClassView
#include "fwxDCam.h"
#include "VideoWnd.h"
#include "fwxVideo.h"
#include "ControlDlg.h"
#include "fwx1394API.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ControlDlg.h : header file
//
#define _PROFILE 1

#define ISO_VIDEO_FRAMES 3

#define FRAMESIZE_MODE0 57600
#define FRAMESIZE_MODE1 153600
#define FRAMESIZE_MODE2 460800
#define FRAMESIZE_MODE3 614400
#define FRAMESIZE_MODE4 921600
#define FRAMESIZE_MODE5 307200

/////////////////////////////////////////////////////////////////////////////
// CControlDlg dialog

class CVideoProcess;
class CControlDlg;

typedef struct 
{
	LPVOID pFrameData;
	BYTE *pVideoFrame;
	ULONG nFrameSize;
	UINT nFrames;
	UINT nVideoMode;
	HANDLE hStopVideoEvent;
	HANDLE hFrameCompleteEvent[ISO_VIDEO_FRAMES];
	CVideoProcess* pVideoProcess;
	CControlDlg* pThis;
} SVideoThreadArg;

class CControlDlg : public CDialog
{
// Construction
public:
	int GetIris();
	BOOL SetIris(int val);
	
	SVideoThreadArg VideoThreadArg;
	BOOL StopVideo();
	BOOL StartVideo();
	BOOL Reconnect();
	BOOL ChangeColor(BOOL bColor);
	BOOL ChangeFrameRate(UINT nRate);
	BOOL ChangeVideoMode(UINT nMode);
	BOOL ChangeChannel(UINT nChannel);
	void CheckFeatures();
	void ChangeControl(CSliderCtrl *pSliderCtrl, int pos);
	BOOL SyncControls();

	void SetDCam(CfwxDCam *dcam);

	int GetGainValue();
	int GetGammaValue();
	int GetWhiteBalance();
	int GetShutterSpeed();
	int GetFocusValue();
	int GetBrightnessValue();
	int GetZoomValue();
    int GetSaturationValue();
	int GetHueValue();
    int GetExposure();
	int GetSharpness();

	int GetChannel();

	BOOL SetGainValue(int val);
	BOOL SetGammaValue(int val);
	BOOL SetWhiteBalance(int val);
	BOOL SetShutterSpeed(int val);
	BOOL SetBrightnessValue(int val);
	BOOL SetFocusValue(int val);
	BOOL SetZoomValue(int val);
    BOOL SetSaturation(int val);
	BOOL SetHue(int val);
    //BOOL SetExposure(int val);
	BOOL SetSharpness(int val);
	
	CControlDlg(CWnd* pParent = NULL);   // constructor
	//~CControlDlg(); //destructor

// Dialog Data
	//{{AFX_DATA(CControlDlg)
	enum { IDD = IDD_DLGCONTROL };
	CStatic	m_stIris;
	CSliderCtrl	m_slIris;
	CStatic	m_stSaturation;
	CSliderCtrl	m_slSaturation;
	CListBox	m_cbVideoMode;
	CListBox	m_cbFrameRate;
	CVideoWnd	m_VideoWnd;
	CStatic	m_stWhiteBalance;
	CStatic	m_stShutterSpeed;
	CStatic	m_stHue;
	CStatic	m_stGamma;
	CStatic	m_stGain;
	CStatic	m_stFocus;
	CStatic	m_stBrightness;
	CStatic	m_stZoom;
    CStatic m_stExposure;
    CStatic m_stSharpness;
	CSliderCtrl	m_slWhiteBalance;
	CSliderCtrl	m_slShutterSpeed;
	CSliderCtrl	m_slHue;
	CSliderCtrl	m_slGamma;
	CSliderCtrl	m_slGain;
	CSliderCtrl	m_slFocus;
	CSliderCtrl	m_slBrightness;
	CSliderCtrl	m_slZoom;
    CSliderCtrl m_slExposure;
    CSliderCtrl m_slSharpness;
	CButton	m_ckGScale;
	CStatic	m_stDCam;
	CEdit	m_editChannel;
	CStatic	m_stTS;
	CStatic	m_stTP;
	CStatic	m_stPS;
	CStatic	m_stPP;
	CEdit	m_editPS;
	CEdit	m_editTS;
	CEdit	m_editTP;
	CEdit	m_editPP;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CControlDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	static UINT ProcessVideoThread(LPVOID pParam);
	CPantilt PanTilt;
	CfwxDCam *pDCam;
	CString outPP;
	CString inPP;
	CString nPP;

	CString outTP;
	CString inTP;
	CString nTP;

	CString outPS;
	CString inPS;
	CString nPS;

	CString outTS;
	CString inTS;
	CString nTS;

	int nZoom;
	int nBrightness;
	int nFocus;
	int nGain;
	int nGamma;
	int nShutterSpeed;
	int nWhiteBalance;
    int nHue;
    int nSaturation;
    int nSharpness;
    int nExposure;
    int nIris;
	bool bGrayScale;

	int nShutDown;
	CVideoProcess * pVideoProcess;

	UINT nVideoMode;
	BYTE *pVideoFrame;
	ULONG nFrameSize[6];
	LPVOID pFrameData;
	CfwxDCam DCam;
	fwxGUID_t GUID;
	HANDLE hDeviceRemovedEvent;
	CString szTitle;
	BOOL bInitialized;
	BOOL bPaused;
	BOOL bReallocateIsoResources;
	int nRemovedTimerID;

#ifdef _PROFILE
	DWORD StartTick;
	DWORD StopTick;
#endif

	CWinThread *pVideoThread;
	HANDLE hStopVideoThreadEvent;
	HANDLE hFrameCompleteEvent[ISO_VIDEO_FRAMES];

	CString szZoom;
	CString szBrightness;
	CString szFocus;
	CString szGain;
	CString szGamma;
	CString szShutterSpeed;
	CString szWhiteBalance;
	CString szGrayScale;
    CString szHue;
    CString szSaturation;
    CString szExposure;
    CString szSharpness;
    CString szIris;

	int nChannel;

	int nZoomMax;
	int nZoomMin;
	int nBrightnessMax;
	int nBrightnessMin;
	int nFocusMax;
	int nFocusMin;
	int nGainMax;
	int nGainMin;
	int nGammaMax;
	int nGammaMin;
	int nShutterSpeedMax;
	int nShutterSpeedMin;
	int nWhiteBalanceMax;
	int nWhiteBalanceMin;
    int nHueMin;
    int nHueMax;
    int nSaturationMax;
    int nSaturationMin;
    int nExposureMax;
    int nExposureMin;
    int nSharpnessMax;
    int nSharpnessMin;
    int nIrisMax;
    int nIrisMin;

	// Generated message map functions
	//{{AFX_MSG(CControlDlg)
	afx_msg void OnBtnapp();
	afx_msg void OnBtnatp();
	afx_msg void OnBtnats();
	afx_msg void OnBtnaps();
	afx_msg void OnBtnstart();
	virtual BOOL OnInitDialog();
	afx_msg void OnBtnreset();
	virtual void OnOK();
	virtual void OnCancel();
	afx_msg void OnBtncpp();
	afx_msg void OnBtnctp();
	afx_msg void OnBtncps();
	afx_msg void OnBtncts();
	afx_msg void OnClose();
	afx_msg void OnSelchangeCbvideomode();
	afx_msg void OnBtnApply();
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnBtnstop();
	afx_msg void OnBtnpause();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CONTROLDLG_H__017F6F99_67AB_11D3_80B1_00C04F60EB8B__INCLUDED_)
