Merge pull request #11518 from german77/bad-npad

service: hid: Implement last active Npad and fix some errors.
This commit is contained in:
liamwhite 2023-09-16 11:40:35 -04:00 committed by GitHub
commit fe771b59f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 36 deletions

View File

@ -154,6 +154,14 @@ NpadIdType HIDCore::GetFirstDisconnectedNpadId() const {
return NpadIdType::Player1; return NpadIdType::Player1;
} }
void HIDCore::SetLastActiveController(NpadIdType npad_id) {
last_active_controller = npad_id;
}
NpadIdType HIDCore::GetLastActiveController() const {
return last_active_controller;
}
void HIDCore::EnableAllControllerConfiguration() { void HIDCore::EnableAllControllerConfiguration() {
player_1->EnableConfiguration(); player_1->EnableConfiguration();
player_2->EnableConfiguration(); player_2->EnableConfiguration();

View File

@ -48,6 +48,12 @@ public:
/// Returns the first disconnected npad id /// Returns the first disconnected npad id
NpadIdType GetFirstDisconnectedNpadId() const; NpadIdType GetFirstDisconnectedNpadId() const;
/// Sets the npad id of the last active controller
void SetLastActiveController(NpadIdType npad_id);
/// Returns the npad id of the last controller that pushed a button
NpadIdType GetLastActiveController() const;
/// Sets all emulated controllers into configuring mode. /// Sets all emulated controllers into configuring mode.
void EnableAllControllerConfiguration(); void EnableAllControllerConfiguration();
@ -77,6 +83,7 @@ private:
std::unique_ptr<EmulatedConsole> console; std::unique_ptr<EmulatedConsole> console;
std::unique_ptr<EmulatedDevices> devices; std::unique_ptr<EmulatedDevices> devices;
NpadStyleTag supported_style_tag{NpadStyleSet::All}; NpadStyleTag supported_style_tag{NpadStyleSet::All};
NpadIdType last_active_controller{NpadIdType::Handheld};
}; };
} // namespace Core::HID } // namespace Core::HID

View File

@ -193,7 +193,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
shared_memory->system_properties.use_minus.Assign(1); shared_memory->system_properties.use_minus.Assign(1);
shared_memory->system_properties.is_charging_joy_dual.Assign( shared_memory->system_properties.is_charging_joy_dual.Assign(
battery_level.dual.is_charging); battery_level.dual.is_charging);
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::SwitchProController; shared_memory->applet_footer_type = AppletFooterUiType::SwitchProController;
shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1); shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1);
break; break;
case Core::HID::NpadStyleIndex::Handheld: case Core::HID::NpadStyleIndex::Handheld:
@ -216,8 +216,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
shared_memory->system_properties.is_charging_joy_right.Assign( shared_memory->system_properties.is_charging_joy_right.Assign(
battery_level.right.is_charging); battery_level.right.is_charging);
shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual;
shared_memory->applet_nfc_xcd.applet_footer.type = shared_memory->applet_footer_type = AppletFooterUiType::HandheldJoyConLeftJoyConRight;
AppletFooterUiType::HandheldJoyConLeftJoyConRight;
shared_memory->sixaxis_handheld_properties.is_newly_assigned.Assign(1); shared_memory->sixaxis_handheld_properties.is_newly_assigned.Assign(1);
break; break;
case Core::HID::NpadStyleIndex::JoyconDual: case Core::HID::NpadStyleIndex::JoyconDual:
@ -247,19 +246,19 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual;
if (controller.is_dual_left_connected && controller.is_dual_right_connected) { if (controller.is_dual_left_connected && controller.is_dual_right_connected) {
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDual; shared_memory->applet_footer_type = AppletFooterUiType::JoyDual;
shared_memory->fullkey_color.fullkey = body_colors.left; shared_memory->fullkey_color.fullkey = body_colors.left;
shared_memory->battery_level_dual = battery_level.left.battery_level; shared_memory->battery_level_dual = battery_level.left.battery_level;
shared_memory->system_properties.is_charging_joy_dual.Assign( shared_memory->system_properties.is_charging_joy_dual.Assign(
battery_level.left.is_charging); battery_level.left.is_charging);
} else if (controller.is_dual_left_connected) { } else if (controller.is_dual_left_connected) {
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDualLeftOnly; shared_memory->applet_footer_type = AppletFooterUiType::JoyDualLeftOnly;
shared_memory->fullkey_color.fullkey = body_colors.left; shared_memory->fullkey_color.fullkey = body_colors.left;
shared_memory->battery_level_dual = battery_level.left.battery_level; shared_memory->battery_level_dual = battery_level.left.battery_level;
shared_memory->system_properties.is_charging_joy_dual.Assign( shared_memory->system_properties.is_charging_joy_dual.Assign(
battery_level.left.is_charging); battery_level.left.is_charging);
} else { } else {
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyDualRightOnly; shared_memory->applet_footer_type = AppletFooterUiType::JoyDualRightOnly;
shared_memory->fullkey_color.fullkey = body_colors.right; shared_memory->fullkey_color.fullkey = body_colors.right;
shared_memory->battery_level_dual = battery_level.right.battery_level; shared_memory->battery_level_dual = battery_level.right.battery_level;
shared_memory->system_properties.is_charging_joy_dual.Assign( shared_memory->system_properties.is_charging_joy_dual.Assign(
@ -278,7 +277,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
shared_memory->system_properties.use_minus.Assign(1); shared_memory->system_properties.use_minus.Assign(1);
shared_memory->system_properties.is_charging_joy_left.Assign( shared_memory->system_properties.is_charging_joy_left.Assign(
battery_level.left.is_charging); battery_level.left.is_charging);
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal; shared_memory->applet_footer_type = AppletFooterUiType::JoyLeftHorizontal;
shared_memory->sixaxis_left_properties.is_newly_assigned.Assign(1); shared_memory->sixaxis_left_properties.is_newly_assigned.Assign(1);
break; break;
case Core::HID::NpadStyleIndex::JoyconRight: case Core::HID::NpadStyleIndex::JoyconRight:
@ -293,7 +292,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
shared_memory->system_properties.use_plus.Assign(1); shared_memory->system_properties.use_plus.Assign(1);
shared_memory->system_properties.is_charging_joy_right.Assign( shared_memory->system_properties.is_charging_joy_right.Assign(
battery_level.right.is_charging); battery_level.right.is_charging);
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyRightHorizontal; shared_memory->applet_footer_type = AppletFooterUiType::JoyRightHorizontal;
shared_memory->sixaxis_right_properties.is_newly_assigned.Assign(1); shared_memory->sixaxis_right_properties.is_newly_assigned.Assign(1);
break; break;
case Core::HID::NpadStyleIndex::GameCube: case Core::HID::NpadStyleIndex::GameCube:
@ -314,12 +313,12 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
case Core::HID::NpadStyleIndex::SNES: case Core::HID::NpadStyleIndex::SNES:
shared_memory->style_tag.lucia.Assign(1); shared_memory->style_tag.lucia.Assign(1);
shared_memory->device_type.fullkey.Assign(1); shared_memory->device_type.fullkey.Assign(1);
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::Lucia; shared_memory->applet_footer_type = AppletFooterUiType::Lucia;
break; break;
case Core::HID::NpadStyleIndex::N64: case Core::HID::NpadStyleIndex::N64:
shared_memory->style_tag.lagoon.Assign(1); shared_memory->style_tag.lagoon.Assign(1);
shared_memory->device_type.fullkey.Assign(1); shared_memory->device_type.fullkey.Assign(1);
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::Lagon; shared_memory->applet_footer_type = AppletFooterUiType::Lagon;
break; break;
case Core::HID::NpadStyleIndex::SegaGenesis: case Core::HID::NpadStyleIndex::SegaGenesis:
shared_memory->style_tag.lager.Assign(1); shared_memory->style_tag.lager.Assign(1);
@ -419,9 +418,17 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
auto& controller = GetControllerFromNpadIdType(npad_id); auto& controller = GetControllerFromNpadIdType(npad_id);
const auto controller_type = controller.device->GetNpadStyleIndex(); const auto controller_type = controller.device->GetNpadStyleIndex();
if (!controller.device->IsConnected() && controller.is_connected) {
DisconnectNpad(npad_id);
return;
}
if (!controller.device->IsConnected()) { if (!controller.device->IsConnected()) {
return; return;
} }
if (controller.device->IsConnected() && !controller.is_connected) {
InitNewlyAddedController(npad_id);
}
// This function is unique to yuzu for the turbo buttons and motion to work properly // This function is unique to yuzu for the turbo buttons and motion to work properly
controller.device->StatusUpdate(); controller.device->StatusUpdate();
@ -468,6 +475,10 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {
pad_entry.npad_buttons.l.Assign(button_state.zl); pad_entry.npad_buttons.l.Assign(button_state.zl);
pad_entry.npad_buttons.r.Assign(button_state.zr); pad_entry.npad_buttons.r.Assign(button_state.zr);
} }
if (pad_entry.npad_buttons.raw != Core::HID::NpadButton::None) {
hid_core.SetLastActiveController(npad_id);
}
} }
void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
@ -736,14 +747,6 @@ void Controller_NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) {
// Once SetSupportedStyleSet is called controllers are fully initialized // Once SetSupportedStyleSet is called controllers are fully initialized
is_controller_initialized = true; is_controller_initialized = true;
// Connect all active controllers
for (auto& controller : controller_data) {
const auto& device = controller.device;
if (device->IsConnected()) {
AddNewControllerAt(device->GetNpadStyleIndex(), device->GetNpadIdType());
}
}
} }
Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const {
@ -1116,7 +1119,7 @@ Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
.left = {}, .left = {},
.right = {}, .right = {},
}; };
shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::None; shared_memory->applet_footer_type = AppletFooterUiType::None;
controller.is_dual_left_connected = true; controller.is_dual_left_connected = true;
controller.is_dual_right_connected = true; controller.is_dual_right_connected = true;

View File

@ -360,7 +360,7 @@ private:
enum class AppletFooterUiType : u8 { enum class AppletFooterUiType : u8 {
None = 0, None = 0,
HandheldNone = 1, HandheldNone = 1,
HandheldJoyConLeftOnly = 1, HandheldJoyConLeftOnly = 2,
HandheldJoyConRightOnly = 3, HandheldJoyConRightOnly = 3,
HandheldJoyConLeftJoyConRight = 4, HandheldJoyConLeftJoyConRight = 4,
JoyDual = 5, JoyDual = 5,
@ -382,13 +382,6 @@ private:
Lagon = 21, Lagon = 21,
}; };
struct AppletFooterUi {
AppletFooterUiAttributes attributes{};
AppletFooterUiType type{AppletFooterUiType::None};
INSERT_PADDING_BYTES(0x5B); // Reserved
};
static_assert(sizeof(AppletFooterUi) == 0x60, "AppletFooterUi is an invalid size");
// This is nn::hid::NpadLarkType // This is nn::hid::NpadLarkType
enum class NpadLarkType : u32 { enum class NpadLarkType : u32 {
Invalid, Invalid,
@ -419,13 +412,6 @@ private:
U, U,
}; };
struct AppletNfcXcd {
union {
AppletFooterUi applet_footer{};
Lifo<NfcXcdDeviceHandleStateImpl, 0x2> nfc_xcd_device_lifo;
};
};
// This is nn::hid::detail::NpadInternalState // This is nn::hid::detail::NpadInternalState
struct NpadInternalState { struct NpadInternalState {
Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None}; Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None};
@ -452,7 +438,9 @@ private:
Core::HID::NpadBatteryLevel battery_level_dual{}; Core::HID::NpadBatteryLevel battery_level_dual{};
Core::HID::NpadBatteryLevel battery_level_left{}; Core::HID::NpadBatteryLevel battery_level_left{};
Core::HID::NpadBatteryLevel battery_level_right{}; Core::HID::NpadBatteryLevel battery_level_right{};
AppletNfcXcd applet_nfc_xcd{}; AppletFooterUiAttributes applet_footer_attributes{};
AppletFooterUiType applet_footer_type{AppletFooterUiType::None};
INSERT_PADDING_BYTES(0x5B); // Reserved
INSERT_PADDING_BYTES(0x20); // Unknown INSERT_PADDING_BYTES(0x20); // Unknown
Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{}; Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{};
NpadLarkType lark_type_l_and_main{}; NpadLarkType lark_type_l_and_main{};

View File

@ -2768,7 +2768,7 @@ private:
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
rb.PushEnum(Core::HID::NpadIdType::Handheld); rb.PushEnum(system.HIDCore().GetLastActiveController());
} }
void GetUniquePadsFromNpad(HLERequestContext& ctx) { void GetUniquePadsFromNpad(HLERequestContext& ctx) {