Fixed sensor timestamp units for third-party PS5 controllers

This commit is contained in:
Sam Lantinga
2023-09-18 12:55:43 -07:00
parent f6756047a4
commit a72dfa6a5f

View File

@@ -725,7 +725,7 @@ static void HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_DriverPS5_Context *ctx)
{
SDL_bool led_reset_complete = SDL_FALSE;
if (ctx->enhanced_reports && ctx->sensors_supported) {
if (ctx->enhanced_reports && ctx->sensors_supported && !ctx->use_alternate_report) {
const PS5StatePacketCommon_t *packet = &ctx->last_state.state;
/* Check the timer to make sure the Bluetooth connection LED animation is complete */
@@ -1310,12 +1310,12 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY, axis);
if (ctx->report_sensors) {
Uint32 delta;
Uint64 sensor_timestamp;
float data[3];
if (ctx->use_alternate_report) {
/* 16-bit timestamp */
Uint16 delta;
Uint16 tick = LOAD16(packet->rgucSensorTimestamp[0],
packet->rgucSensorTimestamp[1]);
if (ctx->last_tick < tick) {
@@ -1324,8 +1324,13 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
}
ctx->last_tick = tick;
ctx->sensor_ticks += delta;
/* Sensor timestamp is in 1us units */
sensor_timestamp = SDL_US_TO_NS(ctx->sensor_ticks);
} else {
/* 32-bit timestamp */
Uint32 delta;
Uint32 tick = LOAD32(packet->rgucSensorTimestamp[0],
packet->rgucSensorTimestamp[1],
packet->rgucSensorTimestamp[2],
@@ -1336,11 +1341,11 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
delta = (SDL_MAX_UINT32 - ctx->last_tick + tick + 1);
}
ctx->last_tick = tick;
}
ctx->sensor_ticks += delta;
ctx->sensor_ticks += delta;
/* Sensor timestamp is in 0.33us units */
sensor_timestamp = (ctx->sensor_ticks * SDL_NS_PER_US) / 3;
/* Sensor timestamp is in 0.33us units */
sensor_timestamp = (ctx->sensor_ticks * SDL_NS_PER_US) / 3;
}
data[0] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 0, LOAD16(packet->rgucGyroX[0], packet->rgucGyroX[1]));
data[1] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 1, LOAD16(packet->rgucGyroY[0], packet->rgucGyroY[1]));