//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS2_USBGuncon2.h
//
// Created by Neil Massey.
//
// Copyright (c) 2002 Rebellion. All rights reserved.
//
// Derived class to handle USB Namco Guncon2 controller
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PS2_USBGUNCON2_H___
#define ___ASURA_PS2_USBGUNCON2_H___ 1

#include "Input/Asura_PS2_USBDevice.h"

class Asura_PS2_GC2_Gun_Adjust
{
public:
	float	m_fXOffset, m_fYOffset;
	int		m_iH, m_iV;
	int		m_iMonitorType;
	int		m_iHdsw;
};

enum {
	ASURA_GUNCON_SYNC_WAIT	 = 0,
	ASURA_GUNCON_SYNC_NOWAIT = 1,
	ASURA_GUNCON_COPY_PREV_UPDATE = 2,
	};

class Asura_PS2_USBGuncon2 : public Asura_PS2_USBDevice
{
public:
	Asura_PS2_USBGuncon2(int iDeviceNumber);
	virtual ~Asura_PS2_USBGuncon2(void);

	virtual void	   Update(void);
	virtual void	   Translate(u_char *piAsuraInputBufferOffset, float *piAsuraAxis_BufferOffset);
	virtual bool	Available(void);
    static  void       Initialise(void);
    void               SetCalibration(float fData1, float fData2);

	// (MH - 03.06.2003) reinstated
	static int  GetNumberOfGuncons(void) {return s_iNumberOfGuncon2s;}
    // (NRM - 12.12.2003) set the device for the player - usually by detecting fire on one gun
    // and assigning this during calibration
    static void  SetDeviceNumber(int iPlayer, int iDevice);

protected:
    Asura_PS2_GC2_Gun_Adjust m_xCalibrateData;

private:
    static void UpdateAllGuncon2s(void);
    static void TranslateControlData(const int iDeviceNumber);

    // Static data
    static ASURA_PS2_USB_PHASE s_eCurrentPhase;
    static ASURA_PS2_USB_PHASE s_eNextPhase;
    static int                 s_iNumberOfGuncon2s;
    static int                 s_iCurrentGuncon;
    static int                 s_iGunconOffset[2];

    // Guncon2 data
	enum {GUNCON_DEVICE_BUFFER_SIZE   = 0x80, 
		  GUNCON_LOCATION_BUFFER_SIZE = 0x80,
		  GUNCON_READ_DATA_SIZE		  = 0x80};
	// Buffers used to communicate with the hardware
	static u_char s_aucGunconDeviceBuffer[GUNCON_DEVICE_BUFFER_SIZE] __attribute__((aligned(64)));
	static u_char s_aucGunconLocationBuffer[GUNCON_LOCATION_BUFFER_SIZE] __attribute__((aligned(64)));
	static u_char s_aucGunconTranslateData[GUNCON_DEVICE_BUFFER_SIZE] __attribute__((aligned(64)));;

    // Data to read into - one per gun
	char		  *m_pucGunconReadData;
};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PS2_USBGUNCON2_H___
