Skip to content

Commit 626be05

Browse files
Core: Track names of connected pad devices.
Rather than just that it's a pad. This tries to get the identifier if possible.
1 parent 21bf41e commit 626be05

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

Core/KeyMap.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ KeyMapping g_controllerMap;
4040
// Incremented on modification, so we know when to update menus.
4141
int g_controllerMapGeneration = 0;
4242
std::set<std::string> g_seenPads;
43+
std::map<int, std::string> g_padNames;
4344
std::set<int> g_seenDeviceIds;
4445

4546
bool g_swapped_keys = false;
@@ -761,8 +762,9 @@ bool HasBuiltinController(const std::string &name) {
761762
return IsOuya(name) || IsXperiaPlay(name) || IsNvidiaShield(name) || IsMOQII7S(name) || IsRetroid(name);
762763
}
763764

764-
void NotifyPadConnected(const std::string &name) {
765+
void NotifyPadConnected(int deviceId, const std::string &name) {
765766
g_seenPads.insert(name);
767+
g_padNames[deviceId] = name;
766768
}
767769

768770
void AutoConfForPad(const std::string &name) {

Core/KeyMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace KeyMap {
153153
void SwapAxis();
154154
void UpdateNativeMenuKeys();
155155

156-
void NotifyPadConnected(const std::string &name);
156+
void NotifyPadConnected(int deviceId, const std::string &name);
157157
bool IsNvidiaShield(const std::string &name);
158158
bool IsNvidiaShieldTV(const std::string &name);
159159
bool IsXperiaPlay(const std::string &name);

SDL/SDLJoystick.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Common/System/System.h"
99

1010
#include "Core/Config.h"
11+
#include "Core/KeyMap.h"
1112
#include "SDL/SDLJoystick.h"
1213

1314
using namespace std;
@@ -54,11 +55,12 @@ void SDLJoystick::setUpControllers() {
5455
}
5556

5657
void SDLJoystick::setUpController(int deviceIndex) {
58+
static constexpr int cbGUID = 33;
59+
char pszGUID[cbGUID];
60+
5761
if (!SDL_IsGameController(deviceIndex)) {
5862
cout << "Control pad device " << deviceIndex << " not supported by SDL game controller database, attempting to create default mapping..." << endl;
59-
int cbGUID = 33;
60-
char pszGUID[cbGUID];
61-
SDL_Joystick* joystick = SDL_JoystickOpen(deviceIndex);
63+
SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex);
6264
if (joystick) {
6365
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), pszGUID, cbGUID);
6466
// create default mapping - this is the PS3 dual shock mapping
@@ -73,13 +75,20 @@ void SDLJoystick::setUpController(int deviceIndex) {
7375
} else {
7476
cout << "Failed to get joystick identifier. Read-only device? Control pad device " + std::to_string(deviceIndex) << endl;
7577
}
78+
} else {
79+
SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex);
80+
if (joystick) {
81+
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), pszGUID, cbGUID);
82+
SDL_JoystickClose(joystick);
83+
}
7684
}
7785
SDL_GameController *controller = SDL_GameControllerOpen(deviceIndex);
7886
if (controller) {
7987
if (SDL_GameControllerGetAttached(controller)) {
8088
controllers.push_back(controller);
8189
controllerDeviceMap[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller))] = deviceIndex;
8290
cout << "found control pad: " << SDL_GameControllerName(controller) << ", loading mapping: ";
91+
KeyMap::NotifyPadConnected(deviceIndex, std::string(pszGUID) + ": " + SDL_GameControllerName(controller));
8392
auto mapping = SDL_GameControllerMapping(controller);
8493
if (mapping == NULL) {
8594
//cout << "FAILED" << endl;

UI/NativeApp.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,12 @@ void NativeRender(GraphicsContext *graphicsContext) {
11761176
}
11771177

11781178
void HandleGlobalMessage(const std::string &msg, const std::string &value) {
1179+
int nextInputDeviceID = -1;
1180+
if (msg == "inputDeviceConnectedID") {
1181+
nextInputDeviceID = parseLong(value);
1182+
}
11791183
if (msg == "inputDeviceConnected") {
1180-
KeyMap::NotifyPadConnected(value);
1184+
KeyMap::NotifyPadConnected(nextInputDeviceID, value);
11811185
}
11821186
if (msg == "bgImage_updated") {
11831187
if (!value.empty()) {
@@ -1419,7 +1423,6 @@ bool NativeAxis(const AxisInput &axis) {
14191423
}
14201424

14211425
void NativeMessageReceived(const char *message, const char *value) {
1422-
// We can only have one message queued.
14231426
std::lock_guard<std::mutex> lock(pendingMutex);
14241427
PendingMessage pendingMessage;
14251428
pendingMessage.msg = message;

Windows/DinputDevice.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "Common/Input/InputState.h"
2525
#include "Common/Input/KeyCodes.h"
26+
#include "Common/StringUtils.h"
2627
#include "Common/System/NativeApp.h"
2728
#include "Core/Config.h"
2829
#include "Core/HLE/sceCtrl.h"
@@ -57,8 +58,6 @@ static const int dinput_buttons[] = {
5758
NKCODE_BUTTON_16,
5859
};
5960

60-
static float NormalizedDeadzoneFilter(short value);
61-
6261
#define DIFF (JOY_POVRIGHT - JOY_POVFORWARD) / 2
6362
#define JOY_POVFORWARD_RIGHT JOY_POVFORWARD + DIFF
6463
#define JOY_POVRIGHT_BACKWARD JOY_POVRIGHT + DIFF
@@ -152,6 +151,11 @@ DinputDevice::DinputDevice(int devnum) {
152151
return;
153152
}
154153

154+
wchar_t guid[64];
155+
if (StringFromGUID2(devices.at(devnum).guidProduct, guid, ARRAY_SIZE(guid)) != 0) {
156+
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0 + pDevNum, StringFromFormat("%S: %S", devices.at(devnum).tszProductName, guid));
157+
}
158+
155159
if (FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) {
156160
pJoystick->Release();
157161
pJoystick = NULL;

Windows/XinputDevice.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#include <algorithm>
55

66
#include "Common/System/NativeApp.h"
7-
#include "Core/Config.h"
87
#include "Common/CommonWindows.h"
98
#include "Common/Log.h"
9+
#include "Common/StringUtils.h"
1010
#include "Common/TimeUtil.h"
1111
#include "Common/Input/InputState.h"
1212
#include "Common/Input/KeyCodes.h"
1313
#include "XinputDevice.h"
14+
#include "Core/Config.h"
1415
#include "Core/Core.h"
1516
#include "Core/KeyMap.h"
1617
#include "Core/HLE/sceCtrl.h"
@@ -21,11 +22,21 @@ static double newVibrationTime = 0.0;
2122

2223
#if !PPSSPP_PLATFORM(UWP)
2324

25+
struct XINPUT_CAPABILITIES_EX {
26+
XINPUT_CAPABILITIES Capabilities;
27+
WORD vendorId;
28+
WORD productId;
29+
WORD revisionId;
30+
DWORD a4; //unknown
31+
};
32+
2433
typedef DWORD (WINAPI *XInputGetState_t) (DWORD dwUserIndex, XINPUT_STATE* pState);
2534
typedef DWORD (WINAPI *XInputSetState_t) (DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
35+
typedef DWORD (WINAPI *XInputGetCapabilitiesEx_t) (DWORD unknown, DWORD dwUserIndex, DWORD flags, XINPUT_CAPABILITIES_EX *pCapabilities);
2636

2737
static XInputGetState_t PPSSPP_XInputGetState = nullptr;
2838
static XInputSetState_t PPSSPP_XInputSetState = nullptr;
39+
static XInputGetCapabilitiesEx_t PPSSPP_XInputGetCapabilitiesEx = nullptr;
2940
static DWORD PPSSPP_XInputVersion = 0;
3041
static HMODULE s_pXInputDLL = 0;
3142
static int s_XInputDLLRefCount = 0;
@@ -83,6 +94,10 @@ static int LoadXInputDLL() {
8394
return -1;
8495
}
8596

97+
if (PPSSPP_XInputVersion >= ((1 << 16) | 4)) {
98+
PPSSPP_XInputGetCapabilitiesEx = (XInputGetCapabilitiesEx_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)108);
99+
}
100+
86101
return 0;
87102
}
88103

@@ -187,10 +202,15 @@ int XinputDevice::UpdateState() {
187202
}
188203

189204
void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state, XINPUT_VIBRATION &vibration) {
190-
static bool notified = false;
191-
if (!notified) {
192-
notified = true;
193-
KeyMap::NotifyPadConnected("Xbox 360 Pad");
205+
static bool notified[XUSER_MAX_COUNT]{};
206+
if (!notified[pad]) {
207+
notified[pad] = true;
208+
XINPUT_CAPABILITIES_EX caps;
209+
if (PPSSPP_XInputGetCapabilitiesEx != nullptr && PPSSPP_XInputGetCapabilitiesEx(1, pad, 0, &caps) == ERROR_SUCCESS) {
210+
KeyMap::NotifyPadConnected(DEVICE_ID_XINPUT_0 + pad, StringFromFormat("Xbox 360 Pad: %d/%d", caps.vendorId, caps.productId));
211+
} else {
212+
KeyMap::NotifyPadConnected(DEVICE_ID_XINPUT_0 + pad, "Xbox 360 Pad");
213+
}
194214
}
195215
ApplyButtons(pad, state);
196216
ApplyVibration(pad, vibration);

android/src/org/ppsspp/ppsspp/InputDeviceState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public InputDeviceState(InputDevice device) {
128128
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
129129
logAdvanced(device);
130130
}
131+
NativeApp.sendMessage("inputDeviceConnectedID", String.valueOf(this.deviceId));
131132
NativeApp.sendMessage("inputDeviceConnected", device.getName());
132133
}
133134

ios/ViewController.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "Core/Config.h"
3333
#include "Core/ConfigValues.h"
34+
#include "Core/KeyMap.h"
3435
#include "Core/System.h"
3536
#include "Core/HLE/sceUsbCam.h"
3637
#include "Core/HLE/sceUsbGps.h"
@@ -94,6 +95,7 @@ void StopThread() override {
9495
static double lastSelectPress = 0.0f;
9596
static double lastStartPress = 0.0f;
9697
static bool simulateAnalog = false;
98+
static bool iCadeConnectNotified = false;
9799
static bool threadEnabled = true;
98100
static bool threadStopped = false;
99101
static UITouch *g_touches[10];
@@ -507,6 +509,11 @@ - (void)buttonDown:(iCadeState)button
507509

508510
- (void)buttonUp:(iCadeState)button
509511
{
512+
if (!iCadeConnectNotified) {
513+
iCadeConnectNotified = true;
514+
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0, "iCade");
515+
}
516+
510517
if (button == iCadeButtonA) {
511518
// Pressing Select twice within 1 second toggles the DPad between
512519
// normal operation and simulating the Analog stick.

0 commit comments

Comments
 (0)