summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Narr the Reg2024-01-23 11:10:34 -0600
committerGravatar Narr the Reg2024-01-23 11:33:08 -0600
commitad4622da2cad626b1acdbf1c3985d4d5b6e86bb0 (patch)
tree48aec311d37a0709c628d4bb0730f12d9dc6b623
parentcore: hid: Only set polling mode if needed (diff)
downloadyuzu-ad4622da2cad626b1acdbf1c3985d4d5b6e86bb0.tar.gz
yuzu-ad4622da2cad626b1acdbf1c3985d4d5b6e86bb0.tar.xz
yuzu-ad4622da2cad626b1acdbf1c3985d4d5b6e86bb0.zip
core: hid: Skip duplicated vibrations
-rw-r--r--src/hid_core/frontend/emulated_controller.cpp12
-rw-r--r--src/hid_core/frontend/emulated_controller.h3
-rw-r--r--src/hid_core/hid_types.h9
3 files changed, 21 insertions, 3 deletions
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp
index 063f5b15a..819460eb5 100644
--- a/src/hid_core/frontend/emulated_controller.cpp
+++ b/src/hid_core/frontend/emulated_controller.cpp
@@ -1245,7 +1245,12 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV
1245 return false; 1245 return false;
1246 } 1246 }
1247 1247
1248 last_vibration_value = vibration; 1248 // Skip duplicated vibrations
1249 if (last_vibration_value[index] == vibration) {
1250 return Settings::values.vibration_enabled.GetValue();
1251 }
1252
1253 last_vibration_value[index] = vibration;
1249 1254
1250 if (!Settings::values.vibration_enabled) { 1255 if (!Settings::values.vibration_enabled) {
1251 return false; 1256 return false;
@@ -1276,7 +1281,10 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV
1276} 1281}
1277 1282
1278VibrationValue EmulatedController::GetActualVibrationValue(DeviceIndex device_index) const { 1283VibrationValue EmulatedController::GetActualVibrationValue(DeviceIndex device_index) const {
1279 return last_vibration_value; 1284 if (device_index >= DeviceIndex::MaxDeviceIndex) {
1285 return Core::HID::DEFAULT_VIBRATION_VALUE;
1286 }
1287 return last_vibration_value[static_cast<std::size_t>(device_index)];
1280} 1288}
1281 1289
1282bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { 1290bool EmulatedController::IsVibrationEnabled(std::size_t device_index) {
diff --git a/src/hid_core/frontend/emulated_controller.h b/src/hid_core/frontend/emulated_controller.h
index 168abe089..701b38300 100644
--- a/src/hid_core/frontend/emulated_controller.h
+++ b/src/hid_core/frontend/emulated_controller.h
@@ -581,7 +581,8 @@ private:
581 f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard}; 581 f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard};
582 u32 turbo_button_state{0}; 582 u32 turbo_button_state{0};
583 std::size_t nfc_handles{0}; 583 std::size_t nfc_handles{0};
584 VibrationValue last_vibration_value{DEFAULT_VIBRATION_VALUE}; 584 std::array<VibrationValue, 2> last_vibration_value{DEFAULT_VIBRATION_VALUE,
585 DEFAULT_VIBRATION_VALUE};
585 586
586 // Temporary values to avoid doing changes while the controller is in configuring mode 587 // Temporary values to avoid doing changes while the controller is in configuring mode
587 NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; 588 NpadStyleIndex tmp_npad_type{NpadStyleIndex::None};
diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h
index 2c3f02f34..a01292a70 100644
--- a/src/hid_core/hid_types.h
+++ b/src/hid_core/hid_types.h
@@ -639,6 +639,15 @@ struct VibrationValue {
639 f32 low_frequency{}; 639 f32 low_frequency{};
640 f32 high_amplitude{}; 640 f32 high_amplitude{};
641 f32 high_frequency{}; 641 f32 high_frequency{};
642 bool operator==(const VibrationValue& b) {
643 if (low_amplitude != b.low_amplitude || high_amplitude != b.high_amplitude) {
644 return false;
645 }
646 if (low_frequency != b.low_amplitude || high_frequency != b.high_frequency) {
647 return false;
648 }
649 return true;
650 }
642}; 651};
643static_assert(sizeof(VibrationValue) == 0x10, "VibrationValue has incorrect size."); 652static_assert(sizeof(VibrationValue) == 0x10, "VibrationValue has incorrect size.");
644 653