summaryrefslogtreecommitdiff
path: root/src/hid_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/hid_core')
-rw-r--r--src/hid_core/frontend/emulated_controller.cpp17
-rw-r--r--src/hid_core/frontend/emulated_controller.h1
-rw-r--r--src/hid_core/hid_types.h6
-rw-r--r--src/hid_core/resources/npad/npad.cpp1
4 files changed, 23 insertions, 2 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};
diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h
index 1b2fc6295..38888fdd1 100644
--- a/src/hid_core/hid_types.h
+++ b/src/hid_core/hid_types.h
@@ -638,7 +638,11 @@ struct VibrationValue {
638 if (low_amplitude != b.low_amplitude || high_amplitude != b.high_amplitude) { 638 if (low_amplitude != b.low_amplitude || high_amplitude != b.high_amplitude) {
639 return false; 639 return false;
640 } 640 }
641 if (low_frequency != b.low_amplitude || high_frequency != b.high_frequency) { 641 // Changes in frequency without amplitude don't have any effect
642 if (low_amplitude == 0 && high_amplitude == 0) {
643 return true;
644 }
645 if (low_frequency != b.low_frequency || high_frequency != b.high_frequency) {
642 return false; 646 return false;
643 } 647 }
644 return true; 648 return true;
diff --git a/src/hid_core/resources/npad/npad.cpp b/src/hid_core/resources/npad/npad.cpp
index e10e97e1c..ca1ccd659 100644
--- a/src/hid_core/resources/npad/npad.cpp
+++ b/src/hid_core/resources/npad/npad.cpp
@@ -3,7 +3,6 @@
3 3
4#include <algorithm> 4#include <algorithm>
5#include <array> 5#include <array>
6#include <chrono>
7#include <cstring> 6#include <cstring>
8 7
9#include "common/assert.h" 8#include "common/assert.h"