aboutsummaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
authorDennys Kaluzny Pereira <64793570+protonnegativo@users.noreply.github.com>2026-11-02 15:05:40 -0300
committerDennys Kaluzny Pereira <64793570+protonnegativo@users.noreply.github.com>2026-11-02 17:13:08 -0300
commit80bfef8e0c5f9d3112424d04062afbe6c3968320 (patch)
tree14544e1e2970ddebd81278ce3d80e851d0d7a041 /src/input_common
parent62214094d6c698b70f51016e5c12af415f025be7 (diff)
input_common/sdl: only log motion capabilities when they change
On the Steam Deck the log was flooded with the same gyro message, over 3000 times in a single session. Motion capabilities are now only logged when they change, and the sensor restart interval grows exponentially (up to 64x) while the sensor keeps returning zeroed data. Tested with Pokemon Pokopia on the Steam Deck: from ~42 messages in 33s down to 1 for the whole session, controls working normally. Assisted-by: Claude Opus 5.5 (debugging, code, and drafting this message)
Diffstat (limited to 'src/input_common')
-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};