#include <Object.h>
#include <TString.h>
#include <ftdi.h>

class SylvacDial : public TObject
{
private:
	ftdi_context *ftdi;
	TString fSense;			// Measurement sense
	TString fFunCache;		// Function cache active?
	TString fUnit;				// Measurement unit active?
	TString fKeyLock;			// Keypad locked?
	TString fMulFac;			// Multiplication factor
	TString fPresetValue;	// Preset value
	TString fReference;		// Reference activ
	TString fHold;				// Status of hold function
	TString fTolLimits;		// Current tolerance limit values
	TString fLCal;				// Date of last calibration
	TString fNCal;				// Date of next calibration
	TString fMode; 			// Active mode (MIN, MAX, DELta, NORmal)
	TString fMainParams;		// Main instrument parameters
	TString fId; 				// Instrument identification code

	TString fBatt;				// battery status, BAT1 = ok, BAT0 low
	TString fFwVersion;		// Version No and date of firmware
	Bool_t fTolLimitsActiveState; 
	int fVerbose;				// Level of debug printout
	double fValue;				// Last read value 
	const static int MAXBUF = 1000;
	unsigned char fBuf[MAXBUF]; // Read buffer

public:
	SylvacDial();
	virtual ~SylvacDial();
	const char * GetSense();
	const char * GetFunCache();
	const char * GetUnit();
	const char * GetKeyLock();
	const char * GetMulFac();
	const char * GetPresetValue();
	const char * GetReference();
	const char * GetHold();
	const char * GetTolLimits();
	const char * GetLCal();
	const char * GetNCal();
	const char * GetMode();
	const char * GetMainParams();
	const char * GetId();
	
	const char * GetBatt();
	const char * GetFwVersion();
	
	const unsigned char * GetBuf() { return fBuf;};
	double GetValue();
	int SetSense(const char * sense);		// +/-
	int SetFunCache(const char * func);		// FCT0..9 A..F
	int SetUnit(const char * unit);			// mm/in
	int SetKeyLock(Bool_t lock);
	int SetMulFac(double mul);
	int SetPresetValue(double preset);
	int SetReference(const char * );			// REF1/Ref2
	int SetHold(Bool_t hold);
	int SetTolLimits(double x, double y);
	int ActivateTolLimits(Bool_t active = kTRUE);
	Bool_t GetTolLimitsActiveState() { return fTolLimitsActiveState; };
	int SetLCal(const char * date);
	int SetNCal(const char * date);
	int SetMode(const char * mode);
	
	void Reset();
	void SetVerbose(int verbose = 1){ fVerbose = verbose;};
	
private:	
	int GetData(TString *str, const char *tit);
	void PrintData(unsigned char * buf, int rsize);
	void ClearBuf() { for (int i=0; i < MAXBUF; i++) fBuf[i]=0;};
	ClassDef (SylvacDial, 0)
};