diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2024-01-11 05:06:54 +0100 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2024-01-16 06:15:40 +0100 |
commit | 2cacb9d48c98603176e52ecc94f2374a934797fb (patch) | |
tree | 12badf5b4eede22b22dece03a9074197ec631a1e /src/hid_core/frontend | |
parent | Merge pull request #12686 from szepeviktor/typos3 (diff) | |
download | yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.gz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.bz2 yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.lz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.xz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.zst yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.zip |
Diffstat (limited to 'src/hid_core/frontend')
-rw-r--r-- | src/hid_core/frontend/emulated_controller.cpp | 40 | ||||
-rw-r--r-- | src/hid_core/frontend/emulated_controller.h | 20 |
2 files changed, 52 insertions, 8 deletions
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 2ab93402d..b6c48aba8 100644 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp @@ -144,8 +144,8 @@ void EmulatedController::ReloadColorsFromSettings() { void EmulatedController::LoadDevices() { // TODO(german77): Use more buttons to detect the correct device - const auto left_joycon = button_params[Settings::NativeButton::DRight]; - const auto right_joycon = button_params[Settings::NativeButton::A]; + const auto& left_joycon = button_params[Settings::NativeButton::DRight]; + const auto& right_joycon = button_params[Settings::NativeButton::A]; // Triggers for GC controllers trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; @@ -1208,20 +1208,43 @@ void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) { controller.nfc_state = controller.nfc_values; } -bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) { +bool EmulatedController::SetVibration(bool should_vibrate) { + VibrationValue vibration_value = DEFAULT_VIBRATION_VALUE; + if (should_vibrate) { + vibration_value.high_amplitude = 1.0f; + vibration_value.low_amplitude = 1.0f; + } + + return SetVibration(DeviceIndex::Left, vibration_value); +} + +bool EmulatedController::SetVibration(u32 slot, Core::HID::VibrationGcErmCommand erm_command) { + VibrationValue vibration_value = DEFAULT_VIBRATION_VALUE; + if (erm_command == Core::HID::VibrationGcErmCommand::Start) { + vibration_value.high_amplitude = 1.0f; + vibration_value.low_amplitude = 1.0f; + } + + return SetVibration(DeviceIndex::Left, vibration_value); +} + +bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationValue& vibration) { if (!is_initialized) { return false; } - if (device_index >= output_devices.size()) { + if (device_index >= DeviceIndex::MaxDeviceIndex) { return false; } - if (!output_devices[device_index]) { + const std::size_t index = static_cast<std::size_t>(device_index); + if (!output_devices[index]) { return false; } const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; + last_vibration_value = vibration; + if (!player.vibration_enabled) { return false; } @@ -1239,8 +1262,11 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v .high_frequency = vibration.high_frequency, .type = type, }; - return output_devices[device_index]->SetVibration(status) == - Common::Input::DriverResult::Success; + return output_devices[index]->SetVibration(status) == Common::Input::DriverResult::Success; +} + +VibrationValue EmulatedController::GetActualVibrationValue(DeviceIndex device_index) const { + return last_vibration_value; } bool 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 90e536e07..168abe089 100644 --- a/src/hid_core/frontend/emulated_controller.h +++ b/src/hid_core/frontend/emulated_controller.h @@ -356,10 +356,27 @@ public: const NfcState& GetNfc() const; /** + * Sends an on/off vibration to the left device + * @return true if vibration had no errors + */ + bool SetVibration(bool should_vibrate); + + /** + * Sends an GC vibration to the left device + * @return true if vibration had no errors + */ + bool SetVibration(u32 slot, Core::HID::VibrationGcErmCommand erm_command); + + /** * Sends a specific vibration to the output device * @return true if vibration had no errors */ - bool SetVibration(std::size_t device_index, VibrationValue vibration); + bool SetVibration(DeviceIndex device_index, const VibrationValue& vibration); + + /** + * @return The last sent vibration + */ + VibrationValue GetActualVibrationValue(DeviceIndex device_index) const; /** * Sends a small vibration to the output device @@ -564,6 +581,7 @@ private: f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard}; u32 turbo_button_state{0}; std::size_t nfc_handles{0}; + VibrationValue last_vibration_value{DEFAULT_VIBRATION_VALUE}; // Temporary values to avoid doing changes while the controller is in configuring mode NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; |