Core: Track names of connected pad devices.

Rather than just that it's a pad.  This tries to get the identifier if
possible.
This commit is contained in:
Unknown W. Brackets 2022-07-04 12:49:38 -07:00
parent 75bae070de
commit 536c050943
8 changed files with 60 additions and 14 deletions

View file

@ -40,6 +40,7 @@ KeyMapping g_controllerMap;
// Incremented on modification, so we know when to update menus.
int g_controllerMapGeneration = 0;
std::set<std::string> g_seenPads;
std::map<int, std::string> g_padNames;
std::set<int> g_seenDeviceIds;
bool g_swapped_keys = false;
@ -762,8 +763,9 @@ bool HasBuiltinController(const std::string &name) {
return IsOuya(name) || IsXperiaPlay(name) || IsNvidiaShield(name) || IsMOQII7S(name) || IsRetroid(name);
}
void NotifyPadConnected(const std::string &name) {
void NotifyPadConnected(int deviceId, const std::string &name) {
g_seenPads.insert(name);
g_padNames[deviceId] = name;
}
void AutoConfForPad(const std::string &name) {

View file

@ -153,7 +153,7 @@ namespace KeyMap {
void SwapAxis();
void UpdateNativeMenuKeys();
void NotifyPadConnected(const std::string &name);
void NotifyPadConnected(int deviceId, const std::string &name);
bool IsNvidiaShield(const std::string &name);
bool IsNvidiaShieldTV(const std::string &name);
bool IsXperiaPlay(const std::string &name);

View file

@ -8,6 +8,7 @@
#include "Common/System/System.h"
#include "Core/Config.h"
#include "Core/KeyMap.h"
#include "SDL/SDLJoystick.h"
using namespace std;
@ -54,11 +55,12 @@ void SDLJoystick::setUpControllers() {
}
void SDLJoystick::setUpController(int deviceIndex) {
static constexpr int cbGUID = 33;
char pszGUID[cbGUID];
if (!SDL_IsGameController(deviceIndex)) {
cout << "Control pad device " << deviceIndex << " not supported by SDL game controller database, attempting to create default mapping..." << endl;
int cbGUID = 33;
char pszGUID[cbGUID];
SDL_Joystick* joystick = SDL_JoystickOpen(deviceIndex);
SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex);
if (joystick) {
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), pszGUID, cbGUID);
// create default mapping - this is the PS3 dual shock mapping
@ -73,6 +75,12 @@ void SDLJoystick::setUpController(int deviceIndex) {
} else {
cout << "Failed to get joystick identifier. Read-only device? Control pad device " + std::to_string(deviceIndex) << endl;
}
} else {
SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex);
if (joystick) {
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), pszGUID, cbGUID);
SDL_JoystickClose(joystick);
}
}
SDL_GameController *controller = SDL_GameControllerOpen(deviceIndex);
if (controller) {
@ -80,6 +88,7 @@ void SDLJoystick::setUpController(int deviceIndex) {
controllers.push_back(controller);
controllerDeviceMap[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller))] = deviceIndex;
cout << "found control pad: " << SDL_GameControllerName(controller) << ", loading mapping: ";
KeyMap::NotifyPadConnected(deviceIndex, std::string(pszGUID) + ": " + SDL_GameControllerName(controller));
auto mapping = SDL_GameControllerMapping(controller);
if (mapping == NULL) {
//cout << "FAILED" << endl;

View file

@ -1176,8 +1176,12 @@ void NativeRender(GraphicsContext *graphicsContext) {
}
void HandleGlobalMessage(const std::string &msg, const std::string &value) {
int nextInputDeviceID = -1;
if (msg == "inputDeviceConnectedID") {
nextInputDeviceID = parseLong(value);
}
if (msg == "inputDeviceConnected") {
KeyMap::NotifyPadConnected(value);
KeyMap::NotifyPadConnected(nextInputDeviceID, value);
}
if (msg == "bgImage_updated") {
if (!value.empty()) {
@ -1419,7 +1423,6 @@ bool NativeAxis(const AxisInput &axis) {
}
void NativeMessageReceived(const char *message, const char *value) {
// We can only have one message queued.
std::lock_guard<std::mutex> lock(pendingMutex);
PendingMessage pendingMessage;
pendingMessage.msg = message;

View file

@ -23,6 +23,7 @@
#include "Common/Input/InputState.h"
#include "Common/Input/KeyCodes.h"
#include "Common/StringUtils.h"
#include "Common/System/NativeApp.h"
#include "Core/Config.h"
#include "Core/HLE/sceCtrl.h"
@ -57,8 +58,6 @@ static const int dinput_buttons[] = {
NKCODE_BUTTON_16,
};
static float NormalizedDeadzoneFilter(short value);
#define DIFF (JOY_POVRIGHT - JOY_POVFORWARD) / 2
#define JOY_POVFORWARD_RIGHT JOY_POVFORWARD + DIFF
#define JOY_POVRIGHT_BACKWARD JOY_POVRIGHT + DIFF
@ -152,6 +151,11 @@ DinputDevice::DinputDevice(int devnum) {
return;
}
wchar_t guid[64];
if (StringFromGUID2(devices.at(devnum).guidProduct, guid, ARRAY_SIZE(guid)) != 0) {
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0 + pDevNum, StringFromFormat("%S: %S", devices.at(devnum).tszProductName, guid));
}
if (FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) {
pJoystick->Release();
pJoystick = NULL;

View file

@ -4,13 +4,14 @@
#include <algorithm>
#include "Common/System/NativeApp.h"
#include "Core/Config.h"
#include "Common/CommonWindows.h"
#include "Common/Log.h"
#include "Common/StringUtils.h"
#include "Common/TimeUtil.h"
#include "Common/Input/InputState.h"
#include "Common/Input/KeyCodes.h"
#include "XinputDevice.h"
#include "Core/Config.h"
#include "Core/Core.h"
#include "Core/KeyMap.h"
#include "Core/HLE/sceCtrl.h"
@ -21,11 +22,21 @@ static double newVibrationTime = 0.0;
#if !PPSSPP_PLATFORM(UWP)
struct XINPUT_CAPABILITIES_EX {
XINPUT_CAPABILITIES Capabilities;
WORD vendorId;
WORD productId;
WORD revisionId;
DWORD a4; //unknown
};
typedef DWORD (WINAPI *XInputGetState_t) (DWORD dwUserIndex, XINPUT_STATE* pState);
typedef DWORD (WINAPI *XInputSetState_t) (DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
typedef DWORD (WINAPI *XInputGetCapabilitiesEx_t) (DWORD unknown, DWORD dwUserIndex, DWORD flags, XINPUT_CAPABILITIES_EX *pCapabilities);
static XInputGetState_t PPSSPP_XInputGetState = nullptr;
static XInputSetState_t PPSSPP_XInputSetState = nullptr;
static XInputGetCapabilitiesEx_t PPSSPP_XInputGetCapabilitiesEx = nullptr;
static DWORD PPSSPP_XInputVersion = 0;
static HMODULE s_pXInputDLL = 0;
static int s_XInputDLLRefCount = 0;
@ -83,6 +94,10 @@ static int LoadXInputDLL() {
return -1;
}
if (PPSSPP_XInputVersion >= ((1 << 16) | 4)) {
PPSSPP_XInputGetCapabilitiesEx = (XInputGetCapabilitiesEx_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)108);
}
return 0;
}
@ -187,10 +202,15 @@ int XinputDevice::UpdateState() {
}
void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state, XINPUT_VIBRATION &vibration) {
static bool notified = false;
if (!notified) {
notified = true;
KeyMap::NotifyPadConnected("Xbox 360 Pad");
static bool notified[XUSER_MAX_COUNT]{};
if (!notified[pad]) {
notified[pad] = true;
XINPUT_CAPABILITIES_EX caps;
if (PPSSPP_XInputGetCapabilitiesEx != nullptr && PPSSPP_XInputGetCapabilitiesEx(1, pad, 0, &caps) == ERROR_SUCCESS) {
KeyMap::NotifyPadConnected(DEVICE_ID_XINPUT_0 + pad, StringFromFormat("Xbox 360 Pad: %d/%d", caps.vendorId, caps.productId));
} else {
KeyMap::NotifyPadConnected(DEVICE_ID_XINPUT_0 + pad, "Xbox 360 Pad");
}
}
ApplyButtons(pad, state);
ApplyVibration(pad, vibration);

View file

@ -128,6 +128,7 @@ public class InputDeviceState {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
logAdvanced(device);
}
NativeApp.sendMessage("inputDeviceConnectedID", String.valueOf(this.deviceId));
NativeApp.sendMessage("inputDeviceConnected", device.getName());
}

View file

@ -31,6 +31,7 @@
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/KeyMap.h"
#include "Core/System.h"
#include "Core/HLE/sceUsbCam.h"
#include "Core/HLE/sceUsbGps.h"
@ -94,6 +95,7 @@ static float dp_yscale = 1.0f;
static double lastSelectPress = 0.0f;
static double lastStartPress = 0.0f;
static bool simulateAnalog = false;
static bool iCadeConnectNotified = false;
static bool threadEnabled = true;
static bool threadStopped = false;
static UITouch *g_touches[10];
@ -507,6 +509,11 @@ int ToTouchID(UITouch *uiTouch, bool allowAllocate) {
- (void)buttonUp:(iCadeState)button
{
if (!iCadeConnectNotified) {
iCadeConnectNotified = true;
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0, "iCade");
}
if (button == iCadeButtonA) {
// Pressing Select twice within 1 second toggles the DPad between
// normal operation and simulating the Analog stick.