#ifndef MOTORDLG_H
#define MOTORDLG_H

#ifndef WM_MODELESSEXIT
#define WM_MODELESSEXIT (WM_USER + 1)
#endif

#include "types.h"

class Motor;
class Axis;
class DataManager;
class CMotorIndicator;
class AtoD;

/////////////////////////////////////////////////////////////////////////////
// CMotorDlg dialog

class CMotorDlg : public CDialog
{
// Construction
public:
	CMotorDlg(CWnd* pParent, Axis *zAxis, Nat16 zid, Axis *rAxis, Nat16 rid, AtoD *pAtoD);
	~CMotorDlg();

	void UpdateStatus();
	void UpdateStopCode();
	void UpdateBitmap(UINT id, CBitmap & bitmap);
	void UpdateCmdOutputWnd(const char * text);

// Dialog Data
	//{{AFX_DATA(CMotorDlg)
	enum { IDD = IDD_MOTOR_DIALOG };
//	int		_jogIncrement;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMotorDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	Motor *_zmotor;
	Motor *_rmotor;
	Axis *_zaxis;
	Axis *_raxis;
	CString _allAxes;
	AtoD *_atod;
	CDMCWin *_servo;
	CString _ctrlCommand;
	CString _ctrlOutput;
	CMotorIndicator *_indicatorZ;
	CMotorIndicator *_indicatorR;
	int _nTimer;
	ConfigFile _plf;   // Saved position list file
	MBool _plChanged;
	MBool _lightsOn;
	MBool _cameraOn;
	MBool _lasersOn;
	MBool _dorissOn;

	float cntsTomm(long cnts); // convert motor counts to millimeters
	long  mmToCnts(float mm);  // convert millimeters to motor counts
	int ContinueHome();        // Cancel or continue the homing process

	// Generated message map functions
	//{{AFX_MSG(CMotorDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnJog();
	afx_msg void OnFindHome();
	afx_msg void OnStop();
	afx_msg void OnClose();
	afx_msg void OnIncrementSelect(UINT nID);
	afx_msg void OnSpeedSelect(UINT nID);
	afx_msg void OnPaint();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	Nat16 _zmotorID;
	Nat16 _rmotorID;
	CWnd *m_pDialog;
	CBitmap *_connectBitmap;
	DataManager *_pDataMgr;
	DATAITEM _zposDITEM;
	DATAITEM _zmmDITEM;
	DATAITEM _rposDITEM;
	DATAITEM _rmmDITEM;
	DATAITEM _tiltXDITEM;
	DATAITEM _tiltYDITEM;
	DATAITEM _tempDITEM;
	DATAITEM _pressDITEM;
	DATAITEM _humidDITEM;
	Boolean  _initHome;

	static Boolean _bitmapsLoaded;
	static CBitmap _flsBitmap;
	static CBitmap _rlsBitmap;
	static CBitmap _homeBitmap;
	static CBitmap _clrBitmap;
	static CBitmap _stopBitmap;
	static CBitmap _goBitmap;
	static CBitmap _rPosBitmap;
	static CBitmap _rNegBitmap;
	static CBitmap _zPosBitmap;
	static CBitmap _zNegBitmap;
	static CBitmap _ledOffBitmap;
	static CBitmap _ledOnBitmap;

public:
	// Desired Z position entered by the user
	long _jogZPosition;
	// Desired R Position entered by the user
	long _jogRPosition;
	afx_msg void OnBnClickedZneg();
	afx_msg void OnBnClickedZpos();
	afx_msg void OnBnClickedRpos();
	afx_msg void OnBnClickedRneg();
	afx_msg void OnEnChangeConInput();
	// User-entered increment per arrow-click
	float _increment;
	afx_msg void OnBnClickedStoreposition();
	afx_msg void OnBnClickedRecallposition();
	afx_msg void OnBnClickedDeleteposition();
	afx_msg void OnBnClickedLights();
	afx_msg void OnBnClickedCamera();
	afx_msg void OnBnClickedLasers();
	afx_msg void OnEnChangeIncrement();
	afx_msg void OnEnKillfocusIncrement();
	afx_msg void OnNMDblclkPositionlist(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedDoriss();
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif
