//###################################################################################
//#						              Definition Of Class GloveObject								          #
//#						                Used To Handle a 5DT Glove								            #
//#						                          Author : 							                      #
//#						                      Aymeric SUTEAU									                #
//#						                       LISA - ANGERS									                #
//###################################################################################

#ifndef GLOVE_OBJECT
#define GLOVE_OBJECT

// Include Standard Libraries
#include <stdio.h>
#include <string>
#include <time.h>
#ifdef WIN32
#include <windows.h> // for Sleep
#else
#include <unistd.h>  // for usleep
#endif

// Include Glove Library
#include "..\fglove\fglove.h"

// Include Thread Library
#include "..\lib\ou_thread.h"
using namespace std;
using namespace openutils;

// Define constants
#define GESTURE_WITHOUT_THUMB 0
#define GESTURE_WITH_THUMB    1


// Class Object
class MyThread;
class GloveObject : public Thread
{
	// Public Methods and Variables
	public:
		// Variables for Sensors Values
		unsigned short *pValues;
		unsigned short *pMax;
		unsigned short *pMin;

    // Constructor / Destructor
		GloveObject();
		~GloveObject();

		// Getters
		fdGlove * GetGlove();
		char * GetPort();
		bool IsShowRaw();
		int GetGloveType();
		char * GetType();
		int GetGloveHand();
		char * GetHand();
		int GetNbrOfSensors();
		int GetGestureIndex();              // Return gesture index between 0 and 15 (thumb not handled) 
    int GetGestureWithThumbIndex();     // Return gesture index between 0 and 31 (thumb handled)
    std::string GetSerialNumber();
    bool GetCalibrationDone();
    bool GetInitValuesDone();
    bool GetInitDone();
    int GetUSBIndex();
    int GetGestureMode();

		// Setters
		void SetGlove(fdGlove *);
		void SetPort(char *);
		void SetShowRaw(bool);
		void SetGloveType(int);
		void SetType(char *);
		void SetGloveHand(int);
		void SetHand(char *);
		void SetNbrOfSensors(int);
		void SetGestureIndex(int);
    void SetGestureWithThumbIndex(int);
    void SetSerialNumber(std::string);
    void SetCalibrationDone(bool);
    void SetInitValuesDone(bool);
    void SetInitDone(bool);
    void SetUSBIndex(int);
    void SetGestureMode(int);

		// Init Glove on USB Port and Glove sensors values
		bool Init(int);
    void InitValues();

		// Close Glove
		int Close();

		// Calibrate Automatically (True) Or Manually (False) The Glove
		void AutoCalibrate(bool);

		// Set Callback
		void SetCallback();

		// Delete Callback
		void DeleteCallback();

		// Called by the Callback Function
		void UpdateGlove();

    // Thread Handling
    void run();
    bool isRunning;

	// Private Attributes
	private:
		fdGlove *pGlove;			  // Pointer to the Glove Object
		char *szPort;			      // COM/USB port
		bool bShowRaw;			    // Boolean to display either raw values or scaled ones
		int iGloveType;			    // Type of glove (index)
		char *szType;			      // Type of glove (string)
		int iGloveHand;			    // Hand Type of glove (index)
		char *szHand;			      // Hand Type of glove (string)
		int iNbrOfSensors;		  // Counter for the number of sensors
		int iGestureIndex;		  // Index of the current gesture (excluding the thumb)
    int iGestureTHIndex;	  // Index of the current gesture (including the thumb)
    //char *szSerialNumber;   // Serial number of the data glove
    std::string szSerialNumber;
    bool bCalibrationDone;  // Boolean to indicate the status of the calibration
    bool bInitValuesDone;   // Boolean to indicate the status of init values procedure
    bool bInitDone;         // Boolean to indicate the status of open glove procedure
    int iUSBIndex;          // Index of the USB port on which the data glove is opened
    int iGestureMode;       // Gesture mode : with or without taking into account thumb
};

#endif
