#ifndef _HYUSBMIFARE_API_H
#define _HYUSBMIFARE_API_H

//----------------------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif

#define	GET_PID_COMMAND							0xF4
#define FLUSH_STATISTIC_COMMAND					0xDC	//Flush Statistic
#define GET_KEY_PRESSDOWN_COUNT_COMMAND			0xD8
#define GET_KEY_PRESSDOWN_COUNTWITHMAX_COMMAND	0xD9
#define GET_MSRGOODBAD_COUNT_COMMAND			0xDA
#define GET_FIRMWARE_COMMAND					0xB0

#define	HY_SUCCESS					0x00
#define	HY_KBMODEL_NOT_FOUND		0x2F
#define HY_NOKEYINDEX_FOUND			0x2E
#define	HY_CHECKSUM_ERR				0xF0		// Checksum error
#define	HY_COM_LINE_ERR				0xF2		// Communication error
//#define	HY_MEM_FAIL					0x09		// Memory fail
//#define	HY_EEPROM_MISSING			0x0A		// The EEPROM is missing

#define	HY_OVERLIMIT				0xE8

#define	HY_INIT_FAIL				0xE1		// Fail to initialize the usb device
#define	HY_SEND_FAIL				0xE2		// Fail to send the command to the device
#define	HY_TIMEOUT_ERR				0xE3		// Fail to receive the response from the device
#define	HY_FEATURE1_ERR				0xE4		// USB commmunication error
#define	HY_FEATURE2_ERR				0xE5		// USB commmunication error
#define	HY_INVALID_PARA				0xE6		// Invalid parameter
#define	HY_RECV_FAIL				0xE7
#define	HY_UNKNOWN_ERR				0xEF
#define HY_NO_FILE					0x60
#define HY_CANNOT_OPEN_FILE			0x61
#define	HY_EXE_INVALID				0x62
#define HY_EXE_FILE_NOT_FOUND		0x63
#define HY_PATH_NOT_FOUND			0x64


#define TOTAL_MODELS	1
#define	MODEL_S66A		0


typedef struct model_prop 
{	
	int nPID;	
	int nTotalKeys;	
	BOOL bMsrSupport;	
	char sModelName[16];	
	byte pbKeyIndex[256];	// max. no. of keys is 256
} model_prop;


/*	
Function:	check the Heng Yu USB keyboard is connected or not
Parameter:	
	
Return:		0x01	=> connected
			0x00	=> not connected
*/
BOOL WINAPI IsUsbConnected(void);

/*	
Function:	Get Product ID
Parameter:	
	pModelProp - return the model structure
Return:		0x00 => success
			0xE1 => function initial fail 
			0xE2 => send command fail
			0xE6 => Invalid input parameter
			0xE7 => received command fail
			0xF0 => Checksum error
			0xF1 => Invalid command
			0xFB => Length error
*/
int WINAPI GetKbModel(model_prop *pModelProp);
/*
Function:	Flush the statistic of keys to flash
Parameter:	void
Return:		0x00 => success
			0xE1 => function initial fail (e.g. usb initialization fail)
			0xE2 => send command fail
			0xE7 => received command fail
			0xF0 => Checksum error
			0xF1 => Invalid command
			0xFB => Length error
*/

int WINAPI FlushKbEEPROM(void);

/*
Function:	Get the Count of the key Press Down 
Parameter:	
		nKeyIndex - Input. key index
		pCount - output. the count of the press key down
Return:		0x00 => success
				0xE1 => function initial fail (e.g. pCount is NULL pointer or usb initialization fail)
				0xE2	 => send command fail
				0xE6 => invalid input parameters
				0xE7 => received command fail
				0xF0 => Checksum error
				0xF1 => Invalid command
				0xFB => Length error
*/
int WINAPI GetPressedCount(int nKeyIndex,int *pCount);

/*
Function:	Get the Max Count of the key Press Down and key position
Parameter:	
		pKeyPos - output. key position
		pCount - output. the count of the press down
Return:		0x00 => success
			0x2F => keyboard model is not found
			0x2E => No Key Index found
			0xE1 => function initial fail 
			0xE2 => send command fail
			0xE6 => invalid input parameters
			0xE7 => received command fail
			0xF0 => Checksum error
			0xF1 => Invalid command
			0xFB => Length error
*/
int WINAPI GetMaxPressedCount(int *pKeyPos,int *pCount);

/*
Function:	Get the Count of the Good and Bad swipe 
Parameter:	
		pTotalCount - output. total count of bad and good swipe
		pSuccessCount - output. good msr count. Then bad msr count is (totalcount - success)
Return:		0x00 => success
			0xE1 => function initial fail (e.g. pTotalCount or pSuccessCount is NULL pointer or usb initialization fail)
			0xE2	 => send command fail
			0xE6 => invalid input parameters
			0xE7 => received command fail
			0xF0 => Checksum error
			0xF1 => Invalid command
			0xFB => Length error
*/
int WINAPI GetSwipeCount(int *pTotalCount, int *pSuccessCount);


/*
Function:
	Get the firmware version of the device

Parameter:
	sVer -	[output] the firmware version will be copied to this character pointer
	        {CAUCTION: 25 bytes should be enough to get the version from the pinpad.}

Return:
	If the function succeeds, the return value is zero (HY_SUCCESS).
	If the function fails, the return value is non-zero.
*/	 
int WINAPI GetFirmware(char *sVer);

/*
Function:
	Update Key Map

Parameter:
	sExePath - Matrix maker executable absolute path
	sKeymapPath - KeyMap file absolute path
	sLogPath - log file absolute path

Return:
	If the function succeeds, the return value is zero (HY_SUCCESS).
	If the function fails, the return value is non-zero.
*/	 
int WINAPI UpdateKeyMap(char *sExePath,char *sKeymapPath, char *sLogPath);

/*
Function:
	Update Firmware using USB or PS2

Parameter:
	sExePath - firmware downloader executable file absolute path
	sFirmwarePath - Firmware file absolute path
	sLogPath - log file absolute path

Return:
	If the function succeeds, the return value is zero (HY_SUCCESS).
	If the function fails, the return value is non-zero.
*/	 

int WINAPI UpdateFirmware(char *sExePath,char *sFirmwarePath, char *sLogPath);


/*
Function:
	GetResultofUpdate

Parameter:

	sLogPath - log file absolute path
	sResultMsg - content of log file
	latestUpdateTime - latest modification time

Return:
	If the function succeeds, the return value is zero (HY_SUCCESS).
	If the function fails, the return value is non-zero.
*/	 
int WINAPI GetResultofUpdate(char *sLogPath, char *sResultMsg, time_t *latestUpdateTime);




#ifdef __cplusplus
}
#endif


#endif