diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 42 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 14 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 4 |
3 files changed, 38 insertions, 22 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index cc54b164d..81725efbb 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -117,7 +117,10 @@ u32 Controller_NPad::IndexToNPad(std::size_t index) { | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system), system(system) {} | 119 | Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system), system(system) {} |
| 120 | Controller_NPad::~Controller_NPad() = default; | 120 | |
| 121 | Controller_NPad::~Controller_NPad() { | ||
| 122 | OnRelease(); | ||
| 123 | } | ||
| 121 | 124 | ||
| 122 | void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { | 125 | void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { |
| 123 | const auto controller_type = connected_controllers[controller_idx].type; | 126 | const auto controller_type = connected_controllers[controller_idx].type; |
| @@ -274,7 +277,11 @@ void Controller_NPad::OnLoadInputDevices() { | |||
| 274 | } | 277 | } |
| 275 | } | 278 | } |
| 276 | 279 | ||
| 277 | void Controller_NPad::OnRelease() {} | 280 | void Controller_NPad::OnRelease() { |
| 281 | for (std::size_t index = 0; index < connected_controllers.size(); ++index) { | ||
| 282 | VibrateControllerAtIndex(index, {}); | ||
| 283 | } | ||
| 284 | } | ||
| 278 | 285 | ||
| 279 | void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { | 286 | void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { |
| 280 | const auto controller_idx = NPadIdToIndex(npad_id); | 287 | const auto controller_idx = NPadIdToIndex(npad_id); |
| @@ -667,8 +674,24 @@ void Controller_NPad::SetNpadMode(u32 npad_id, NpadAssignments assignment_mode) | |||
| 667 | } | 674 | } |
| 668 | } | 675 | } |
| 669 | 676 | ||
| 670 | void Controller_NPad::VibrateController(const std::vector<DeviceHandle>& vibration_device_handles, | 677 | bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, |
| 671 | const std::vector<VibrationValue>& vibration_values) { | 678 | const VibrationValue& vibration_value) { |
| 679 | if (!connected_controllers[npad_index].is_connected) { | ||
| 680 | return false; | ||
| 681 | } | ||
| 682 | |||
| 683 | using namespace Settings::NativeButton; | ||
| 684 | const auto& button_state = buttons[npad_index]; | ||
| 685 | |||
| 686 | return button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( | ||
| 687 | vibration_value.amp_low * Settings::values.vibration_strength.GetValue() / 100, | ||
| 688 | vibration_value.freq_low, | ||
| 689 | vibration_value.amp_high * Settings::values.vibration_strength.GetValue() / 100, | ||
| 690 | vibration_value.freq_high); | ||
| 691 | } | ||
| 692 | |||
| 693 | void Controller_NPad::VibrateControllers(const std::vector<DeviceHandle>& vibration_device_handles, | ||
| 694 | const std::vector<VibrationValue>& vibration_values) { | ||
| 672 | LOG_TRACE(Service_HID, "called"); | 695 | LOG_TRACE(Service_HID, "called"); |
| 673 | 696 | ||
| 674 | if (!Settings::values.vibration_enabled.GetValue() || !can_controllers_vibrate) { | 697 | if (!Settings::values.vibration_enabled.GetValue() || !can_controllers_vibrate) { |
| @@ -717,17 +740,8 @@ void Controller_NPad::VibrateController(const std::vector<DeviceHandle>& vibrati | |||
| 717 | continue; | 740 | continue; |
| 718 | } | 741 | } |
| 719 | 742 | ||
| 720 | using namespace Settings::NativeButton; | ||
| 721 | const auto& button_state = buttons[npad_index]; | ||
| 722 | |||
| 723 | // TODO: Vibrate left/right vibration motors independently if possible. | 743 | // TODO: Vibrate left/right vibration motors independently if possible. |
| 724 | const bool success = button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( | 744 | if (VibrateControllerAtIndex(npad_index, vibration_values[i])) { |
| 725 | vibration_values[i].amp_low * Settings::values.vibration_strength.GetValue() / 100, | ||
| 726 | vibration_values[i].freq_low, | ||
| 727 | vibration_values[i].amp_high * Settings::values.vibration_strength.GetValue() / 100, | ||
| 728 | vibration_values[i].freq_high); | ||
| 729 | |||
| 730 | if (success) { | ||
| 731 | switch (connected_controllers[npad_index].type) { | 745 | switch (connected_controllers[npad_index].type) { |
| 732 | case NPadControllerType::None: | 746 | case NPadControllerType::None: |
| 733 | UNREACHABLE(); | 747 | UNREACHABLE(); |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index c1b19103a..4dc2a974d 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -110,10 +110,10 @@ public: | |||
| 110 | static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size"); | 110 | static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size"); |
| 111 | 111 | ||
| 112 | struct VibrationValue { | 112 | struct VibrationValue { |
| 113 | f32 amp_low; | 113 | f32 amp_low{0.0f}; |
| 114 | f32 freq_low; | 114 | f32 freq_low{160.0f}; |
| 115 | f32 amp_high; | 115 | f32 amp_high{0.0f}; |
| 116 | f32 freq_high; | 116 | f32 freq_high{320.0f}; |
| 117 | }; | 117 | }; |
| 118 | static_assert(sizeof(VibrationValue) == 0x10, "Vibration is an invalid size"); | 118 | static_assert(sizeof(VibrationValue) == 0x10, "Vibration is an invalid size"); |
| 119 | 119 | ||
| @@ -148,8 +148,10 @@ public: | |||
| 148 | 148 | ||
| 149 | void SetNpadMode(u32 npad_id, NpadAssignments assignment_mode); | 149 | void SetNpadMode(u32 npad_id, NpadAssignments assignment_mode); |
| 150 | 150 | ||
| 151 | void VibrateController(const std::vector<DeviceHandle>& vibration_device_handles, | 151 | bool VibrateControllerAtIndex(std::size_t npad_index, const VibrationValue& vibration_value); |
| 152 | const std::vector<VibrationValue>& vibration_values); | 152 | |
| 153 | void VibrateControllers(const std::vector<DeviceHandle>& vibration_device_handles, | ||
| 154 | const std::vector<VibrationValue>& vibration_values); | ||
| 153 | 155 | ||
| 154 | VibrationValue GetLastVibration(const DeviceHandle& vibration_device_handle) const; | 156 | VibrationValue GetLastVibration(const DeviceHandle& vibration_device_handle) const; |
| 155 | 157 | ||
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 89327cd86..878f20bd2 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -1022,7 +1022,7 @@ void Hid::SendVibrationValue(Kernel::HLERequestContext& ctx) { | |||
| 1022 | const auto parameters{rp.PopRaw<Parameters>()}; | 1022 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1023 | 1023 | ||
| 1024 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 1024 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 1025 | .VibrateController({parameters.vibration_device_handle}, {parameters.vibration_value}); | 1025 | .VibrateControllers({parameters.vibration_device_handle}, {parameters.vibration_value}); |
| 1026 | 1026 | ||
| 1027 | LOG_DEBUG(Service_HID, | 1027 | LOG_DEBUG(Service_HID, |
| 1028 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 1028 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| @@ -1100,7 +1100,7 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { | |||
| 1100 | std::memcpy(vibration_values.data(), vibrations.data(), vibrations.size()); | 1100 | std::memcpy(vibration_values.data(), vibrations.data(), vibrations.size()); |
| 1101 | 1101 | ||
| 1102 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | 1102 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 1103 | .VibrateController(vibration_device_handles, vibration_values); | 1103 | .VibrateControllers(vibration_device_handles, vibration_values); |
| 1104 | 1104 | ||
| 1105 | LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); | 1105 | LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); |
| 1106 | 1106 | ||