summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2022-05-21 23:48:05 +0200
committerNarr the Reg <juangerman-13@hotmail.com>2022-05-27 17:21:10 +0200
commit390d49c5f17f12f98c80867915bb30991a40ea31 (patch)
treea061c6d1385f8b9555ab59b2fce37ba0ddf409f9 /src/core/hle
parentservice: hid: Implement MergeSingleJoyAsDualJoy according to RE (diff)
downloadyuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar.gz
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar.bz2
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar.lz
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar.xz
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.tar.zst
yuzu-390d49c5f17f12f98c80867915bb30991a40ea31.zip
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp250
-rw-r--r--src/core/hle/service/hid/controllers/npad.h23
2 files changed, 88 insertions, 185 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 4095a0a3c..8badefdec 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -582,6 +582,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
UNREACHABLE();
break;
case Core::HID::NpadStyleIndex::ProController:
+ case Core::HID::NpadStyleIndex::Pokeball:
set_motion_state(sixaxis_fullkey_state, motion_state[0]);
break;
case Core::HID::NpadStyleIndex::Handheld:
@@ -1007,96 +1008,47 @@ ResultCode Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
WriteEmptyEntry(shared_memory);
return ResultSuccess;
}
-
-ResultCode Controller_NPad::SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
- GyroscopeZeroDriftMode drift_mode) {
+ResultCode Controller_NPad::SetGyroscopeZeroDriftMode(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, GyroscopeZeroDriftMode drift_mode) {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
- auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- controller.sixaxis_fullkey.gyroscope_zero_drift_mode = drift_mode;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- controller.sixaxis_handheld.gyroscope_zero_drift_mode = drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- controller.sixaxis_dual_left.gyroscope_zero_drift_mode = drift_mode;
- break;
- }
- controller.sixaxis_dual_right.gyroscope_zero_drift_mode = drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- controller.sixaxis_left.gyroscope_zero_drift_mode = drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- controller.sixaxis_right.gyroscope_zero_drift_mode = drift_mode;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ sixaxis.gyroscope_zero_drift_mode = drift_mode;
return ResultSuccess;
}
-ResultCode Controller_NPad::GetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
- GyroscopeZeroDriftMode& drift_mode) const {
+ResultCode Controller_NPad::GetGyroscopeZeroDriftMode(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle,
+ GyroscopeZeroDriftMode& drift_mode) const {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
- auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- drift_mode = controller.sixaxis_fullkey.gyroscope_zero_drift_mode;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- drift_mode = controller.sixaxis_handheld.gyroscope_zero_drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- drift_mode = controller.sixaxis_dual_left.gyroscope_zero_drift_mode;
- break;
- }
- drift_mode = controller.sixaxis_dual_right.gyroscope_zero_drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- drift_mode = controller.sixaxis_left.gyroscope_zero_drift_mode;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- drift_mode = controller.sixaxis_right.gyroscope_zero_drift_mode;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ const auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ drift_mode = sixaxis.gyroscope_zero_drift_mode;
return ResultSuccess;
}
-ResultCode Controller_NPad::IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle,
- bool& is_at_rest) const {
+ResultCode Controller_NPad::IsSixAxisSensorAtRest(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_at_rest) const {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
+
const auto& controller = GetControllerFromHandle(sixaxis_handle);
is_at_rest = controller.sixaxis_at_rest;
return ResultSuccess;
}
ResultCode Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor(
- Core::HID::SixAxisSensorHandle sixaxis_handle, bool& is_firmware_available) const {
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
@@ -1107,7 +1059,7 @@ ResultCode Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor(
return ResultSuccess;
}
-ResultCode Controller_NPad::SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool sixaxis_status) {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
@@ -1119,82 +1071,32 @@ ResultCode Controller_NPad::SetSixAxisEnabled(Core::HID::SixAxisSensorHandle six
}
ResultCode Controller_NPad::IsSixAxisSensorFusionEnabled(
- Core::HID::SixAxisSensorHandle sixaxis_handle, bool& is_fusion_enabled) const {
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_fusion_enabled) const {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
- auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- is_fusion_enabled = controller.sixaxis_fullkey.is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- is_fusion_enabled = controller.sixaxis_handheld.is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- is_fusion_enabled = controller.sixaxis_dual_left.is_fusion_enabled;
- break;
- }
- is_fusion_enabled = controller.sixaxis_dual_right.is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- is_fusion_enabled = controller.sixaxis_left.is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- is_fusion_enabled = controller.sixaxis_right.is_fusion_enabled;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ const auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ is_fusion_enabled = sixaxis.is_fusion_enabled;
return ResultSuccess;
}
-ResultCode Controller_NPad::SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle,
- bool is_fusion_enabled) {
+ResultCode Controller_NPad::SetSixAxisFusionEnabled(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_fusion_enabled) {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
- auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- controller.sixaxis_fullkey.is_fusion_enabled = is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- controller.sixaxis_handheld.is_fusion_enabled = is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- controller.sixaxis_dual_left.is_fusion_enabled = is_fusion_enabled;
- break;
- }
- controller.sixaxis_dual_right.is_fusion_enabled = is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- controller.sixaxis_left.is_fusion_enabled = is_fusion_enabled;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- controller.sixaxis_right.is_fusion_enabled = is_fusion_enabled;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ sixaxis.is_fusion_enabled = is_fusion_enabled;
return ResultSuccess;
}
ResultCode Controller_NPad::SetSixAxisFusionParameters(
- Core::HID::SixAxisSensorHandle sixaxis_handle,
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
@@ -1205,72 +1107,22 @@ ResultCode Controller_NPad::SetSixAxisFusionParameters(
return InvalidSixAxisFusionRange;
}
- auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- controller.sixaxis_fullkey.fusion = sixaxis_fusion_parameters;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- controller.sixaxis_handheld.fusion = sixaxis_fusion_parameters;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- controller.sixaxis_dual_left.fusion = sixaxis_fusion_parameters;
- break;
- }
- controller.sixaxis_dual_right.fusion = sixaxis_fusion_parameters;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- controller.sixaxis_left.fusion = sixaxis_fusion_parameters;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- controller.sixaxis_right.fusion = sixaxis_fusion_parameters;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ sixaxis.fusion = sixaxis_fusion_parameters;
return ResultSuccess;
}
ResultCode Controller_NPad::GetSixAxisFusionParameters(
- Core::HID::SixAxisSensorHandle sixaxis_handle,
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters& parameters) const {
if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle;
}
- const auto& controller = GetControllerFromHandle(sixaxis_handle);
- switch (sixaxis_handle.npad_type) {
- case Core::HID::NpadStyleIndex::ProController:
- parameters = controller.sixaxis_fullkey.fusion;
- break;
- case Core::HID::NpadStyleIndex::Handheld:
- parameters = controller.sixaxis_handheld.fusion;
- break;
- case Core::HID::NpadStyleIndex::JoyconDual:
- case Core::HID::NpadStyleIndex::GameCube:
- case Core::HID::NpadStyleIndex::Pokeball:
- if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
- parameters = controller.sixaxis_dual_left.fusion;
- break;
- }
- parameters = controller.sixaxis_dual_right.fusion;
- break;
- case Core::HID::NpadStyleIndex::JoyconLeft:
- parameters = controller.sixaxis_left.fusion;
- break;
- case Core::HID::NpadStyleIndex::JoyconRight:
- parameters = controller.sixaxis_right.fusion;
- break;
- default:
- LOG_ERROR(Service_HID, "Invalid Npad type {}", sixaxis_handle.npad_type);
- return NpadInvalidHandle;
- }
+ const auto& sixaxis = GetSixaxisState(sixaxis_handle);
+ parameters = sixaxis.fusion;
return ResultSuccess;
}
@@ -1547,4 +1399,50 @@ const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpa
return controller_data[npad_index];
}
+Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
+ auto& controller = GetControllerFromHandle(sixaxis_handle);
+ switch (sixaxis_handle.npad_type) {
+ case Core::HID::NpadStyleIndex::ProController:
+ case Core::HID::NpadStyleIndex::Pokeball:
+ return controller.sixaxis_fullkey;
+ case Core::HID::NpadStyleIndex::Handheld:
+ return controller.sixaxis_handheld;
+ case Core::HID::NpadStyleIndex::JoyconDual:
+ if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
+ return controller.sixaxis_dual_left;
+ }
+ return controller.sixaxis_dual_right;
+ case Core::HID::NpadStyleIndex::JoyconLeft:
+ return controller.sixaxis_left;
+ case Core::HID::NpadStyleIndex::JoyconRight:
+ return controller.sixaxis_right;
+ default:
+ return controller.sixaxis_unknown;
+ }
+}
+
+const Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState(
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle) const {
+ const auto& controller = GetControllerFromHandle(sixaxis_handle);
+ switch (sixaxis_handle.npad_type) {
+ case Core::HID::NpadStyleIndex::ProController:
+ case Core::HID::NpadStyleIndex::Pokeball:
+ return controller.sixaxis_fullkey;
+ case Core::HID::NpadStyleIndex::Handheld:
+ return controller.sixaxis_handheld;
+ case Core::HID::NpadStyleIndex::JoyconDual:
+ if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
+ return controller.sixaxis_dual_left;
+ }
+ return controller.sixaxis_dual_right;
+ case Core::HID::NpadStyleIndex::JoyconLeft:
+ return controller.sixaxis_left;
+ case Core::HID::NpadStyleIndex::JoyconRight:
+ return controller.sixaxis_right;
+ default:
+ return controller.sixaxis_unknown;
+ }
+}
+
} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 5305e8cf8..dfb4de740 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -143,25 +143,25 @@ public:
ResultCode DisconnectNpad(Core::HID::NpadIdType npad_id);
- ResultCode SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ ResultCode SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
GyroscopeZeroDriftMode drift_mode);
- ResultCode GetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ ResultCode GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
GyroscopeZeroDriftMode& drift_mode) const;
- ResultCode IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ ResultCode IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool& is_at_rest) const;
ResultCode IsFirmwareUpdateAvailableForSixAxisSensor(
- Core::HID::SixAxisSensorHandle sixaxis_handle, bool& is_firmware_available) const;
- ResultCode SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const;
+ ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool sixaxis_status);
- ResultCode IsSixAxisSensorFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool& is_fusion_enabled) const;
- ResultCode SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle,
+ ResultCode SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool is_fusion_enabled);
ResultCode SetSixAxisFusionParameters(
- Core::HID::SixAxisSensorHandle sixaxis_handle,
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters);
ResultCode GetSixAxisFusionParameters(
- Core::HID::SixAxisSensorHandle sixaxis_handle,
+ const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters& parameters) const;
ResultCode GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
ResultCode IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
@@ -493,6 +493,7 @@ private:
SixaxisParameters sixaxis_dual_right{};
SixaxisParameters sixaxis_left{};
SixaxisParameters sixaxis_right{};
+ SixaxisParameters sixaxis_unknown{};
// Current pad state
NPadGenericState npad_pad_state{};
@@ -524,6 +525,10 @@ private:
NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const;
+ SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle);
+ const SixaxisParameters& GetSixaxisState(
+ const Core::HID::SixAxisSensorHandle& device_handle) const;
+
std::atomic<u64> press_state{};
std::array<NpadControllerData, NPAD_COUNT> controller_data{};