From 645b8e7f6dc0dca9f1843337074ff94432e65599 Mon Sep 17 00:00:00 2001
From: Sanjay Govind <[EMAIL REDACTED]>
Date: Wed, 25 Feb 2026 15:58:13 +1300
Subject: [PATCH] Support accelerometers on 3rd party ps3 controllers (#15109)
(cherry picked from commit 0c859452ef9807dd85ba013aca7b76853d600f54)
---
src/joystick/hidapi/SDL_hidapi_ps3.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c
index ada3844297932..158f90da4c498 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps3.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps3.c
@@ -743,6 +743,8 @@ static bool HIDAPI_DriverPS3ThirdParty_OpenJoystick(SDL_HIDAPI_Device *device, S
joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
}
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 100.0f);
+
return true;
}
@@ -773,7 +775,11 @@ static bool HIDAPI_DriverPS3ThirdParty_SendJoystickEffect(SDL_HIDAPI_Device *dev
static bool HIDAPI_DriverPS3ThirdParty_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
{
- return SDL_Unsupported();
+ SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context;
+
+ ctx->report_sensors = enabled;
+
+ return true;
}
static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket18(SDL_Joystick *joystick, SDL_DriverPS3_Context *ctx, Uint8 *data, int size)
@@ -1011,6 +1017,15 @@ static void HIDAPI_DriverPS3ThirdParty_HandleStatePacket19(SDL_Joystick *joystic
}
}
+ if (ctx->report_sensors) {
+ float sensor_data[3];
+
+ sensor_data[0] = -HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[20], data[19]));
+ sensor_data[1] = -HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[22], data[21]));
+ sensor_data[2] = -HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[24], data[23]));
+ SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, timestamp, sensor_data, SDL_arraysize(sensor_data));
+ }
+
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
}