diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-10-07 20:22:47 +0200 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-11-16 05:33:20 +0100 |
commit | 07b81f57babcc7aa41fddfc892148688e841d96e (patch) | |
tree | 1fc825c5a8e9b93ee1384f4713b3379ec4218931 /src/core/hle/service/hid/controllers/npad.cpp | |
parent | hid: Pop a struct of parameters instead of popping individual parameters (diff) | |
download | yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar.gz yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar.bz2 yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar.lz yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar.xz yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.tar.zst yuzu-07b81f57babcc7aa41fddfc892148688e841d96e.zip |
Diffstat (limited to 'src/core/hle/service/hid/controllers/npad.cpp')
-rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index b330c5e40..8a5e5abcf 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -667,35 +667,44 @@ void Controller_NPad::SetNpadMode(u32 npad_id, NpadAssignments assignment_mode) } } -void Controller_NPad::VibrateController(const std::vector<u32>& controllers, - const std::vector<Vibration>& vibrations) { +void Controller_NPad::VibrateController(const std::vector<DeviceHandle>& vibration_device_handles, + const std::vector<VibrationValue>& vibration_values) { LOG_TRACE(Service_HID, "called"); if (!Settings::values.vibration_enabled.GetValue() || !can_controllers_vibrate) { return; } - bool success = true; - for (std::size_t i = 0; i < controllers.size(); ++i) { - if (!connected_controllers[i].is_connected) { + + ASSERT_MSG(vibration_device_handles.size() == vibration_values.size(), + "The amount of device handles does not match with the amount of vibration values," + "this is undefined behavior!"); + + for (std::size_t i = 0; i < vibration_device_handles.size(); ++i) { + const auto npad_index = NPadIdToIndex(vibration_device_handles[i].npad_id); + const auto device_index = + static_cast<std::size_t>(vibration_device_handles[i].device_index); + + if (!connected_controllers[npad_index].is_connected) { continue; } + using namespace Settings::NativeButton; - const auto& button_state = buttons[i]; - if (button_state[A - BUTTON_HID_BEGIN]) { - if (button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( - vibrations[0].amp_high, vibrations[0].amp_low, vibrations[0].freq_high, - vibrations[0].freq_low)) { - success = false; - } - } - } - if (success) { - last_processed_vibration = vibrations.back(); + const auto& button_state = buttons[npad_index]; + + // TODO: Vibrate left/right vibration motors independently if possible. + button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( + vibration_values[i].amp_high, vibration_values[i].amp_low, + vibration_values[i].freq_high, vibration_values[i].freq_low); + + latest_vibration_values[npad_index][device_index] = vibration_values[i]; } } -Controller_NPad::Vibration Controller_NPad::GetLastVibration() const { - return last_processed_vibration; +Controller_NPad::VibrationValue Controller_NPad::GetLastVibration( + const DeviceHandle& vibration_device_handle) const { + const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); + const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); + return latest_vibration_values[npad_index][device_index]; } std::shared_ptr<Kernel::ReadableEvent> Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) const { |