//============================================================-
// ctimerw.h
// Header file for CONTEC API-TIMER(WDM)
//                                             CONTEC.Co.,Ltd.
//============================================================-

#ifndef __CTIM_H_DEFINED__
#define __CTIM_H_DEFINED__


typedef void (WINAPI *PTM_INTERVAL_CALLBACK)(short, WPARAM, LPARAM, void *);

//=========================================================
//	Type definition
//=========================================================
#define	TIM_USE_NG							0		// disable
#define	TIM_USE_OK							1		// enable
#define	TIM_TYPE_ONBOARD					0		// on board system timer 
#define	TIM_TYPE_SYSTEM						1		// system timer
#define	TIM_MEASURE_HIGH					0		// high accuracy
#define	TIM_MEASURE_NORMAL					1		// normal

#define	TIMM_INTERVAL						0x8900	// windows message number of interval timer

//================================================================
//	Error codes
//================================================================
#define	TIM_ERR_SUCCESS						0		// Normality completion
#define	TIM_ERR_INI_MEMORY					3		// Failed in the allocation of the memory
#define	TIM_ERR_INI_REGISTRY				4		// Failed in the access of registry
#define	TIM_ERR_SYS_RECOVERED_FROM_STANDBY	7		// Execute XxxResetDevice function prepared in each API-XXX(WDM) because the device has recovered from standby mode.

#define	TIM_ERR_DLL_INVALID_ID				10001	// Invalid ID was specified
#define	TIM_ERR_DLL_CALL_DRIVER				10002	// Driver can't be called
#define	TIM_ERR_DLL_CREATE_THREAD			10005	// Failed in the creation of the thread
#define	TIM_ERR_DLL_NOT_INITIALIZED			10010	// It is not initialized. Please confirm whether the initialization function has ended 

#define	TIM_ERR_DLL_NOT_FIND_DEVICE			10051	// The device that can be used is not found.
#define	TIM_ERR_DLL_BUFF_ADDRESS			10100	// Invalid data buffer address
#define	TIM_ERR_DLL_HWND					10200	// Window handle is invalid
#define	TIM_ERR_DLL_CALLBACK				10400	// Invalid callback address
#define	TIM_ERR_DLL_INVALID_TIME			10550	// It is outside the range where set time can be set.
#define	TIM_ERR_DLL_INVALID_TIMER_TYPE		10551	// It is outside the range where the timer type can be set.
#define	TIM_ERR_DLL_INVALID_MEASURE_MODE	10552	// It is outside the range where the measurement mode can be set.
#define	TIM_ERR_DLL_OVER_MAX_TIMER			10553	// It exceeded the maximum usable number of timers.

#define	TIM_ERR_SYS_MEMORY					20000	// It failed in memory allocation for the object preparation
#define	TIM_ERR_SYS_NOT_SUPPORTED			20001	// This function can't be used by this device.

//================================================================
//	Prototype definition
//================================================================
#ifdef __cplusplus
extern "C"{
#endif
long WINAPI TimInit(char *DeviceName, char *ProductName);
long WINAPI TimExit(void);
long WINAPI TimGetErrorString(long ErrorCode , char *ErrorString);
long WINAPI TimWait(unsigned long Microseconds);
long WINAPI TimCountStart(short *CountId);
long WINAPI TimCountStop(short CountId, unsigned long *Microseconds);
long WINAPI TimCountLap(short CountId, unsigned long *Microseconds);
long WINAPI TimCountReset(short CountId);
long WINAPI TimStartTimer(short *TimerId, unsigned long Microseconds, HWND hWnd);
long WINAPI TimTimerCallBackProc(short TimerId, PTM_INTERVAL_CALLBACK CallBackProc, void *Param);
long WINAPI TimStopTimer(short TimerId);
long WINAPI TimIsTimer(short TimerType, short *Enabled);
long WINAPI TimGetTimerType(short *TimerType);
long WINAPI TimSelectTimerType(short TimerType);
long WINAPI TimGetMeasureMode(short *MeasureMode);
long WINAPI TimSetMeasureMode(short MeasureMode);
#ifdef __cplusplus
};
#endif

#endif
