2020-06-23 07:47:46 +00:00
|
|
|
#pragma once
|
|
|
|
#include "ControllerSpec1.1.h"
|
|
|
|
#include "Button.h"
|
2020-07-15 11:10:20 +00:00
|
|
|
#include "DeviceNotification.h"
|
2020-07-01 03:37:55 +00:00
|
|
|
#include "N64Controller.h"
|
2021-02-28 21:32:50 +00:00
|
|
|
#include <Common/CriticalSection.h>
|
2020-06-23 07:47:46 +00:00
|
|
|
#define DIRECTINPUT_VERSION 0x0800
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <dinput.h>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class CDirectInput
|
|
|
|
{
|
2020-07-15 11:32:48 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CONFIG_THRESHOLD = 50,
|
2020-07-27 11:51:30 +00:00
|
|
|
MIN_AXIS_VALUE = -32767,
|
|
|
|
MAX_AXIS_VALUE = 32767,
|
2020-08-03 11:12:00 +00:00
|
|
|
AXIS_TOP_VALUE = MAX_AXIS_VALUE / 2,
|
|
|
|
AXIS_BOTTOM_VALUE = MAX_AXIS_VALUE + AXIS_TOP_VALUE,
|
2020-07-15 11:32:48 +00:00
|
|
|
RANGE_RELATIVE = 0x8000,
|
|
|
|
AI_AXE_POSITIVE = 0,
|
|
|
|
AI_AXE_NEGATIVE = 1,
|
|
|
|
THRESHOLD = 50,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AI_POV
|
|
|
|
{
|
|
|
|
AI_POV_UP = 0,
|
|
|
|
AI_POV_RIGHT = 1,
|
|
|
|
AI_POV_DOWN = 2,
|
|
|
|
AI_POV_LEFT = 3,
|
|
|
|
};
|
|
|
|
|
2020-06-23 07:47:46 +00:00
|
|
|
public:
|
|
|
|
enum ScanResult
|
|
|
|
{
|
|
|
|
SCAN_FAILED = 0x00,
|
|
|
|
SCAN_SUCCEED = 0x01,
|
|
|
|
SCAN_ESCAPE = 0x10,
|
|
|
|
};
|
|
|
|
|
|
|
|
CDirectInput(HINSTANCE hinst);
|
|
|
|
~CDirectInput();
|
|
|
|
|
|
|
|
void Initiate(CONTROL_INFO * ControlInfo);
|
2020-07-01 03:37:55 +00:00
|
|
|
void MapControllerDevice(N64CONTROLLER & Controller);
|
2020-06-23 07:47:46 +00:00
|
|
|
ScanResult ScanDevices(BUTTON & Button);
|
|
|
|
std::wstring ButtonAssignment(BUTTON & Button);
|
2020-07-27 07:33:35 +00:00
|
|
|
std::wstring ControllerDevices(const N64CONTROLLER & Controller);
|
2020-07-01 03:47:36 +00:00
|
|
|
bool IsButtonPressed(BUTTON & Button);
|
2020-07-15 11:32:48 +00:00
|
|
|
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
|
2020-07-01 03:47:36 +00:00
|
|
|
void UpdateDeviceData(void);
|
2020-07-15 11:10:20 +00:00
|
|
|
void DevicesChanged(void);
|
2020-06-23 07:47:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CDirectInput();
|
|
|
|
CDirectInput(const CDirectInput&);
|
|
|
|
CDirectInput& operator=(const CDirectInput&);
|
|
|
|
|
|
|
|
static BOOL CALLBACK stEnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
|
|
|
|
BOOL EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi);
|
2020-07-15 11:04:23 +00:00
|
|
|
ScanResult ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, uint8_t * KeyboardState, BUTTON & pButton);
|
2020-07-15 11:32:48 +00:00
|
|
|
ScanResult ScanGamePad(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, DIJOYSTATE & BaseState, BUTTON & pButton);
|
2020-07-01 03:47:36 +00:00
|
|
|
bool AcquireDevice(LPDIRECTINPUTDEVICE8 lpDirectInputDevice);
|
2020-07-15 11:10:20 +00:00
|
|
|
void RefreshDeviceList(void);
|
2020-07-15 11:32:48 +00:00
|
|
|
bool JoyPadPovPressed(AI_POV Pov, int32_t Angle);
|
2020-06-23 07:47:46 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPDIRECTINPUTDEVICE8 didHandle;
|
|
|
|
uint32_t dwDevType;
|
|
|
|
std::string InstanceName;
|
|
|
|
std::string ProductName;
|
2020-07-01 03:47:36 +00:00
|
|
|
union INPUTSTATE
|
|
|
|
{
|
|
|
|
DIJOYSTATE Joy;
|
|
|
|
DIMOUSESTATE2 Mouse;
|
|
|
|
uint8_t Keyboard[256];
|
|
|
|
} State;
|
2020-06-23 07:47:46 +00:00
|
|
|
} DEVICE;
|
|
|
|
|
|
|
|
struct GUIDComparer
|
|
|
|
{
|
|
|
|
bool operator()(const GUID & Left, const GUID & Right) const
|
|
|
|
{
|
|
|
|
return memcmp(&Left, &Right, sizeof(Right)) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef std::map<GUID, DEVICE, GUIDComparer> DEVICE_MAP;
|
|
|
|
|
2020-07-15 11:10:20 +00:00
|
|
|
DeviceNotification m_DeviceNotification;
|
2020-06-23 07:47:46 +00:00
|
|
|
DEVICE_MAP m_Devices;
|
2020-07-22 03:43:42 +00:00
|
|
|
CriticalSection m_DeviceCS;
|
2020-06-23 07:47:46 +00:00
|
|
|
HMODULE m_hDirectInputDLL;
|
|
|
|
LPDIRECTINPUT8 m_pDIHandle;
|
|
|
|
HINSTANCE m_hinst;
|
|
|
|
HWND m_hWnd;
|
|
|
|
};
|