// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>20#include <set>21#include <InitGuid.h>22#include <wrl/client.h>23#define DIRECTINPUT_VERSION 0x080024#define DIRECTINPUT_RGBBUTTONS_MAX 12825#include "InputDevice.h"26#include <dinput.h>2728// TODO: This needs a major refactor into a DinputManager and individual devices inside.2930class DinputDevice {31public:32//instantiates device number devnum as explored by the first call to33//getDevices(), enumerates all devices if not done yet34DinputDevice(int devnum);35~DinputDevice();36int UpdateState();37static size_t getNumPads();38static void CheckDevices() {39needsCheck_ = true;40}4142static void SetDevicesToIgnore(std::set<u32> &&ignoreDevices) {43ignoreDevices_ = std::move(ignoreDevices);44}4546private:47void ReleaseAllKeys();48void ApplyButtons(DIJOYSTATE2 &state);49//unfortunate and unclean way to keep only one DirectInput instance around50static LPDIRECTINPUT8 getPDI();51//unfortunate and unclean way to keep track of the number of devices and the52//GUIDs of the plugged in devices. This function will only search for devices53//if none have been found yet and will only list plugged in devices54//also, it excludes the devices that are compatible with XInput55static void getDevices(bool refresh);56//callback for the WinAPI to call57static BOOL CALLBACK DevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);5859static unsigned int pInstances;60static std::vector<DIDEVICEINSTANCE> devices;61static Microsoft::WRL::ComPtr<IDirectInput8> pDI;62static bool needsCheck_;63static std::set<u32> ignoreDevices_;64int pDevNum;65Microsoft::WRL::ComPtr<IDirectInputDevice8> pJoystick;66DIJOYSTATE2 pPrevState;67bool analog;68BYTE lastButtons_[128]{};69WORD lastPOV_[4]{};70int last_lX_;71int last_lY_;72int last_lZ_;73int last_lRx_;74int last_lRy_;75int last_lRz_;76};7778struct DInputMetaDevice : public InputDevice {79public:80DInputMetaDevice();81int UpdateState() override;82private:83std::vector<std::unique_ptr<DinputDevice>> devices_;84size_t numDinputDevices_ = 0;85int checkCounter_ = 0;86};878889