/*************************************************************************\
* "$RCSfile: CFeature.hpp,v $"                                            *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2011/10/20 07:46:38 $                      *
*     by                $Author: schluckebier $
*     Revision        : $Revision: 1.20 $                                 *
\*************************************************************************/
/*! \file CFeature.hpp
*	\brief Header CFeature Class
**************************************************************************/

#include "pfcam.h"

#define MAX_PROPNAME 32

//! Camera property
typedef struct sPROPERTY
{
	char Name[MAX_PROPNAME];	//!< Property name
	PFValue Value;				//!< Property value
	PFValue Min;				//!< Minimum value
	PFValue Max;				//!< Maximum value
} PROPERTY;

/*************************************************************************/
/*! @brief Camera and "frame-grabber" feature handling class.

	Provides the interface to camera and "frame-grabber" settings and
	resolves their dependencies. Some changes of sensor module settings
	make it necessary to change "frame-grabber" settings also and vice a
	versa. Every instance of CFeature handles one camera property.
**************************************************************************/
class CFeature
{
friend class CPSApp;
friend class CDlgCam;
friend class CDlgApp;
friend class CCamFeatures;

public:
	//! Constants
	enum eCONST
	{
		MAXPROPERTIES = 128	//!< Maximum numbers of properties
	};

	//! Constructor
	CFeature(const char *pName, bool bIsOnlyCamProperty, bool bIsOnlyFGProperty, int ScaleFactor = 1000);
	//! Destructor
	virtual ~CFeature() {}
	virtual int UpdateValue(Config *pConfig = NULL);
	void Event();
	int  GetValue();

	//! Returns a pointer to the name of the feature
	const char *GetName() const { return m_Name; }
	//! Returns the value string of the feature
	char *GetValueStr() { return m_ValueStr; }
	//! Gets the minimum allowed value
	int GetMin() const { return m_Min; }
	//! Gets the maximum allowed value
	int GetMax() const { return m_Max; }
	//! Gets the scale factor of the feature
	int GetScaleFactor() const { return m_ScaleFactor; }
	//! Gets the current value of the feature
	int GetMValue() const { return m_Value; }
	//! Sets the value of the feature
	void SetValue(int Val) { m_Value = Val; UpdateValue(); }
	//! Tells if feature is available from connected camera
	int GetIsAvailable() const { return m_bIsAvailable; }

protected:
	int   Init();
	void  ReadValueFromCamera();
	int   WriteValueToCamera();

	class CPSApp *m_pApp;		//!< Pointer to the application for accessing the frame-grabber parameters
	char  m_Name[32];			//!< Name of the feature
	char  m_ValueStr[32];		//!< Value of the feature if the type is \p PF_STRING
	char  m_ModeValues[256];	//!< String to the modes names of a feature
	char  m_Buffer;				//!< Value of the feature if the type is \p PF_BUFFER
	int   m_Value;				//!< Value of the feature
	int   m_Min;				//!< Minimum allowed value
	int   m_Max;				//!< Maximum allowed value
	int   m_StateIniParam;		//!< Feature is enabled or disabled from Param in INI file
	int   m_Port;				//!< Port of the COM interface of the camera module
	int   m_ScaleFactor;		//!< For handling float as integer, \p m_Value is multiplied with this factor
	bool  m_bInactive;			//!< State of the feature
	bool  m_bIsOnlyCamProperty;	//!< Camera module feature only and there is no dependency between FG and Cam
	bool  m_bIsOnlyFGProperty;	//!< FG feature only and there is no dependency between FG and Cam
	bool  m_bIsVolatile;		//!< Value is changed without user interaction
	bool  m_bIsAvailable;		//!< feature is supported from connected camera
	TOKEN m_Token;				//!< TOKEN of Property
	PropertyType m_PropertyType;//!< "mode", "float", "int", etc.
	Config *m_pTempConf;		//!< Temporary configuration object
};

/*************************************************************************/
/*! @brief Camera and "frame-grabber" \e window feature handling class.

	It inherits the properties of CFeature but has a different UpdateValue()
	function, because the frame-grabber has to be stopped before changing
	the value on the camera module and restarted after that.
**************************************************************************/
class CFeatureWindow : public CFeature
{
public:
	CFeatureWindow(const char *pName, bool bIsOnlyCamProperty, bool bIsOnlyFGProperty, int ScaleFactor = 1000);
	int UpdateValue(Config *pConfig = NULL);
};

/*************************************************************************/
/*! @brief Camera and "frame-grabber" \e trigger feature handling class.

	The trigger mode and source have to be set inside the camera module
	and the DSP interface FPGA.
**************************************************************************/
class CFeatureTrigger : public CFeature
{
public:
	CFeatureTrigger(const char *pName, bool bIsOnlyCamProperty, bool bIsOnlyFGProperty, int ScaleFactor = 1000);
	int UpdateValue(Config *pConfig = NULL);
};

/*************************************************************************/
/*! @brief Camera and "frame-grabber" \e resolution feature handling class.

	It inherits the properties of CFeature but has a different UpdateValue()
	function, because the FG has to be stopped before changing the value
	on the camera module and restarted after that.
**************************************************************************/
class CFeatureResolution : public CFeature
{
public:
	CFeatureResolution(const char *pName, bool bIsOnlyCamProperty, bool bIsOnlyFGProperty, int ScaleFactor = 1000);
	int UpdateValue(Config *pConfig = NULL);
	void CalcCameraModel();

protected:
	void UpdateCamPixelFormat();
	int m_CameraModel;	//!< For handling one and two tap camera modules
};

/*************************************************************************/
