From ca7f949ee84a7f15990c9e09f2de9ea54b8f997a Mon Sep 17 00:00:00 2001 From: german77 Date: Sat, 24 Feb 2024 12:13:47 -0600 Subject: core: hid: Reintroduce vibration filter --- src/hid_core/frontend/emulated_controller.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/hid_core/frontend/emulated_controller.cpp') diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 5cd26819c..7664341bd 100644 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "common/polyfill_ranges.h" @@ -1287,6 +1288,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV return false; } + if (!Settings::values.enable_accurate_vibrations.GetValue()) { + using std::chrono::duration_cast; + using std::chrono::milliseconds; + using std::chrono::steady_clock; + + const auto now = steady_clock::now(); + + // Filter out non-zero vibrations that are within 15ms of each other. + if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) && + duration_cast(now - last_vibration_timepoint[index]) < milliseconds(15)) { + return false; + } + + last_vibration_timepoint[index] = now; + } + // Exponential amplification is too strong at low amplitudes. Switch to a linear // amplification if strength is set below 0.7f const Common::Input::VibrationAmplificationType type = -- cgit v1.2.3