diff options
Diffstat (limited to 'src/hid_core/frontend')
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.cpp | 17 | ||||
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.h | 1 |
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 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <algorithm> | 4 | #include <algorithm> |
| 5 | #include <chrono> | ||
| 5 | #include <common/scope_exit.h> | 6 | #include <common/scope_exit.h> |
| 6 | 7 | ||
| 7 | #include "common/polyfill_ranges.h" | 8 | #include "common/polyfill_ranges.h" |
| @@ -1287,6 +1288,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV | |||
| 1287 | return false; | 1288 | return false; |
| 1288 | } | 1289 | } |
| 1289 | 1290 | ||
| 1291 | if (!Settings::values.enable_accurate_vibrations.GetValue()) { | ||
| 1292 | using std::chrono::duration_cast; | ||
| 1293 | using std::chrono::milliseconds; | ||
| 1294 | using std::chrono::steady_clock; | ||
| 1295 | |||
| 1296 | const auto now = steady_clock::now(); | ||
| 1297 | |||
| 1298 | // Filter out non-zero vibrations that are within 15ms of each other. | ||
| 1299 | if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) && | ||
| 1300 | duration_cast<milliseconds>(now - last_vibration_timepoint[index]) < milliseconds(15)) { | ||
| 1301 | return false; | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | last_vibration_timepoint[index] = now; | ||
| 1305 | } | ||
| 1306 | |||
| 1290 | // Exponential amplification is too strong at low amplitudes. Switch to a linear | 1307 | // Exponential amplification is too strong at low amplitudes. Switch to a linear |
| 1291 | // amplification if strength is set below 0.7f | 1308 | // amplification if strength is set below 0.7f |
| 1292 | const Common::Input::VibrationAmplificationType type = | 1309 | 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: | |||
| 583 | std::size_t nfc_handles{0}; | 583 | std::size_t nfc_handles{0}; |
| 584 | std::array<VibrationValue, 2> last_vibration_value{DEFAULT_VIBRATION_VALUE, | 584 | std::array<VibrationValue, 2> last_vibration_value{DEFAULT_VIBRATION_VALUE, |
| 585 | DEFAULT_VIBRATION_VALUE}; | 585 | DEFAULT_VIBRATION_VALUE}; |
| 586 | std::array<std::chrono::steady_clock::time_point, 2> last_vibration_timepoint{}; | ||
| 586 | 587 | ||
| 587 | // Temporary values to avoid doing changes while the controller is in configuring mode | 588 | // Temporary values to avoid doing changes while the controller is in configuring mode |
| 588 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; | 589 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; |