// 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 ApplyButtons(DIJOYSTATE2 &state);48//unfortunate and unclean way to keep only one DirectInput instance around49static LPDIRECTINPUT8 getPDI();50//unfortunate and unclean way to keep track of the number of devices and the51//GUIDs of the plugged in devices. This function will only search for devices52//if none have been found yet and will only list plugged in devices53//also, it excludes the devices that are compatible with XInput54static void getDevices(bool refresh);55//callback for the WinAPI to call56static BOOL CALLBACK DevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);5758static unsigned int pInstances;59static std::vector<DIDEVICEINSTANCE> devices;60static Microsoft::WRL::ComPtr<IDirectInput8> pDI;61static bool needsCheck_;62static std::set<u32> ignoreDevices_;63int pDevNum;64Microsoft::WRL::ComPtr<IDirectInputDevice8> pJoystick;65DIJOYSTATE2 pPrevState;66bool analog;67BYTE lastButtons_[128]{};68WORD lastPOV_[4]{};69int last_lX_;70int last_lY_;71int last_lZ_;72int last_lRx_;73int last_lRy_;74int last_lRz_;75};7677struct DInputMetaDevice : public InputDevice {78public:79DInputMetaDevice();80int UpdateState() override;81private:82std::vector<std::unique_ptr<DinputDevice>> devices_;83size_t numDinputDevices_ = 0;84int checkCounter_ = 0;85};868788