diff options
| author | 2023-09-16 11:40:35 -0400 | |
|---|---|---|
| committer | 2023-09-16 11:40:35 -0400 | |
| commit | fe771b59f4b1d2bf30bfc665eef68518949fe7ad (patch) | |
| tree | ec30d266f5f5e6f85ef137c9756c36b2523f78ab /src | |
| parent | Merge pull request #11517 from german77/amiibo-format (diff) | |
| parent | hid: service: Remove outdated field from npad (diff) | |
| download | yuzu-fe771b59f4b1d2bf30bfc665eef68518949fe7ad.tar.gz yuzu-fe771b59f4b1d2bf30bfc665eef68518949fe7ad.tar.xz yuzu-fe771b59f4b1d2bf30bfc665eef68518949fe7ad.zip | |
Merge pull request #11518 from german77/bad-npad
service: hid: Implement last active Npad and fix some errors.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hid/hid_core.cpp | 8 | ||||
| -rw-r--r-- | src/core/hid/hid_core.h | 7 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 41 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 20 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 2 |
5 files changed, 42 insertions, 36 deletions
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp index 7d6373414..cf53c04d9 100644 --- a/src/core/hid/hid_core.cpp +++ b/src/core/hid/hid_core.cpp | |||
| @@ -154,6 +154,14 @@ NpadIdType HIDCore::GetFirstDisconnectedNpadId() const { | |||
| 154 | return NpadIdType::Player1; | 154 | return NpadIdType::Player1; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | void HIDCore::SetLastActiveController(NpadIdType npad_id) { | ||
| 158 | last_active_controller = npad_id; | ||
| 159 | } | ||
| 160 | |||
| 161 | NpadIdType HIDCore::GetLastActiveController() const { | ||
| 162 | return last_active_controller; | ||
| 163 | } | ||
| 164 | |||
| 157 | void HIDCore::EnableAllControllerConfiguration() { | 165 | void HIDCore::EnableAllControllerConfiguration() { |
| 158 | player_1->EnableConfiguration(); | 166 | player_1->EnableConfiguration(); |
| 159 | player_2->EnableConfiguration(); | 167 | player_2->EnableConfiguration(); |
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h index 5fe36551e..80abab18b 100644 --- a/src/core/hid/hid_core.h +++ b/src/core/hid/hid_core.h | |||
| @@ -48,6 +48,12 @@ public: | |||
| 48 | /// Returns the first disconnected npad id | 48 | /// Returns the first disconnected npad id |
| 49 | NpadIdType GetFirstDisconnectedNpadId() const; | 49 | NpadIdType GetFirstDisconnectedNpadId() const; |
| 50 | 50 | ||
| 51 | /// Sets the npad id of the last active controller | ||
| 52 | void SetLastActiveController(NpadIdType npad_id); | ||
| 53 | |||
| 54 | /// Returns the npad id of the last controller that pushed a button | ||
| 55 | NpadIdType GetLastActiveController() const; | ||
| 56 | |||
| 51 | /// Sets all emulated controllers into configuring mode. | 57 | /// Sets all emulated controllers into configuring mode. |
| 52 | void EnableAllControllerConfiguration(); | 58 | void EnableAllControllerConfiguration(); |
| 53 | 59 | ||
| @@ -77,6 +83,7 @@ private: | |||
| 77 | std::unique_ptr<EmulatedConsole> console; | 83 | std::unique_ptr<EmulatedConsole> console; |
| 78 | std::unique_ptr<EmulatedDevices> devices; | 84 | std::unique_ptr<EmulatedDevices> devices; |
| 79 | NpadStyleTag supported_style_tag{NpadStyleSet::All}; | 85 | NpadStyleTag supported_style_tag{NpadStyleSet::All}; |
| 86 | NpadIdType last_active_controller{NpadIdType::Handheld}; | ||
| 80 | }; | 87 | }; |
| 81 | 88 | ||
| 82 | } // namespace Core::HID | 89 | } // namespace Core::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 3b349b4c4..e7d25e86e 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -193,7 +193,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 193 | shared_memory->system_properties.use_minus.Assign(1); | 193 | shared_memory->system_properties.use_minus.Assign(1); |
| 194 | shared_memory->system_properties.is_charging_joy_dual.Assign( | 194 | shared_memory->system_properties.is_charging_joy_dual.Assign( |
| 195 | battery_level.dual.is_charging); | 195 | battery_level.dual.is_charging); |
| 196 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::SwitchProController; | 196 | shared_memory->applet_footer_type = AppletFooterUiType::SwitchProController; |
| 197 | shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1); | 197 | shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1); |
| 198 | break; | 198 | break; |
| 199 | case Core::HID::NpadStyleIndex::Handheld: | 199 | case Core::HID::NpadStyleIndex::Handheld: |
| @@ -216,8 +216,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 216 | shared_memory->system_properties.is_charging_joy_right.Assign( | 216 | shared_memory->system_properties.is_charging_joy_right.Assign( |
| 217 | battery_level.right.is_charging); | 217 | battery_level.right.is_charging); |
| 218 | shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; | 218 | shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; |
| 219 | shared_memory->applet_nfc_xcd.applet_footer.type = | 219 | shared_memory->applet_footer_type = AppletFooterUiType::HandheldJoyConLeftJoyConRight; |
| 220 | AppletFooterUiType::HandheldJoyConLeftJoyConRight; | ||
| 221 | shared_memory->sixaxis_handheld_properties.is_newly_assigned.Assign(1); | 220 | shared_memory->sixaxis_handheld_properties.is_newly_assigned.Assign(1); |
| 222 | break; | 221 | break; |
| 223 | case Core::HID::NpadStyleIndex::JoyconDual: | 222 | case Core::HID::NpadStyleIndex::JoyconDual: |
| @@ -247,19 +246,19 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 247 | shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; | 246 | shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; |
| 248 | 247 | ||
| 249 | if (controller.is_dual_left_connected && controller.is_dual_right_connected) { | 248 | if (controller.is_dual_left_connected && controller.is_dual_right_connected) { |
| 250 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDual; | 249 | shared_memory->applet_footer_type = AppletFooterUiType::JoyDual; |
| 251 | shared_memory->fullkey_color.fullkey = body_colors.left; | 250 | shared_memory->fullkey_color.fullkey = body_colors.left; |
| 252 | shared_memory->battery_level_dual = battery_level.left.battery_level; | 251 | shared_memory->battery_level_dual = battery_level.left.battery_level; |
| 253 | shared_memory->system_properties.is_charging_joy_dual.Assign( | 252 | shared_memory->system_properties.is_charging_joy_dual.Assign( |
| 254 | battery_level.left.is_charging); | 253 | battery_level.left.is_charging); |
| 255 | } else if (controller.is_dual_left_connected) { | 254 | } else if (controller.is_dual_left_connected) { |
| 256 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDualLeftOnly; | 255 | shared_memory->applet_footer_type = AppletFooterUiType::JoyDualLeftOnly; |
| 257 | shared_memory->fullkey_color.fullkey = body_colors.left; | 256 | shared_memory->fullkey_color.fullkey = body_colors.left; |
| 258 | shared_memory->battery_level_dual = battery_level.left.battery_level; | 257 | shared_memory->battery_level_dual = battery_level.left.battery_level; |
| 259 | shared_memory->system_properties.is_charging_joy_dual.Assign( | 258 | shared_memory->system_properties.is_charging_joy_dual.Assign( |
| 260 | battery_level.left.is_charging); | 259 | battery_level.left.is_charging); |
| 261 | } else { | 260 | } else { |
| 262 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDualRightOnly; | 261 | shared_memory->applet_footer_type = AppletFooterUiType::JoyDualRightOnly; |
| 263 | shared_memory->fullkey_color.fullkey = body_colors.right; | 262 | shared_memory->fullkey_color.fullkey = body_colors.right; |
| 264 | shared_memory->battery_level_dual = battery_level.right.battery_level; | 263 | shared_memory->battery_level_dual = battery_level.right.battery_level; |
| 265 | shared_memory->system_properties.is_charging_joy_dual.Assign( | 264 | shared_memory->system_properties.is_charging_joy_dual.Assign( |
| @@ -278,7 +277,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 278 | shared_memory->system_properties.use_minus.Assign(1); | 277 | shared_memory->system_properties.use_minus.Assign(1); |
| 279 | shared_memory->system_properties.is_charging_joy_left.Assign( | 278 | shared_memory->system_properties.is_charging_joy_left.Assign( |
| 280 | battery_level.left.is_charging); | 279 | battery_level.left.is_charging); |
| 281 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal; | 280 | shared_memory->applet_footer_type = AppletFooterUiType::JoyLeftHorizontal; |
| 282 | shared_memory->sixaxis_left_properties.is_newly_assigned.Assign(1); | 281 | shared_memory->sixaxis_left_properties.is_newly_assigned.Assign(1); |
| 283 | break; | 282 | break; |
| 284 | case Core::HID::NpadStyleIndex::JoyconRight: | 283 | case Core::HID::NpadStyleIndex::JoyconRight: |
| @@ -293,7 +292,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 293 | shared_memory->system_properties.use_plus.Assign(1); | 292 | shared_memory->system_properties.use_plus.Assign(1); |
| 294 | shared_memory->system_properties.is_charging_joy_right.Assign( | 293 | shared_memory->system_properties.is_charging_joy_right.Assign( |
| 295 | battery_level.right.is_charging); | 294 | battery_level.right.is_charging); |
| 296 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyRightHorizontal; | 295 | shared_memory->applet_footer_type = AppletFooterUiType::JoyRightHorizontal; |
| 297 | shared_memory->sixaxis_right_properties.is_newly_assigned.Assign(1); | 296 | shared_memory->sixaxis_right_properties.is_newly_assigned.Assign(1); |
| 298 | break; | 297 | break; |
| 299 | case Core::HID::NpadStyleIndex::GameCube: | 298 | case Core::HID::NpadStyleIndex::GameCube: |
| @@ -314,12 +313,12 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 314 | case Core::HID::NpadStyleIndex::SNES: | 313 | case Core::HID::NpadStyleIndex::SNES: |
| 315 | shared_memory->style_tag.lucia.Assign(1); | 314 | shared_memory->style_tag.lucia.Assign(1); |
| 316 | shared_memory->device_type.fullkey.Assign(1); | 315 | shared_memory->device_type.fullkey.Assign(1); |
| 317 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::Lucia; | 316 | shared_memory->applet_footer_type = AppletFooterUiType::Lucia; |
| 318 | break; | 317 | break; |
| 319 | case Core::HID::NpadStyleIndex::N64: | 318 | case Core::HID::NpadStyleIndex::N64: |
| 320 | shared_memory->style_tag.lagoon.Assign(1); | 319 | shared_memory->style_tag.lagoon.Assign(1); |
| 321 | shared_memory->device_type.fullkey.Assign(1); | 320 | shared_memory->device_type.fullkey.Assign(1); |
| 322 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::Lagon; | 321 | shared_memory->applet_footer_type = AppletFooterUiType::Lagon; |
| 323 | break; | 322 | break; |
| 324 | case Core::HID::NpadStyleIndex::SegaGenesis: | 323 | case Core::HID::NpadStyleIndex::SegaGenesis: |
| 325 | shared_memory->style_tag.lager.Assign(1); | 324 | shared_memory->style_tag.lager.Assign(1); |
| @@ -419,9 +418,17 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { | |||
| 419 | std::scoped_lock lock{mutex}; | 418 | std::scoped_lock lock{mutex}; |
| 420 | auto& controller = GetControllerFromNpadIdType(npad_id); | 419 | auto& controller = GetControllerFromNpadIdType(npad_id); |
| 421 | const auto controller_type = controller.device->GetNpadStyleIndex(); | 420 | const auto controller_type = controller.device->GetNpadStyleIndex(); |
| 421 | |||
| 422 | if (!controller.device->IsConnected() && controller.is_connected) { | ||
| 423 | DisconnectNpad(npad_id); | ||
| 424 | return; | ||
| 425 | } | ||
| 422 | if (!controller.device->IsConnected()) { | 426 | if (!controller.device->IsConnected()) { |
| 423 | return; | 427 | return; |
| 424 | } | 428 | } |
| 429 | if (controller.device->IsConnected() && !controller.is_connected) { | ||
| 430 | InitNewlyAddedController(npad_id); | ||
| 431 | } | ||
| 425 | 432 | ||
| 426 | // This function is unique to yuzu for the turbo buttons and motion to work properly | 433 | // This function is unique to yuzu for the turbo buttons and motion to work properly |
| 427 | controller.device->StatusUpdate(); | 434 | controller.device->StatusUpdate(); |
| @@ -468,6 +475,10 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { | |||
| 468 | pad_entry.npad_buttons.l.Assign(button_state.zl); | 475 | pad_entry.npad_buttons.l.Assign(button_state.zl); |
| 469 | pad_entry.npad_buttons.r.Assign(button_state.zr); | 476 | pad_entry.npad_buttons.r.Assign(button_state.zr); |
| 470 | } | 477 | } |
| 478 | |||
| 479 | if (pad_entry.npad_buttons.raw != Core::HID::NpadButton::None) { | ||
| 480 | hid_core.SetLastActiveController(npad_id); | ||
| 481 | } | ||
| 471 | } | 482 | } |
| 472 | 483 | ||
| 473 | void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 484 | void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| @@ -736,14 +747,6 @@ void Controller_NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) { | |||
| 736 | 747 | ||
| 737 | // Once SetSupportedStyleSet is called controllers are fully initialized | 748 | // Once SetSupportedStyleSet is called controllers are fully initialized |
| 738 | is_controller_initialized = true; | 749 | is_controller_initialized = true; |
| 739 | |||
| 740 | // Connect all active controllers | ||
| 741 | for (auto& controller : controller_data) { | ||
| 742 | const auto& device = controller.device; | ||
| 743 | if (device->IsConnected()) { | ||
| 744 | AddNewControllerAt(device->GetNpadStyleIndex(), device->GetNpadIdType()); | ||
| 745 | } | ||
| 746 | } | ||
| 747 | } | 750 | } |
| 748 | 751 | ||
| 749 | Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { | 752 | Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { |
| @@ -1116,7 +1119,7 @@ Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { | |||
| 1116 | .left = {}, | 1119 | .left = {}, |
| 1117 | .right = {}, | 1120 | .right = {}, |
| 1118 | }; | 1121 | }; |
| 1119 | shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::None; | 1122 | shared_memory->applet_footer_type = AppletFooterUiType::None; |
| 1120 | 1123 | ||
| 1121 | controller.is_dual_left_connected = true; | 1124 | controller.is_dual_left_connected = true; |
| 1122 | controller.is_dual_right_connected = true; | 1125 | controller.is_dual_right_connected = true; |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 776411261..09707d2f8 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -360,7 +360,7 @@ private: | |||
| 360 | enum class AppletFooterUiType : u8 { | 360 | enum class AppletFooterUiType : u8 { |
| 361 | None = 0, | 361 | None = 0, |
| 362 | HandheldNone = 1, | 362 | HandheldNone = 1, |
| 363 | HandheldJoyConLeftOnly = 1, | 363 | HandheldJoyConLeftOnly = 2, |
| 364 | HandheldJoyConRightOnly = 3, | 364 | HandheldJoyConRightOnly = 3, |
| 365 | HandheldJoyConLeftJoyConRight = 4, | 365 | HandheldJoyConLeftJoyConRight = 4, |
| 366 | JoyDual = 5, | 366 | JoyDual = 5, |
| @@ -382,13 +382,6 @@ private: | |||
| 382 | Lagon = 21, | 382 | Lagon = 21, |
| 383 | }; | 383 | }; |
| 384 | 384 | ||
| 385 | struct AppletFooterUi { | ||
| 386 | AppletFooterUiAttributes attributes{}; | ||
| 387 | AppletFooterUiType type{AppletFooterUiType::None}; | ||
| 388 | INSERT_PADDING_BYTES(0x5B); // Reserved | ||
| 389 | }; | ||
| 390 | static_assert(sizeof(AppletFooterUi) == 0x60, "AppletFooterUi is an invalid size"); | ||
| 391 | |||
| 392 | // This is nn::hid::NpadLarkType | 385 | // This is nn::hid::NpadLarkType |
| 393 | enum class NpadLarkType : u32 { | 386 | enum class NpadLarkType : u32 { |
| 394 | Invalid, | 387 | Invalid, |
| @@ -419,13 +412,6 @@ private: | |||
| 419 | U, | 412 | U, |
| 420 | }; | 413 | }; |
| 421 | 414 | ||
| 422 | struct AppletNfcXcd { | ||
| 423 | union { | ||
| 424 | AppletFooterUi applet_footer{}; | ||
| 425 | Lifo<NfcXcdDeviceHandleStateImpl, 0x2> nfc_xcd_device_lifo; | ||
| 426 | }; | ||
| 427 | }; | ||
| 428 | |||
| 429 | // This is nn::hid::detail::NpadInternalState | 415 | // This is nn::hid::detail::NpadInternalState |
| 430 | struct NpadInternalState { | 416 | struct NpadInternalState { |
| 431 | Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None}; | 417 | Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None}; |
| @@ -452,7 +438,9 @@ private: | |||
| 452 | Core::HID::NpadBatteryLevel battery_level_dual{}; | 438 | Core::HID::NpadBatteryLevel battery_level_dual{}; |
| 453 | Core::HID::NpadBatteryLevel battery_level_left{}; | 439 | Core::HID::NpadBatteryLevel battery_level_left{}; |
| 454 | Core::HID::NpadBatteryLevel battery_level_right{}; | 440 | Core::HID::NpadBatteryLevel battery_level_right{}; |
| 455 | AppletNfcXcd applet_nfc_xcd{}; | 441 | AppletFooterUiAttributes applet_footer_attributes{}; |
| 442 | AppletFooterUiType applet_footer_type{AppletFooterUiType::None}; | ||
| 443 | INSERT_PADDING_BYTES(0x5B); // Reserved | ||
| 456 | INSERT_PADDING_BYTES(0x20); // Unknown | 444 | INSERT_PADDING_BYTES(0x20); // Unknown |
| 457 | Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{}; | 445 | Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{}; |
| 458 | NpadLarkType lark_type_l_and_main{}; | 446 | NpadLarkType lark_type_l_and_main{}; |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index fd466db7b..3657e61d3 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -2768,7 +2768,7 @@ private: | |||
| 2768 | 2768 | ||
| 2769 | IPC::ResponseBuilder rb{ctx, 3}; | 2769 | IPC::ResponseBuilder rb{ctx, 3}; |
| 2770 | rb.Push(ResultSuccess); | 2770 | rb.Push(ResultSuccess); |
| 2771 | rb.PushEnum(Core::HID::NpadIdType::Handheld); | 2771 | rb.PushEnum(system.HIDCore().GetLastActiveController()); |
| 2772 | } | 2772 | } |
| 2773 | 2773 | ||
| 2774 | void GetUniquePadsFromNpad(HLERequestContext& ctx) { | 2774 | void GetUniquePadsFromNpad(HLERequestContext& ctx) { |