diff options
| author | 2020-10-22 06:55:23 -0400 | |
|---|---|---|
| committer | 2020-11-15 23:33:20 -0500 | |
| commit | 978ca65f59f1388358ce0d45de41816e8b0aa887 (patch) | |
| tree | 9185157f57f1b1a3900e529ba7a167b36831d11c /src | |
| parent | input_common: Add VibrationDevice and VibrationDeviceFactory (diff) | |
| download | yuzu-978ca65f59f1388358ce0d45de41816e8b0aa887.tar.gz yuzu-978ca65f59f1388358ce0d45de41816e8b0aa887.tar.xz yuzu-978ca65f59f1388358ce0d45de41816e8b0aa887.zip | |
hid: Implement InitializeVibrationDevice and IsVibrationDeviceMounted
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 42 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 7 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 29 |
3 files changed, 66 insertions, 12 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 27099de24..ecc33bc08 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -278,6 +278,9 @@ void Controller_NPad::OnLoadInputDevices() { | |||
| 278 | std::transform(players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, | 278 | std::transform(players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, |
| 279 | players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_END, | 279 | players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_END, |
| 280 | motions[i].begin(), Input::CreateDevice<Input::MotionDevice>); | 280 | motions[i].begin(), Input::CreateDevice<Input::MotionDevice>); |
| 281 | for (std::size_t device_idx = 0; device_idx < vibrations[i].size(); ++device_idx) { | ||
| 282 | InitializeVibrationDeviceAtIndex(i, device_idx); | ||
| 283 | } | ||
| 281 | } | 284 | } |
| 282 | } | 285 | } |
| 283 | 286 | ||
| @@ -689,6 +692,14 @@ bool Controller_NPad::VibrateControllerAtIndex(std::size_t npad_index, std::size | |||
| 689 | const auto& player = Settings::values.players.GetValue()[npad_index]; | 692 | const auto& player = Settings::values.players.GetValue()[npad_index]; |
| 690 | 693 | ||
| 691 | if (!player.vibration_enabled) { | 694 | if (!player.vibration_enabled) { |
| 695 | if (latest_vibration_values[npad_index][device_index].amp_low != 0.0f || | ||
| 696 | latest_vibration_values[npad_index][device_index].amp_high != 0.0f) { | ||
| 697 | // Send an empty vibration to stop any vibrations. | ||
| 698 | vibrations[npad_index][device_index]->SetRumblePlay(0.0f, 160.0f, 0.0f, 320.0f); | ||
| 699 | // Then reset the vibration value to its default value. | ||
| 700 | latest_vibration_values[npad_index][device_index] = {}; | ||
| 701 | } | ||
| 702 | |||
| 692 | return false; | 703 | return false; |
| 693 | } | 704 | } |
| 694 | 705 | ||
| @@ -716,7 +727,8 @@ void Controller_NPad::VibrateControllers(const std::vector<DeviceHandle>& vibrat | |||
| 716 | const auto device_index = | 727 | const auto device_index = |
| 717 | static_cast<std::size_t>(vibration_device_handles[i].device_index); | 728 | static_cast<std::size_t>(vibration_device_handles[i].device_index); |
| 718 | 729 | ||
| 719 | if (!connected_controllers[npad_index].is_connected) { | 730 | if (!vibration_devices_mounted[npad_index][device_index] || |
| 731 | !connected_controllers[npad_index].is_connected) { | ||
| 720 | continue; | 732 | continue; |
| 721 | } | 733 | } |
| 722 | 734 | ||
| @@ -768,6 +780,28 @@ Controller_NPad::VibrationValue Controller_NPad::GetLastVibration( | |||
| 768 | return latest_vibration_values[npad_index][device_index]; | 780 | return latest_vibration_values[npad_index][device_index]; |
| 769 | } | 781 | } |
| 770 | 782 | ||
| 783 | void Controller_NPad::InitializeVibrationDevice(const DeviceHandle& vibration_device_handle) { | ||
| 784 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | ||
| 785 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | ||
| 786 | InitializeVibrationDeviceAtIndex(npad_index, device_index); | ||
| 787 | } | ||
| 788 | |||
| 789 | void Controller_NPad::InitializeVibrationDeviceAtIndex(std::size_t npad_index, | ||
| 790 | std::size_t device_index) { | ||
| 791 | if (vibrations[npad_index][device_index]) { | ||
| 792 | vibration_devices_mounted[npad_index][device_index] = | ||
| 793 | vibrations[npad_index][device_index]->GetStatus() == 1; | ||
| 794 | } else { | ||
| 795 | vibration_devices_mounted[npad_index][device_index] = false; | ||
| 796 | } | ||
| 797 | } | ||
| 798 | |||
| 799 | bool Controller_NPad::IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const { | ||
| 800 | const auto npad_index = NPadIdToIndex(vibration_device_handle.npad_id); | ||
| 801 | const auto device_index = static_cast<std::size_t>(vibration_device_handle.device_index); | ||
| 802 | return vibration_devices_mounted[npad_index][device_index]; | ||
| 803 | } | ||
| 804 | |||
| 771 | std::shared_ptr<Kernel::ReadableEvent> Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) const { | 805 | std::shared_ptr<Kernel::ReadableEvent> Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) const { |
| 772 | const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)]; | 806 | const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)]; |
| 773 | return styleset_event.readable; | 807 | return styleset_event.readable; |
| @@ -809,6 +843,12 @@ void Controller_NPad::DisconnectNpad(u32 npad_id) { | |||
| 809 | } | 843 | } |
| 810 | 844 | ||
| 811 | void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { | 845 | void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { |
| 846 | for (std::size_t device_idx = 0; device_idx < vibrations[npad_index].size(); ++device_idx) { | ||
| 847 | // Send an empty vibration to stop any vibrations. | ||
| 848 | VibrateControllerAtIndex(npad_index, device_idx); | ||
| 849 | vibration_devices_mounted[npad_index][device_idx] = false; | ||
| 850 | } | ||
| 851 | |||
| 812 | Settings::values.players.GetValue()[npad_index].connected = false; | 852 | Settings::values.players.GetValue()[npad_index].connected = false; |
| 813 | connected_controllers[npad_index].is_connected = false; | 853 | connected_controllers[npad_index].is_connected = false; |
| 814 | 854 | ||
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 3ae9fb8e6..30e3cb02f 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -156,6 +156,12 @@ public: | |||
| 156 | 156 | ||
| 157 | VibrationValue GetLastVibration(const DeviceHandle& vibration_device_handle) const; | 157 | VibrationValue GetLastVibration(const DeviceHandle& vibration_device_handle) const; |
| 158 | 158 | ||
| 159 | void InitializeVibrationDevice(const DeviceHandle& vibration_device_handle); | ||
| 160 | |||
| 161 | void InitializeVibrationDeviceAtIndex(std::size_t npad_index, std::size_t device_index); | ||
| 162 | |||
| 163 | bool IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const; | ||
| 164 | |||
| 159 | std::shared_ptr<Kernel::ReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const; | 165 | std::shared_ptr<Kernel::ReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const; |
| 160 | void SignalStyleSetChangedEvent(u32 npad_id) const; | 166 | void SignalStyleSetChangedEvent(u32 npad_id) const; |
| 161 | 167 | ||
| @@ -416,6 +422,7 @@ private: | |||
| 416 | // Each controller should have their own styleset changed event | 422 | // Each controller should have their own styleset changed event |
| 417 | std::array<Kernel::EventPair, 10> styleset_changed_events; | 423 | std::array<Kernel::EventPair, 10> styleset_changed_events; |
| 418 | std::array<std::array<VibrationValue, 2>, 10> latest_vibration_values{}; | 424 | std::array<std::array<VibrationValue, 2>, 10> latest_vibration_values{}; |
| 425 | std::array<std::array<bool, 2>, 10> vibration_devices_mounted{}; | ||
| 419 | std::array<ControllerHolder, 10> connected_controllers{}; | 426 | std::array<ControllerHolder, 10> connected_controllers{}; |
| 420 | std::array<bool, 10> unintended_home_button_input_protection{}; | 427 | std::array<bool, 10> unintended_home_button_input_protection{}; |
| 421 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | 428 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 1d882a977..ecaa847b2 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -139,7 +139,8 @@ void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose | |||
| 139 | 139 | ||
| 140 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { | 140 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { |
| 141 | public: | 141 | public: |
| 142 | IActiveVibrationDeviceList() : ServiceFramework("IActiveVibrationDeviceList") { | 142 | explicit IActiveVibrationDeviceList(std::shared_ptr<IAppletResource> applet_resource_) |
| 143 | : ServiceFramework("IActiveVibrationDeviceList"), applet_resource(applet_resource_) { | ||
| 143 | // clang-format off | 144 | // clang-format off |
| 144 | static const FunctionInfo functions[] = { | 145 | static const FunctionInfo functions[] = { |
| 145 | {0, &IActiveVibrationDeviceList::InitializeVibrationDevice, "InitializeVibrationDevice"}, | 146 | {0, &IActiveVibrationDeviceList::InitializeVibrationDevice, "InitializeVibrationDevice"}, |
| @@ -154,13 +155,18 @@ private: | |||
| 154 | IPC::RequestParser rp{ctx}; | 155 | IPC::RequestParser rp{ctx}; |
| 155 | const auto vibration_device_handle{rp.PopRaw<Controller_NPad::DeviceHandle>()}; | 156 | const auto vibration_device_handle{rp.PopRaw<Controller_NPad::DeviceHandle>()}; |
| 156 | 157 | ||
| 157 | LOG_WARNING(Service_HID, "(STUBBED) called, npad_type={}, npad_id={}, device_index={}", | 158 | applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 158 | vibration_device_handle.npad_type, vibration_device_handle.npad_id, | 159 | .InitializeVibrationDevice(vibration_device_handle); |
| 159 | vibration_device_handle.device_index); | 160 | |
| 161 | LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", | ||
| 162 | vibration_device_handle.npad_type, vibration_device_handle.npad_id, | ||
| 163 | vibration_device_handle.device_index); | ||
| 160 | 164 | ||
| 161 | IPC::ResponseBuilder rb{ctx, 2}; | 165 | IPC::ResponseBuilder rb{ctx, 2}; |
| 162 | rb.Push(RESULT_SUCCESS); | 166 | rb.Push(RESULT_SUCCESS); |
| 163 | } | 167 | } |
| 168 | |||
| 169 | std::shared_ptr<IAppletResource> applet_resource; | ||
| 164 | }; | 170 | }; |
| 165 | 171 | ||
| 166 | std::shared_ptr<IAppletResource> Hid::GetAppletResource() { | 172 | std::shared_ptr<IAppletResource> Hid::GetAppletResource() { |
| @@ -1062,7 +1068,7 @@ void Hid::CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) { | |||
| 1062 | 1068 | ||
| 1063 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1069 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1064 | rb.Push(RESULT_SUCCESS); | 1070 | rb.Push(RESULT_SUCCESS); |
| 1065 | rb.PushIpcInterface<IActiveVibrationDeviceList>(); | 1071 | rb.PushIpcInterface<IActiveVibrationDeviceList>(applet_resource); |
| 1066 | } | 1072 | } |
| 1067 | 1073 | ||
| 1068 | void Hid::PermitVibration(Kernel::HLERequestContext& ctx) { | 1074 | void Hid::PermitVibration(Kernel::HLERequestContext& ctx) { |
| @@ -1137,15 +1143,16 @@ void Hid::IsVibrationDeviceMounted(Kernel::HLERequestContext& ctx) { | |||
| 1137 | 1143 | ||
| 1138 | const auto parameters{rp.PopRaw<Parameters>()}; | 1144 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 1139 | 1145 | ||
| 1140 | LOG_WARNING( | 1146 | LOG_DEBUG(Service_HID, |
| 1141 | Service_HID, | 1147 | "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", |
| 1142 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | 1148 | parameters.vibration_device_handle.npad_type, |
| 1143 | parameters.vibration_device_handle.npad_type, parameters.vibration_device_handle.npad_id, | 1149 | parameters.vibration_device_handle.npad_id, |
| 1144 | parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); | 1150 | parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id); |
| 1145 | 1151 | ||
| 1146 | IPC::ResponseBuilder rb{ctx, 3}; | 1152 | IPC::ResponseBuilder rb{ctx, 3}; |
| 1147 | rb.Push(RESULT_SUCCESS); | 1153 | rb.Push(RESULT_SUCCESS); |
| 1148 | rb.Push(true); | 1154 | rb.Push(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 1155 | .IsVibrationDeviceMounted(parameters.vibration_device_handle)); | ||
| 1149 | } | 1156 | } |
| 1150 | 1157 | ||
| 1151 | void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | 1158 | void Hid::ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { |