diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 271871e6e4..8e6d563dcf 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -2023,6 +2023,18 @@ void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, f } } +void SDL_PrivateJoystickSensorRate(SDL_Joystick *joystick, SDL_SensorType type, float rate) +{ + int i; + SDL_AssertJoysticksLocked(); + + for (i = 0; i < joystick->nsensors; ++i) { + if (joystick->sensors[i].type == type) { + joystick->sensors[i].rate = rate; + } + } +} + void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id) { SDL_JoystickDriver *driver; diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index 7fc6645192..ba99b012c8 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -156,6 +156,7 @@ extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid /* Internal event queueing functions */ extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers); extern void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, float rate); +extern void SDL_PrivateJoystickSensorRate(SDL_Joystick *joystick, SDL_SensorType type, float rate); extern void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id); extern SDL_bool SDL_IsJoystickBeingAdded(void); extern void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id); diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index 5c5d5ea454..5a4f9e2193 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -717,8 +717,8 @@ static void HIDAPI_DriverPS4_SetEnhancedModeAvailable(SDL_DriverPS4_Context *ctx } if (ctx->sensors_supported) { - SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_GYRO, 250.0f); - SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, 250.0f); + SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_GYRO, (float)(1000 / ctx->report_interval)); + SDL_PrivateJoystickAddSensor(ctx->joystick, SDL_SENSOR_ACCEL, (float)(1000 / ctx->report_interval)); } if (ctx->official_controller) { @@ -818,6 +818,10 @@ static void SDLCALL SDL_PS4ReportIntervalHintChanged(void *userdata, const char ctx->report_interval = (Uint8)new_report_interval; HIDAPI_DriverPS4_UpdateEffects(ctx, SDL_FALSE); + SDL_LockJoysticks(); + SDL_PrivateJoystickSensorRate(ctx->joystick, SDL_SENSOR_GYRO, (float)(1000 / ctx->report_interval)); + SDL_PrivateJoystickSensorRate(ctx->joystick, SDL_SENSOR_ACCEL, (float)(1000 / ctx->report_interval)); + SDL_UnlockJoysticks(); } } @@ -849,6 +853,7 @@ static SDL_bool HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy ctx->rumble_left = 0; ctx->rumble_right = 0; ctx->color_set = SDL_FALSE; + ctx->report_interval = 4; SDL_zero(ctx->last_state); /* Initialize player index (needed for setting LEDs) */