1 // Copyright (c) 2012- PPSSPP Project. 2 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, version 2.0 or later versions. 6 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License 2.0 for more details. 11 12 // A copy of the GPL 2.0 should have been included with the program. 13 // If not, see http://www.gnu.org/licenses/ 14 15 // Official git repository and contact information can be found at 16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. 17 18 #pragma once 19 20 #include <vector> 21 #include <InitGuid.h> 22 #define DIRECTINPUT_VERSION 0x0800 23 #define DIRECTINPUT_RGBBUTTONS_MAX 128 24 #include "InputDevice.h" 25 #include "dinput.h" 26 27 class DinputDevice final : 28 public InputDevice 29 { 30 public: 31 //instantiates device number devnum as explored by the first call to 32 //getDevices(), enumerates all devices if not done yet 33 DinputDevice(int devnum); 34 ~DinputDevice(); 35 virtual int UpdateState() override; 36 static size_t getNumPads(); CheckDevices()37 static void CheckDevices() { 38 needsCheck_ = true; 39 } 40 41 private: 42 void ApplyButtons(DIJOYSTATE2 &state); 43 //unfortunate and unclean way to keep only one DirectInput instance around 44 static LPDIRECTINPUT8 getPDI(); 45 //unfortunate and unclean way to keep track of the number of devices and the 46 //GUIDs of the plugged in devices. This function will only search for devices 47 //if none have been found yet and will only list plugged in devices 48 //also, it excludes the devices that are compatible with XInput 49 static void getDevices(bool refresh); 50 //callback for the WinAPI to call 51 static BOOL CALLBACK DevicesCallback( 52 LPCDIDEVICEINSTANCE lpddi, 53 LPVOID pvRef 54 ); 55 static unsigned int pInstances; 56 static std::vector<DIDEVICEINSTANCE> devices; 57 static LPDIRECTINPUT8 pDI; 58 static bool needsCheck_; 59 int pDevNum; 60 LPDIRECTINPUTDEVICE8 pJoystick; 61 DIJOYSTATE2 pPrevState; 62 bool analog; 63 BYTE lastButtons_[128]; 64 WORD lastPOV_[4]; 65 int last_lX_; 66 int last_lY_; 67 int last_lZ_; 68 int last_lRx_; 69 int last_lRy_; 70 int last_lRz_; 71 }; 72