summaryrefslogtreecommitdiff
path: root/src/hid_core/frontend
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-02-25 14:00:59 -0500
committerGitHub <noreply@github.com>2024-02-25 14:00:59 -0500
commit8416d1c028b3d0fe7ab70dacd28ab8e076014f70 (patch)
tree3ef0a2763194a01147b9f3e134efeaee8dc41b5b /src/hid_core/frontend
parent9e27dbb53b854d83b4c9667db9e29652616f798a (diff)
parentca7f949ee84a7f15990c9e09f2de9ea54b8f997a (diff)
Merge pull request #13154 from german77/vibration-filter
core: hid: Reintroduce vibration filter
Diffstat (limited to 'src/hid_core/frontend')
-rw-r--r--src/hid_core/frontend/emulated_controller.cpp17
-rw-r--r--src/hid_core/frontend/emulated_controller.h1
2 files changed, 18 insertions, 0 deletions
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 <algorithm>
+#include <chrono>
#include <common/scope_exit.h>
#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<milliseconds>(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 =
diff --git a/src/hid_core/frontend/emulated_controller.h b/src/hid_core/frontend/emulated_controller.h
index ab3c6fcd3..17ad6069e 100644
--- a/src/hid_core/frontend/emulated_controller.h
+++ b/src/hid_core/frontend/emulated_controller.h
@@ -583,6 +583,7 @@ private:
std::size_t nfc_handles{0};
std::array<VibrationValue, 2> last_vibration_value{DEFAULT_VIBRATION_VALUE,
DEFAULT_VIBRATION_VALUE};
+ std::array<std::chrono::steady_clock::time_point, 2> last_vibration_timepoint{};
// Temporary values to avoid doing changes while the controller is in configuring mode
NpadStyleIndex tmp_npad_type{NpadStyleIndex::None};