/******************************************************************************
    Joystick.h : Definition of structures and Macros
    Author : JENTEY F.
    Last update : 06/03/97
                  20/11/97 DInput 5
******************************************************************************/
 
#ifndef	  _INO_MAIN_H
#define   _INO_MAIN_H
 
#include "cpa_std.h"
#include "DInput.h"
 
/**************************************/
#ifndef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else
#define CPA_EXPORT
#endif
#endif
/**************************************/
 
#if !defined(U64)
#define  INO_C_wNbMaxDevice          20
#define  INO_C_wNbMaxAxis            6
#else  /* U64, 4 joystick with only 2 axes */
#define  INO_C_wNbMaxDevice          4
#define  INO_C_wNbMaxAxis            2
#endif
 
 
/**************************************************************************
   Device type.
***************************************************************************/
#define  INO_C_uwUnknown             0
#define  INO_C_uwMouse		         (1 << 2)
#define  INO_C_uwKeyboard	         (1 << 3)
#define  INO_C_uwJoystick            (1 << 4)
#define  INO_C_uwAnyType             0xFF
 
/**************************************************************************
   Device status.
***************************************************************************/
#define  INO_C_ucConnected           1
#define  INO_C_ucAcquired            (1 << 1)
#define  INO_C_ucAccessError         (1 << 2)
#define  INO_C_ucGLDLink             (1 << 3)
#define  INO_C_ucActivated           (1 << 4)
 
/**************************************************************************
   Read mode for INO_fn_wReadAllDevices (short wMode).
***************************************************************************/
#define  INO_C_wAllDevices           1
#define  INO_C_wConnectedDevices     2
 
/**************************************************************************
   Key or button state.
***************************************************************************/
#define  INO_C_ucButtonDown          0x80
#define  INO_C_ucKeyDown             INO_C_ucButtonDown
#define  INO_C_ucKeyToggled          0x01
 
/**************************************************************************
  INO device common capabilities
***************************************************************************/
typedef struct stDevCaps
{
    unsigned char  m_ucNbButtons;
    unsigned long  m_ulCapsFlags;
 
} INO_tdstDevCaps;
 
/**************************************************************************
  INO device state
***************************************************************************/
typedef struct stDevState
{
    unsigned char   m_ucStatus;        /* Connected, acquired, link with GLD */
} INO_tdstDevState;
 
/**************************************************************************
  INO axis capabilities
***************************************************************************/
typedef struct stAxisCaps
{
    long m_lCenter;
    long m_lRange;
    long m_lThreshold;
 
} INO_tdstAxisCaps;
 
/**************************************************************************
  INO device structure
***************************************************************************/
#ifdef __cplusplus
struct stDevice;
typedef struct stDevice INO_tdstDevice, *INO_tdhDevice;
#endif /* __cplusplus*/
typedef short (*INO_fn_wMethod)(INO_tdstDevice);
 
#ifndef __cplusplus
typedef
#endif
struct stDevice
{
    unsigned short    m_uwType;
    INO_tdstDevCaps  *m_p_stCaps;          /* Device type specific caps */
    INO_tdstDevState *m_p_stState;         /* Device state, to cast acording to the device type */
    unsigned long     m_ulLastTimeCount;
    /* Historic */
    short             m_wHistoricSize;
  	short		      m_wHistoricHead;
	short             m_wRecordNumber;
    void             *m_pvHistoric;
    /* Device access methods */
    INO_fn_wMethod    m_pfnRead;
 
}
#ifdef __cplusplus
;
#else
 INO_tdstDevice, *INO_tdhDevice;
#endif /* __cplusplus*/
 
 
/* Device capabilities */
#define INO_M_uwType(hDev)       ((hDev)->m_uwType & 0xFF)
#define INO_M_uwSubType(hDev)    ((hDev)->m_uwType)
#define INO_M_ucNbButtons(hDev)  ((hDev)->m_p_stCaps->m_ucNbButtons)
#define INO_M_lNbKeys(hDev)      INO_M_lNbButtons(hDev)
#define INO_M_ulAxes(hDev)       ((hDev)->m_p_stCaps->m_ulCapsFlags & C_ulAxesMask)
 
/* Device state */
#define INO_M_wReadDevice(hDev)  ((hDev)->m_pfnRead(hDev))
#define INO_M_bIsConnected(hDev) (((hDev)->m_p_stState->m_ucStatus & INO_C_ucConnected) != 0)
#define INO_M_bIsFocused(hDev)   (((hDev)->m_p_stState->m_ucStatus & INO_C_ucAcquired) != 0)
#define INO_M_bDeviceReady(hDev) (((hDev)->m_p_stState->m_ucStatus & (INO_C_ucConnected | INO_C_ucAcquired)) \
                                                                      == (INO_C_ucConnected | INO_C_ucAcquired) )
 
 
/******************************************************************************
  All functions return 1 if Ok else 0
******************************************************************************/
 
#if defined(__cplusplus)
#define INO_EXTERN
extern "C"
{
#else
#define INO_EXTERN extern 
#endif
 
INO_EXTERN CPA_EXPORT short INO_fn_wInit(HINSTANCE hInstance, HWND hWindow);
INO_EXTERN CPA_EXPORT void  INO_fn_vRelease();
INO_EXTERN CPA_EXPORT INO_tdhDevice INO_fn_hCreateDevice(unsigned short uwType, short wHistoricSize);
INO_EXTERN CPA_EXPORT short INO_fn_wReleaseDevice(INO_tdhDevice hDevice);
INO_EXTERN CPA_EXPORT void  INO_fn_vResetDevice(INO_tdhDevice hDevice);
INO_EXTERN CPA_EXPORT short INO_fn_wGetNbDevices(unsigned short uwType);
 
INO_EXTERN CPA_EXPORT short INO_fn_wIsHandleValid(INO_tdhDevice hDev);
INO_EXTERN CPA_EXPORT short INO_fn_wInvalidateHandle(INO_tdhDevice *hDev);
 
INO_EXTERN CPA_EXPORT short INO_fn_wIsConnected(INO_tdhDevice hDev);
 
INO_EXTERN CPA_EXPORT short INO_fn_wReadAllDevices(unsigned short uwType, short wMode);
 
INO_EXTERN CPA_EXPORT short INO_fn_wActivateDevice(INO_tdhDevice hDev);
INO_EXTERN CPA_EXPORT short INO_fn_wDeactivateDevice(INO_tdhDevice hDev);
INO_EXTERN CPA_EXPORT void  INO_fn_vUpdateLastError(unsigned short uwErrorCode);
#if defined(__cplusplus)
#undef INO_EXTERN
}
#endif
 
 
#endif /* _INO_MAIN_H */
