mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-01-24 17:31:12 +00:00
Fixed handling simple mode PS4 reports
Fixes https://github.com/libsdl-org/SDL/issues/7270 (cherry picked from commit 5925cd4ef377a2211fd057ef6fa9f41141999cb7)
This commit is contained in:
parent
22df572979
commit
2c6995778e
|
@ -822,7 +822,7 @@ static int HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
|
static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet, int size)
|
||||||
{
|
{
|
||||||
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
||||||
static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */
|
static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */
|
||||||
|
@ -925,7 +925,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
|
||||||
axis = ((int)packet->ucRightJoystickY * 257) - 32768;
|
axis = ((int)packet->ucRightJoystickY * 257) - 32768;
|
||||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
||||||
|
|
||||||
if (ctx->device->is_bluetooth && ctx->official_controller) {
|
if (size > 9 && ctx->device->is_bluetooth && ctx->official_controller) {
|
||||||
if (packet->ucBatteryLevel & 0x10) {
|
if (packet->ucBatteryLevel & 0x10) {
|
||||||
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
|
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
|
||||||
} else {
|
} else {
|
||||||
|
@ -943,7 +943,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->report_touchpad) {
|
if (size > 9 && ctx->report_touchpad) {
|
||||||
touchpad_state = !(packet->ucTouchpadCounter1 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
|
touchpad_state = !(packet->ucTouchpadCounter1 & 0x80) ? SDL_PRESSED : SDL_RELEASED;
|
||||||
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
|
touchpad_x = packet->rgucTouchpadData1[0] | (((int)packet->rgucTouchpadData1[1] & 0x0F) << 8);
|
||||||
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
|
touchpad_y = (packet->rgucTouchpadData1[1] >> 4) | ((int)packet->rgucTouchpadData1[2] << 4);
|
||||||
|
@ -955,7 +955,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
|
||||||
SDL_PrivateJoystickTouchpad(joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
|
SDL_PrivateJoystickTouchpad(joystick, 0, 1, touchpad_state, touchpad_x * TOUCHPAD_SCALEX, touchpad_y * TOUCHPAD_SCALEY, touchpad_state ? 1.0f : 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->report_sensors) {
|
if (size > 9 && ctx->report_sensors) {
|
||||||
Uint16 timestamp;
|
Uint16 timestamp;
|
||||||
Uint64 timestamp_us;
|
Uint64 timestamp_us;
|
||||||
float data[3];
|
float data[3];
|
||||||
|
@ -1011,6 +1011,11 @@ static SDL_bool HIDAPI_DriverPS4_IsPacketValid(SDL_DriverPS4_Context *ctx, Uint8
|
||||||
{
|
{
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case k_EPS4ReportIdUsbState:
|
case k_EPS4ReportIdUsbState:
|
||||||
|
if (size == 10) {
|
||||||
|
/* This is non-enhanced mode, this packet is fine */
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* In the case of a DS4 USB dongle, bit[2] of byte 31 indicates if a DS4 is actually connected (indicated by '0').
|
/* In the case of a DS4 USB dongle, bit[2] of byte 31 indicates if a DS4 is actually connected (indicated by '0').
|
||||||
* For non-dongle, this bit is always 0 (connected).
|
* For non-dongle, this bit is always 0 (connected).
|
||||||
* This is usually the ID over USB, but the DS4v2 that started shipping with the PS4 Slim will also send this
|
* This is usually the ID over USB, but the DS4v2 that started shipping with the PS4 Slim will also send this
|
||||||
|
@ -1070,7 +1075,7 @@ static SDL_bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case k_EPS4ReportIdUsbState:
|
case k_EPS4ReportIdUsbState:
|
||||||
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1]);
|
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1], size - 1);
|
||||||
break;
|
break;
|
||||||
case k_EPS4ReportIdBluetoothState1:
|
case k_EPS4ReportIdBluetoothState1:
|
||||||
case k_EPS4ReportIdBluetoothState2:
|
case k_EPS4ReportIdBluetoothState2:
|
||||||
|
@ -1086,7 +1091,7 @@ static SDL_bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
|
HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
|
||||||
}
|
}
|
||||||
/* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID is present */
|
/* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID is present */
|
||||||
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[3]);
|
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[3], size - 3);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef DEBUG_JOYSTICK
|
#ifdef DEBUG_JOYSTICK
|
||||||
|
|
Loading…
Reference in a new issue