/* read report */

#define REPORT_ID_JOY			0xf1
#define REPORT_ID_KEY			0xf2
#define REPORT_ID_WWWKEY		0xf3
#define REPORT_ID_MOU			0xf4

#define REPORT_ID_CMD			0xf0
#define REPORT_ID_NAV_ID1		0x01
#define REPORT_ID_NAV_ID2		0x02
#define REPORT_ID_NAV_ID3		0x03

#define INPUT_TYPE_JOYSTICK		0x01
#define INPUT_TYPE_MOUSE		0x02
#define INPUT_TYPE_KEYBOARD		0x04
#define INPUT_TYPE_WWW			0x08
#define INPUT_TYPE_INFO			0x80
#define INPUT_TYPE_RBC_ALL		(INPUT_TYPE_JOYSTICK | INPUT_TYPE_MOUSE | INPUT_TYPE_KEYBOARD | INPUT_TYPE_WWW | INPUT_TYPE_INFO )

#define INPUT_TYPE_NAV_ID1		0x10
#define INPUT_TYPE_NAV_ID2		0x20
#define INPUT_TYPE_NAV_ID3		0x40
#define INPUT_TYPE_NAV_ALL		(INPUT_TYPE_NAV_ID1 | INPUT_TYPE_NAV_ID2 | INPUT_TYPE_NAV_ID3 )

#define INPUT_TYPE_ALL			(INPUT_TYPE_RBC_ALL | INPUT_TYPE_NAV_ALL)

#define INPUT_REPORT_NUM_JOY_AXE	8
#define INPUT_REPORT_NUM_JOY_BUTTON 8
#define INPUT_REPORT_NUM_KBD_CODE   232
#define INPUT_REPORT_NUM_WWW_CODE	16
#define INPUT_REPORT_NUM_MOU_BUTTON 5

#define KEY_BASE_MODIFIER	0xe0
#define KEY_MAX_KEY			6

#define JOY_OFFSET 360

#define MOU_MAX_VALUE 127
#define MOU_MAX_BTN	5

#define MOU_DELAY_QUICK 10
#define MOU_DELAY_LENT 1000
#define NAV_VALUE_QUICK 300
#define NAV_VALUE_LENT 2

#define NAV_MAX_VALUE 360
#define NAV_MAX_CARRE (NAV_MAX_VALUE*NAV_MAX_VALUE)
#define NAV_MAX_AXE 6
#define NAV_MAX_BTN 21

static UCHAR NAV_PACKET_LED[]		= { 0x21,0x09,0x04,0x02,0x00,0x00,0x02,0x00};
static UCHAR NAV_PACKET_INIT[]		= { 0x21,0x09,0x06,0x03,0x00,0x00,0x02,0x00};

static UCHAR NAV_PACKET_DESCRIPTOR[]		= { 0x81,0x06,0x00,0x22,0x00,0x00,0x0a,0x01};

#pragma pack(push, 1)


typedef struct _CONTROLLER_SPACENAV_INPUT_REPORT {

	UCHAR report_id;
	union {
		short Axe[3];
		UCHAR Btn[6];
	};

} CONTROLLER_SPACENAV_INPUT_REPORT, *PCONTROLLER_SPACENAV_INPUT_REPORT;

typedef struct _CONTROLLER_SPACENAV_TRAME {

	CONTROLLER_SPACENAV_INPUT_REPORT Trame[3];

} CONTROLLER_SPACENAV_TRAME, *PCONTROLLER_SPACENAV_TRAME;

typedef struct _CONTROLLER_JOY_INPUT_REPORT {
	UCHAR report_id;            /* Report ID: 1 */

	union {
		struct {
			SHORT x;            /* X:  0x00 - 0xff */
			SHORT y;            /* Y:  0x00 - 0xff */
			SHORT z;            /* Z:  0x00 - 0xff */
			SHORT rx;           /* RX: 0x00 - 0xff */
			SHORT ry;           /* RY: 0x00 - 0xff */
			SHORT rz;           /* RZ: 0x00 - 0xff */
			SHORT slider;       /* SL: 0x00 - 0xff */
			SHORT slider2;      /* SL: 0x00 - 0xff */
		//	SHORT throttle;     /* TH: 0x00 - 0xff */
		};

		struct {
			SHORT axis[INPUT_REPORT_NUM_JOY_AXE];      /* x, y, z, rx, ry, yz, slider, throttle */
		};
	};

	UCHAR Pov : 4;				/* H1: 0x00 - 0x07 */
	UCHAR Pov_Aling : 4;        /* Padding */

	UCHAR button;				/* BN: 0x00/0x01 */

} CONTROLLER_JOY_INPUT_REPORT;

typedef struct _CONTROLLER_KBD_INPUT_REPORT {
	UCHAR report_id;           

	UCHAR Modifier;

	UCHAR keys[6]; 

} CONTROLLER_KBD_INPUT_REPORT;


typedef struct _CONTROLLER_WWW_INPUT_REPORT {
	UCHAR report_id;            /* Report ID: 2 */

	UCHAR keys[(INPUT_REPORT_NUM_WWW_CODE + 7) / 8]; 
} CONTROLLER_WWW_INPUT_REPORT;

typedef struct _CONTROLLER_MOU_INPUT_REPORT {
	UCHAR report_id;            /* Report ID: 3 */

	CHAR x;                     /* x:     0x81 - 0x7f */
	CHAR y;                     /* y:     0x81 - 0x7f */
	CHAR wheel;                 /* wheel: 0x81 - 0x7f */

	UCHAR button;				/* 5 buttons */
} CONTROLLER_MOU_INPUT_REPORT;

typedef struct _CONTROLLER_INFO_INPUT_REPORT {
	UCHAR	report_id;           

	UCHAR	Ctrl;
	short	Profil_Id; 

} CONTROLLER_INFO_INPUT_REPORT;

typedef struct _CONTROLLER_INPUT_REPORT {
	CONTROLLER_JOY_INPUT_REPORT		joy;
	CONTROLLER_KBD_INPUT_REPORT		kbd;
	CONTROLLER_WWW_INPUT_REPORT		www;
	CONTROLLER_MOU_INPUT_REPORT		mou;
	CONTROLLER_INFO_INPUT_REPORT	Info;
	CONTROLLER_SPACENAV_TRAME		SpaceNav;

} CONTROLLER_INPUT_REPORT;

typedef struct _CONTROLLER_CMD_REPORT
{
	UCHAR command;
	union {
		UCHAR InfoByte; 
		short ProfilNum;
	};

} CONTROLLER_CMD_REPORT;

typedef struct _CONTROLLER_OUTPUT_REPORT
{
	UCHAR report_id;            /* Report ID: 1 */

	union {
		UCHAR OriByte[7]; 
		CONTROLLER_CMD_REPORT Cmd;
	};


} CONTROLLER_OUTPUT_REPORT, *PCONTROLLER_OUTPUT_REPORT;

typedef struct _RAW_INPUT {
	UCHAR ReportId;
	union {
		struct {
			SHORT Axe[3];
		};
		struct {
			UCHAR Btn[6]; 
		};
	};

} RAW_INPUT, *PRAW_INPUT;

typedef struct _RAW_OUTPUT {
	UCHAR ReportId;
	UCHAR InfoByte;
} RAW_OUTPUT, *PRAW_OUTPUT;


typedef struct _MOU_REPEAT
{
	ULONGLONG				next_time;
	ULONGLONG				wheel_time;
	ULONGLONG				wheel_wait;
	char					wheel_val;

} MOU_REPEAT;

typedef struct _LED_REPEAT
{
	BOOLEAN					On;
	ULONGLONG				first_time;
	ULONGLONG				next_time;
	ULONGLONG				TimeOn;
	ULONGLONG				TimeOff;
	ULONGLONG				HowLong;

	struct _LED_REPEAT		*NextLed;

} LED_REPEAT, *PLED_REPEAT;

typedef struct _SPECIAL_ACTION
{
	BOOLEAN			Running;
	ULONGLONG		MinTime;
	ULONGLONG		Start_Detect;
	ULONGLONG		Time_Action;

} SPECIAL_ACTION;

typedef struct _KEY_FLAG {

	UCHAR		Event;
	short		Fire_Delay;
	ULONGLONG	Last_Fire;

}KEY_FLAG;

typedef struct _KEYB_STATUS {

	KEY_FLAG	Key[INPUT_REPORT_NUM_KBD_CODE];	

} KEYB_STATUS;

typedef struct _NAV_STATUS {
	BOOLEAN		Last_On;
	short		Last_Val;
	ULONGLONG	Last_Press;
	ULONGLONG	Last_Release;
} NAV_STATUS;


#pragma pack(pop)