aboutsummaryrefslogtreecommitdiff
path: root/src/input_common/drivers/sdl_driver.cpp
diff options
context:
space:
mode:
authorcirakg <cirakg@cirakg.xyz>2026-11-03 00:31:11 +0100
committercirakg <cirakg@cirakg.xyz>2026-11-03 00:31:11 +0100
commitc85a2c2d021e5337cf27ebd91a0f1e3d9f628de3 (patch)
tree7e48118157f01fcb2d6540985570ae5df67a3ea8 /src/input_common/drivers/sdl_driver.cpp
parent172aeaa0449d5618cff5753073a5c1741d619689 (diff)
parent0f9760e5ccfd336130f194c2564849052acde591 (diff)
Merge upstream Djihads80/Eglantine nx2 into nx2
Diffstat (limited to 'src/input_common/drivers/sdl_driver.cpp')
-rw-r--r--src/input_common/drivers/sdl_driver.cpp26
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};