mirror of
https://github.com/starr-dusT/yuzu-mainline
synced 2024-03-05 21:12:25 -08:00
service: hid: Add error handling to setNpadAssignment and variants
This commit is contained in:
parent
74d1b9a254
commit
7aa1d10655
@ -701,11 +701,12 @@ Controller_NPad::NpadCommunicationMode Controller_NPad::GetNpadCommunicationMode
|
|||||||
return communication_mode;
|
return communication_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceType npad_device_type,
|
ResultCode Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id,
|
||||||
|
NpadJoyDeviceType npad_device_type,
|
||||||
NpadJoyAssignmentMode assignment_mode) {
|
NpadJoyAssignmentMode assignment_mode) {
|
||||||
if (!IsNpadIdValid(npad_id)) {
|
if (!IsNpadIdValid(npad_id)) {
|
||||||
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
|
LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id);
|
||||||
return;
|
return InvalidNpadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& controller = GetControllerFromNpadIdType(npad_id);
|
auto& controller = GetControllerFromNpadIdType(npad_id);
|
||||||
@ -714,7 +715,7 @@ void Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!controller.device->IsConnected()) {
|
if (!controller.device->IsConnected()) {
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assignment_mode == NpadJoyAssignmentMode::Dual) {
|
if (assignment_mode == NpadJoyAssignmentMode::Dual) {
|
||||||
@ -723,34 +724,34 @@ void Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceTy
|
|||||||
controller.is_dual_left_connected = true;
|
controller.is_dual_left_connected = true;
|
||||||
controller.is_dual_right_connected = false;
|
controller.is_dual_right_connected = false;
|
||||||
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
|
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
if (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight) {
|
if (controller.device->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::JoyconRight) {
|
||||||
DisconnectNpad(npad_id);
|
DisconnectNpad(npad_id);
|
||||||
controller.is_dual_left_connected = false;
|
controller.is_dual_left_connected = false;
|
||||||
controller.is_dual_right_connected = true;
|
controller.is_dual_right_connected = true;
|
||||||
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
|
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id, true);
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is for NpadJoyAssignmentMode::Single
|
// This is for NpadJoyAssignmentMode::Single
|
||||||
|
|
||||||
// Only JoyconDual get affected by this function
|
// Only JoyconDual get affected by this function
|
||||||
if (controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::JoyconDual) {
|
if (controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::JoyconDual) {
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller.is_dual_left_connected && !controller.is_dual_right_connected) {
|
if (controller.is_dual_left_connected && !controller.is_dual_right_connected) {
|
||||||
DisconnectNpad(npad_id);
|
DisconnectNpad(npad_id);
|
||||||
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
|
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconLeft, npad_id, true);
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
if (!controller.is_dual_left_connected && controller.is_dual_right_connected) {
|
if (!controller.is_dual_left_connected && controller.is_dual_right_connected) {
|
||||||
DisconnectNpad(npad_id);
|
DisconnectNpad(npad_id);
|
||||||
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
|
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconRight, npad_id, true);
|
||||||
return;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have two controllers connected to the same npad_id we need to split them
|
// We have two controllers connected to the same npad_id we need to split them
|
||||||
@ -768,6 +769,7 @@ void Controller_NPad::SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceTy
|
|||||||
controller_2.is_dual_right_connected = false;
|
controller_2.is_dual_right_connected = false;
|
||||||
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id_2, true);
|
UpdateControllerAt(Core::HID::NpadStyleIndex::JoyconDual, npad_id_2, true);
|
||||||
}
|
}
|
||||||
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id,
|
bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id,
|
||||||
|
@ -107,7 +107,7 @@ public:
|
|||||||
void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_);
|
void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_);
|
||||||
NpadCommunicationMode GetNpadCommunicationMode() const;
|
NpadCommunicationMode GetNpadCommunicationMode() const;
|
||||||
|
|
||||||
void SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceType npad_device_type,
|
ResultCode SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceType npad_device_type,
|
||||||
NpadJoyAssignmentMode assignment_mode);
|
NpadJoyAssignmentMode assignment_mode);
|
||||||
|
|
||||||
bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
|
bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
|
||||||
|
@ -1026,15 +1026,16 @@ void Hid::SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx
|
|||||||
|
|
||||||
const auto parameters{rp.PopRaw<Parameters>()};
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
applet_resource->GetController<Controller_NPad>(HidController::NPad)
|
auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad);
|
||||||
.SetNpadMode(parameters.npad_id, Controller_NPad::NpadJoyDeviceType::Left,
|
const auto result =
|
||||||
|
controller.SetNpadMode(parameters.npad_id, Controller_NPad::NpadJoyDeviceType::Left,
|
||||||
Controller_NPad::NpadJoyAssignmentMode::Single);
|
Controller_NPad::NpadJoyAssignmentMode::Single);
|
||||||
|
|
||||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||||
parameters.applet_resource_user_id);
|
parameters.applet_resource_user_id);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) {
|
void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) {
|
||||||
@ -1049,8 +1050,8 @@ void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) {
|
|||||||
|
|
||||||
const auto parameters{rp.PopRaw<Parameters>()};
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
applet_resource->GetController<Controller_NPad>(HidController::NPad)
|
auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad);
|
||||||
.SetNpadMode(parameters.npad_id, parameters.npad_joy_device_type,
|
const auto result = controller.SetNpadMode(parameters.npad_id, parameters.npad_joy_device_type,
|
||||||
Controller_NPad::NpadJoyAssignmentMode::Single);
|
Controller_NPad::NpadJoyAssignmentMode::Single);
|
||||||
|
|
||||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
|
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
|
||||||
@ -1058,7 +1059,7 @@ void Hid::SetNpadJoyAssignmentModeSingle(Kernel::HLERequestContext& ctx) {
|
|||||||
parameters.npad_joy_device_type);
|
parameters.npad_joy_device_type);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) {
|
void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) {
|
||||||
@ -1072,14 +1073,15 @@ void Hid::SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) {
|
|||||||
|
|
||||||
const auto parameters{rp.PopRaw<Parameters>()};
|
const auto parameters{rp.PopRaw<Parameters>()};
|
||||||
|
|
||||||
applet_resource->GetController<Controller_NPad>(HidController::NPad)
|
auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad);
|
||||||
.SetNpadMode(parameters.npad_id, {}, Controller_NPad::NpadJoyAssignmentMode::Dual);
|
const auto result = controller.SetNpadMode(parameters.npad_id, {},
|
||||||
|
Controller_NPad::NpadJoyAssignmentMode::Dual);
|
||||||
|
|
||||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||||
parameters.applet_resource_user_id);
|
parameters.applet_resource_user_id);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) {
|
void Hid::MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user