diff options
| author | 2024-01-10 22:06:54 -0600 | |
|---|---|---|
| committer | 2024-01-15 23:15:40 -0600 | |
| commit | 2cacb9d48c98603176e52ecc94f2374a934797fb (patch) | |
| tree | 12badf5b4eede22b22dece03a9074197ec631a1e /src/hid_core/resource_manager.cpp | |
| parent | Merge pull request #12686 from szepeviktor/typos3 (diff) | |
| download | yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.gz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.xz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.zip | |
service: hid: Fully implement abstract vibration
Diffstat (limited to 'src/hid_core/resource_manager.cpp')
| -rw-r--r-- | src/hid_core/resource_manager.cpp | 123 |
1 files changed, 122 insertions, 1 deletions
diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp index 2c5fe6d51..ca824b4a3 100644 --- a/src/hid_core/resource_manager.cpp +++ b/src/hid_core/resource_manager.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "core/hle/kernel/k_shared_memory.h" | 7 | #include "core/hle/kernel/k_shared_memory.h" |
| 8 | #include "core/hle/service/ipc_helpers.h" | 8 | #include "core/hle/service/ipc_helpers.h" |
| 9 | #include "hid_core/hid_core.h" | 9 | #include "hid_core/hid_core.h" |
| 10 | #include "hid_core/hid_util.h" | ||
| 10 | #include "hid_core/resource_manager.h" | 11 | #include "hid_core/resource_manager.h" |
| 11 | 12 | ||
| 12 | #include "hid_core/resources/applet_resource.h" | 13 | #include "hid_core/resources/applet_resource.h" |
| @@ -27,6 +28,10 @@ | |||
| 27 | #include "hid_core/resources/touch_screen/gesture.h" | 28 | #include "hid_core/resources/touch_screen/gesture.h" |
| 28 | #include "hid_core/resources/touch_screen/touch_screen.h" | 29 | #include "hid_core/resources/touch_screen/touch_screen.h" |
| 29 | #include "hid_core/resources/unique_pad/unique_pad.h" | 30 | #include "hid_core/resources/unique_pad/unique_pad.h" |
| 31 | #include "hid_core/resources/vibration/gc_vibration_device.h" | ||
| 32 | #include "hid_core/resources/vibration/n64_vibration_device.h" | ||
| 33 | #include "hid_core/resources/vibration/vibration_base.h" | ||
| 34 | #include "hid_core/resources/vibration/vibration_device.h" | ||
| 30 | 35 | ||
| 31 | namespace Service::HID { | 36 | namespace Service::HID { |
| 32 | 37 | ||
| @@ -52,6 +57,7 @@ void ResourceManager::Initialize() { | |||
| 52 | 57 | ||
| 53 | system.HIDCore().ReloadInputDevices(); | 58 | system.HIDCore().ReloadInputDevices(); |
| 54 | 59 | ||
| 60 | handheld_config = std::make_shared<HandheldConfig>(); | ||
| 55 | InitializeHidCommonSampler(); | 61 | InitializeHidCommonSampler(); |
| 56 | InitializeTouchScreenSampler(); | 62 | InitializeTouchScreenSampler(); |
| 57 | InitializeConsoleSixAxisSampler(); | 63 | InitializeConsoleSixAxisSampler(); |
| @@ -174,7 +180,7 @@ void ResourceManager::InitializeHidCommonSampler() { | |||
| 174 | debug_pad->SetAppletResource(applet_resource, &shared_mutex); | 180 | debug_pad->SetAppletResource(applet_resource, &shared_mutex); |
| 175 | digitizer->SetAppletResource(applet_resource, &shared_mutex); | 181 | digitizer->SetAppletResource(applet_resource, &shared_mutex); |
| 176 | keyboard->SetAppletResource(applet_resource, &shared_mutex); | 182 | keyboard->SetAppletResource(applet_resource, &shared_mutex); |
| 177 | npad->SetNpadExternals(applet_resource, &shared_mutex); | 183 | npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config); |
| 178 | six_axis->SetAppletResource(applet_resource, &shared_mutex); | 184 | six_axis->SetAppletResource(applet_resource, &shared_mutex); |
| 179 | mouse->SetAppletResource(applet_resource, &shared_mutex); | 185 | mouse->SetAppletResource(applet_resource, &shared_mutex); |
| 180 | debug_mouse->SetAppletResource(applet_resource, &shared_mutex); | 186 | debug_mouse->SetAppletResource(applet_resource, &shared_mutex); |
| @@ -257,6 +263,121 @@ void ResourceManager::EnableTouchScreen(u64 aruid, bool is_enabled) { | |||
| 257 | applet_resource->EnableTouchScreen(aruid, is_enabled); | 263 | applet_resource->EnableTouchScreen(aruid, is_enabled); |
| 258 | } | 264 | } |
| 259 | 265 | ||
| 266 | NpadVibrationBase* ResourceManager::GetVibrationDevice( | ||
| 267 | const Core::HID::VibrationDeviceHandle& handle) { | ||
| 268 | return npad->GetVibrationDevice(handle); | ||
| 269 | } | ||
| 270 | |||
| 271 | NpadN64VibrationDevice* ResourceManager::GetN64VibrationDevice( | ||
| 272 | const Core::HID::VibrationDeviceHandle& handle) { | ||
| 273 | return npad->GetN64VibrationDevice(handle); | ||
| 274 | } | ||
| 275 | |||
| 276 | NpadVibrationDevice* ResourceManager::GetNSVibrationDevice( | ||
| 277 | const Core::HID::VibrationDeviceHandle& handle) { | ||
| 278 | return npad->GetNSVibrationDevice(handle); | ||
| 279 | } | ||
| 280 | |||
| 281 | NpadGcVibrationDevice* ResourceManager::GetGcVibrationDevice( | ||
| 282 | const Core::HID::VibrationDeviceHandle& handle) { | ||
| 283 | return npad->GetGcVibrationDevice(handle); | ||
| 284 | } | ||
| 285 | |||
| 286 | Result ResourceManager::SetAruidValidForVibration(u64 aruid, bool is_enabled) { | ||
| 287 | std::scoped_lock lock{shared_mutex}; | ||
| 288 | const bool has_changed = applet_resource->SetAruidValidForVibration(aruid, is_enabled); | ||
| 289 | |||
| 290 | if (has_changed) { | ||
| 291 | auto devices = npad->GetAllVibrationDevices(); | ||
| 292 | for ([[maybe_unused]] auto* device : devices) { | ||
| 293 | // TODO | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | auto* vibration_handler = npad->GetVibrationHandler(); | ||
| 298 | if (aruid != vibration_handler->GetSessionAruid()) { | ||
| 299 | vibration_handler->EndPermitVibrationSession(); | ||
| 300 | } | ||
| 301 | |||
| 302 | return ResultSuccess; | ||
| 303 | } | ||
| 304 | |||
| 305 | void ResourceManager::SetForceHandheldStyleVibration(bool is_forced) { | ||
| 306 | handheld_config->is_force_handheld_style_vibration = is_forced; | ||
| 307 | } | ||
| 308 | |||
| 309 | Result ResourceManager::IsVibrationAruidActive(u64 aruid, bool& is_active) const { | ||
| 310 | std::scoped_lock lock{shared_mutex}; | ||
| 311 | is_active = applet_resource->IsVibrationAruidActive(aruid); | ||
| 312 | return ResultSuccess; | ||
| 313 | } | ||
| 314 | |||
| 315 | Result ResourceManager::GetVibrationDeviceInfo(Core::HID::VibrationDeviceInfo& device_info, | ||
| 316 | const Core::HID::VibrationDeviceHandle& handle) { | ||
| 317 | bool check_device_index = false; | ||
| 318 | |||
| 319 | const Result is_valid = IsVibrationHandleValid(handle); | ||
| 320 | if (is_valid.IsError()) { | ||
| 321 | return is_valid; | ||
| 322 | } | ||
| 323 | |||
| 324 | switch (handle.npad_type) { | ||
| 325 | case Core::HID::NpadStyleIndex::Fullkey: | ||
| 326 | case Core::HID::NpadStyleIndex::Handheld: | ||
| 327 | case Core::HID::NpadStyleIndex::JoyconDual: | ||
| 328 | case Core::HID::NpadStyleIndex::JoyconLeft: | ||
| 329 | case Core::HID::NpadStyleIndex::JoyconRight: | ||
| 330 | device_info.type = Core::HID::VibrationDeviceType::LinearResonantActuator; | ||
| 331 | check_device_index = true; | ||
| 332 | break; | ||
| 333 | case Core::HID::NpadStyleIndex::GameCube: | ||
| 334 | device_info.type = Core::HID::VibrationDeviceType::GcErm; | ||
| 335 | break; | ||
| 336 | case Core::HID::NpadStyleIndex::N64: | ||
| 337 | device_info.type = Core::HID::VibrationDeviceType::N64; | ||
| 338 | break; | ||
| 339 | default: | ||
| 340 | device_info.type = Core::HID::VibrationDeviceType::Unknown; | ||
| 341 | break; | ||
| 342 | } | ||
| 343 | |||
| 344 | device_info.position = Core::HID::VibrationDevicePosition::None; | ||
| 345 | if (check_device_index) { | ||
| 346 | switch (handle.device_index) { | ||
| 347 | case Core::HID::DeviceIndex::Left: | ||
| 348 | device_info.position = Core::HID::VibrationDevicePosition::Left; | ||
| 349 | break; | ||
| 350 | case Core::HID::DeviceIndex::Right: | ||
| 351 | device_info.position = Core::HID::VibrationDevicePosition::Right; | ||
| 352 | break; | ||
| 353 | case Core::HID::DeviceIndex::None: | ||
| 354 | default: | ||
| 355 | ASSERT_MSG(false, "DeviceIndex should never be None!"); | ||
| 356 | break; | ||
| 357 | } | ||
| 358 | } | ||
| 359 | return ResultSuccess; | ||
| 360 | } | ||
| 361 | |||
| 362 | Result ResourceManager::SendVibrationValue(u64 aruid, | ||
| 363 | const Core::HID::VibrationDeviceHandle& handle, | ||
| 364 | const Core::HID::VibrationValue& value) { | ||
| 365 | bool has_active_aruid{}; | ||
| 366 | NpadVibrationDevice* device{nullptr}; | ||
| 367 | Result result = IsVibrationAruidActive(aruid, has_active_aruid); | ||
| 368 | |||
| 369 | if (result.IsSuccess() && has_active_aruid) { | ||
| 370 | result = IsVibrationHandleValid(handle); | ||
| 371 | } | ||
| 372 | if (result.IsSuccess() && has_active_aruid) { | ||
| 373 | device = GetNSVibrationDevice(handle); | ||
| 374 | } | ||
| 375 | if (device != nullptr) { | ||
| 376 | result = device->SendVibrationValue(value); | ||
| 377 | } | ||
| 378 | return result; | ||
| 379 | } | ||
| 380 | |||
| 260 | void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) { | 381 | void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) { |
| 261 | auto& core_timing = system.CoreTiming(); | 382 | auto& core_timing = system.CoreTiming(); |
| 262 | debug_pad->OnUpdate(core_timing); | 383 | debug_pad->OnUpdate(core_timing); |