mirror of https://github.com/encounter/SDL.git
Added detection of the joystick type for third party PS4 and PS5 controllers
This commit is contained in:
parent
6b75a592a4
commit
17d7d03adf
|
@ -239,6 +239,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
Uint8 data[USB_PACKET_LENGTH];
|
Uint8 data[USB_PACKET_LENGTH];
|
||||||
int size;
|
int size;
|
||||||
char serial[18];
|
char serial[18];
|
||||||
|
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||||
|
|
||||||
ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
|
ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
|
@ -315,6 +316,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
} else if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
} else if ((size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||||
data[2] == 0x27) {
|
data[2] == 0x27) {
|
||||||
Uint8 capabilities = data[4];
|
Uint8 capabilities = data[4];
|
||||||
|
Uint8 device_type = data[5];
|
||||||
|
|
||||||
#ifdef DEBUG_PS4_PROTOCOL
|
#ifdef DEBUG_PS4_PROTOCOL
|
||||||
HIDAPI_DumpPacket("PS4 capabilities: size = %d", data, size);
|
HIDAPI_DumpPacket("PS4 capabilities: size = %d", data, size);
|
||||||
|
@ -331,6 +333,33 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
if ((capabilities & 0x40) != 0) {
|
if ((capabilities & 0x40) != 0) {
|
||||||
ctx->touchpad_supported = SDL_TRUE;
|
ctx->touchpad_supported = SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (device_type) {
|
||||||
|
case 0x00:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||||
|
break;
|
||||||
|
case 0x01:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
|
||||||
|
break;
|
||||||
|
case 0x04:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_DANCE_PAD;
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_WHEEL;
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_ARCADE_STICK;
|
||||||
|
break;
|
||||||
|
case 0x08:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_FLIGHT_STICK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (device->vendor_id == USB_VENDOR_RAZER) {
|
} else if (device->vendor_id == USB_VENDOR_RAZER) {
|
||||||
/* The Razer Raiju doesn't respond to the detection protocol, but has a touchpad and vibration */
|
/* The Razer Raiju doesn't respond to the detection protocol, but has a touchpad and vibration */
|
||||||
ctx->vibration_supported = SDL_TRUE;
|
ctx->vibration_supported = SDL_TRUE;
|
||||||
|
@ -338,6 +367,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
}
|
}
|
||||||
ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported);
|
ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported);
|
||||||
|
|
||||||
|
device->joystick_type = joystick_type;
|
||||||
device->type = SDL_CONTROLLER_TYPE_PS4;
|
device->type = SDL_CONTROLLER_TYPE_PS4;
|
||||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||||
HIDAPI_SetDeviceName(device, "PS4 Controller");
|
HIDAPI_SetDeviceName(device, "PS4 Controller");
|
||||||
|
|
|
@ -340,6 +340,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
Uint8 data[USB_PACKET_LENGTH*2];
|
Uint8 data[USB_PACKET_LENGTH*2];
|
||||||
int size;
|
int size;
|
||||||
char serial[18];
|
char serial[18];
|
||||||
|
SDL_JoystickType joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||||
|
|
||||||
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
|
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
|
@ -422,6 +423,7 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
data[2] == 0x28) {
|
data[2] == 0x28) {
|
||||||
Uint8 capabilities = data[4];
|
Uint8 capabilities = data[4];
|
||||||
Uint8 capabilities2 = data[20];
|
Uint8 capabilities2 = data[20];
|
||||||
|
Uint8 device_type = data[5];
|
||||||
|
|
||||||
#ifdef DEBUG_PS5_PROTOCOL
|
#ifdef DEBUG_PS5_PROTOCOL
|
||||||
HIDAPI_DumpPacket("PS5 capabilities: size = %d", data, size);
|
HIDAPI_DumpPacket("PS5 capabilities: size = %d", data, size);
|
||||||
|
@ -442,10 +444,35 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
ctx->playerled_supported = SDL_TRUE;
|
ctx->playerled_supported = SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (device_type) {
|
||||||
|
case 0x00:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||||
|
break;
|
||||||
|
case 0x01:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_GUITAR;
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_DRUM_KIT;
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_WHEEL;
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_ARCADE_STICK;
|
||||||
|
break;
|
||||||
|
case 0x08:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_FLIGHT_STICK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
joystick_type = SDL_JOYSTICK_TYPE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ctx->use_alternate_report = SDL_TRUE;
|
ctx->use_alternate_report = SDL_TRUE;
|
||||||
}
|
}
|
||||||
ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported || ctx->playerled_supported);
|
ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported || ctx->playerled_supported);
|
||||||
|
|
||||||
|
device->joystick_type = joystick_type;
|
||||||
device->type = SDL_CONTROLLER_TYPE_PS5;
|
device->type = SDL_CONTROLLER_TYPE_PS5;
|
||||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||||
HIDAPI_SetDeviceName(device, "PS5 Controller");
|
HIDAPI_SetDeviceName(device, "PS5 Controller");
|
||||||
|
|
Loading…
Reference in New Issue