diff options
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.cpp | 22 | ||||
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.h | 1 | ||||
| -rw-r--r-- | src/hid_core/hid_types.h | 6 | ||||
| -rw-r--r-- | src/hid_core/resources/npad/npad.cpp | 1 |
4 files changed, 25 insertions, 5 deletions
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 5cd26819c..9aa08d5cc 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" |
| @@ -175,10 +176,9 @@ void EmulatedController::LoadDevices() { | |||
| 175 | if (npad_id_type == NpadIdType::Player1 || npad_id_type == NpadIdType::Handheld) { | 176 | if (npad_id_type == NpadIdType::Player1 || npad_id_type == NpadIdType::Handheld) { |
| 176 | camera_params[1] = Common::ParamPackage{"engine:camera,camera:1"}; | 177 | camera_params[1] = Common::ParamPackage{"engine:camera,camera:1"}; |
| 177 | nfc_params[0] = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"}; | 178 | nfc_params[0] = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"}; |
| 178 | #ifdef HAVE_LIBUSB | 179 | #ifndef ANDROID |
| 179 | ring_params[1] = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; | 180 | ring_params[1] = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; |
| 180 | #endif | 181 | #else |
| 181 | #ifdef ANDROID | ||
| 182 | android_params = Common::ParamPackage{"engine:android,port:100"}; | 182 | android_params = Common::ParamPackage{"engine:android,port:100"}; |
| 183 | #endif | 183 | #endif |
| 184 | } | 184 | } |
| @@ -1287,6 +1287,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV | |||
| 1287 | return false; | 1287 | return false; |
| 1288 | } | 1288 | } |
| 1289 | 1289 | ||
| 1290 | if (!Settings::values.enable_accurate_vibrations.GetValue()) { | ||
| 1291 | using std::chrono::duration_cast; | ||
| 1292 | using std::chrono::milliseconds; | ||
| 1293 | using std::chrono::steady_clock; | ||
| 1294 | |||
| 1295 | const auto now = steady_clock::now(); | ||
| 1296 | |||
| 1297 | // Filter out non-zero vibrations that are within 15ms of each other. | ||
| 1298 | if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) && | ||
| 1299 | duration_cast<milliseconds>(now - last_vibration_timepoint[index]) < milliseconds(15)) { | ||
| 1300 | return false; | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | last_vibration_timepoint[index] = now; | ||
| 1304 | } | ||
| 1305 | |||
| 1290 | // Exponential amplification is too strong at low amplitudes. Switch to a linear | 1306 | // Exponential amplification is too strong at low amplitudes. Switch to a linear |
| 1291 | // amplification if strength is set below 0.7f | 1307 | // amplification if strength is set below 0.7f |
| 1292 | const Common::Input::VibrationAmplificationType type = | 1308 | 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" |