diff options
| author | néo Luigi <85024393+neoluigi4123@users.noreply.github.com> | 2026-11-03 00:49:36 +0100 |
|---|---|---|
| committer | néo Luigi <85024393+neoluigi4123@users.noreply.github.com> | 2026-11-03 00:49:36 +0100 |
| commit | c84e5caf82a786f748c233e27b7f4ed9aaad9f44 (patch) | |
| tree | 3ec9cab90d74292445d0a076370933bac946fc4d /src/input_common/drivers/sdl_driver.cpp | |
| parent | 2b413a46a2820f0a646baaa8dbd683009f096f32 (diff) | |
| parent | efa7c19e59839f0d464c2e9bd41f9ca8f867fef0 (diff) | |
Merge remote-tracking branch 'origin/nx2' into neo.ai/vibration-fix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
# src/core/hle/service/hid/hid_server.cpp
# src/core/hle/service/hid/hid_server.h
Diffstat (limited to 'src/input_common/drivers/sdl_driver.cpp')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index c3e9a066b3..a308554071 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -3,6 +3,7 @@ // SPDX-FileCopyrightText: 2018 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include <algorithm> #include <array> #include <numbers> #include "common/logging.h" @@ -115,7 +116,15 @@ public: } } - LOG_INFO(Input, "Controller motion capabilities: accel={} gyro={}", has_accel, has_gyro); + // EnableMotion is also called to recover a stalled sensor, so only log when the reported + // capabilities actually change instead of on every restart. + if (!motion_capabilities_logged || logged_accel != has_accel || logged_gyro != has_gyro) { + LOG_INFO(Input, "Controller motion capabilities: accel={} gyro={}", has_accel, + has_gyro); + motion_capabilities_logged = true; + logged_accel = has_accel; + logged_gyro = has_gyro; + } } bool HasMotion() const { @@ -163,16 +172,21 @@ public: // Motion data is invalid if (motion.accel_x == 0 && motion.gyro_x == 0 && motion.accel_y == 0 && motion.gyro_y == 0 && motion.accel_z == 0 && motion.gyro_z == 0) { - if (motion_error_count++ < 200) { + if (motion_error_count++ < motion_restart_threshold) { return false; } - // Try restarting the sensor + // Try restarting the sensor. Back off exponentially so a sensor that keeps reporting + // zeros (observed on the Steam Deck) isn't toggled several times a + // second for the whole session. motion_error_count = 0; + motion_restart_threshold = + std::min(motion_restart_threshold * 2, MaxMotionRestartThreshold); EnableMotion(); return false; } motion_error_count = 0; + motion_restart_threshold = InitialMotionRestartThreshold; motion.delta_timestamp = time_difference; return true; } @@ -393,7 +407,13 @@ private: mutable std::mutex mutex; u64 last_motion_update{}; + static constexpr std::size_t InitialMotionRestartThreshold = 200; + static constexpr std::size_t MaxMotionRestartThreshold = 200 * 64; std::size_t motion_error_count{}; + std::size_t motion_restart_threshold{InitialMotionRestartThreshold}; + bool motion_capabilities_logged{false}; + bool logged_accel{false}; + bool logged_gyro{false}; bool has_gyro{false}; bool has_accel{false}; bool has_vibration{false}; |
