service: hid: Refractor sixaxis functions

This commit is contained in:
german77 2022-05-21 16:48:05 -05:00 committed by Narr the Reg
parent 3cf15af31e
commit 390d49c5f1
2 changed files with 88 additions and 185 deletions

View File

@ -582,6 +582,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
UNREACHABLE(); UNREACHABLE();
break; break;
case Core::HID::NpadStyleIndex::ProController: case Core::HID::NpadStyleIndex::ProController:
case Core::HID::NpadStyleIndex::Pokeball:
set_motion_state(sixaxis_fullkey_state, motion_state[0]); set_motion_state(sixaxis_fullkey_state, motion_state[0]);
break; break;
case Core::HID::NpadStyleIndex::Handheld: case Core::HID::NpadStyleIndex::Handheld:
@ -1007,96 +1008,47 @@ ResultCode Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
WriteEmptyEntry(shared_memory); WriteEmptyEntry(shared_memory);
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::SetGyroscopeZeroDriftMode(
ResultCode Controller_NPad::SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, const Core::HID::SixAxisSensorHandle& sixaxis_handle, GyroscopeZeroDriftMode drift_mode) {
GyroscopeZeroDriftMode drift_mode) {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
auto& controller = GetControllerFromHandle(sixaxis_handle); auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { sixaxis.gyroscope_zero_drift_mode = drift_mode;
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;
}
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::GetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode Controller_NPad::GetGyroscopeZeroDriftMode(
GyroscopeZeroDriftMode& drift_mode) const { const Core::HID::SixAxisSensorHandle& sixaxis_handle,
GyroscopeZeroDriftMode& drift_mode) const {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
auto& controller = GetControllerFromHandle(sixaxis_handle); const auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { drift_mode = sixaxis.gyroscope_zero_drift_mode;
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;
}
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode Controller_NPad::IsSixAxisSensorAtRest(
bool& is_at_rest) const { const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_at_rest) const {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
const auto& controller = GetControllerFromHandle(sixaxis_handle); const auto& controller = GetControllerFromHandle(sixaxis_handle);
is_at_rest = controller.sixaxis_at_rest; is_at_rest = controller.sixaxis_at_rest;
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor( 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)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
@ -1107,7 +1059,7 @@ ResultCode Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor(
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool sixaxis_status) { bool sixaxis_status) {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
@ -1119,82 +1071,32 @@ ResultCode Controller_NPad::SetSixAxisEnabled(Core::HID::SixAxisSensorHandle six
} }
ResultCode Controller_NPad::IsSixAxisSensorFusionEnabled( 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)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
auto& controller = GetControllerFromHandle(sixaxis_handle); const auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { is_fusion_enabled = sixaxis.is_fusion_enabled;
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;
}
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode Controller_NPad::SetSixAxisFusionEnabled(
bool is_fusion_enabled) { const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_fusion_enabled) {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
auto& controller = GetControllerFromHandle(sixaxis_handle); auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { sixaxis.is_fusion_enabled = is_fusion_enabled;
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;
}
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::SetSixAxisFusionParameters( ResultCode Controller_NPad::SetSixAxisFusionParameters(
Core::HID::SixAxisSensorHandle sixaxis_handle, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) { Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
@ -1205,72 +1107,22 @@ ResultCode Controller_NPad::SetSixAxisFusionParameters(
return InvalidSixAxisFusionRange; return InvalidSixAxisFusionRange;
} }
auto& controller = GetControllerFromHandle(sixaxis_handle); auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { sixaxis.fusion = sixaxis_fusion_parameters;
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;
}
return ResultSuccess; return ResultSuccess;
} }
ResultCode Controller_NPad::GetSixAxisFusionParameters( ResultCode Controller_NPad::GetSixAxisFusionParameters(
Core::HID::SixAxisSensorHandle sixaxis_handle, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters& parameters) const { Core::HID::SixAxisSensorFusionParameters& parameters) const {
if (!IsDeviceHandleValid(sixaxis_handle)) { if (!IsDeviceHandleValid(sixaxis_handle)) {
LOG_ERROR(Service_HID, "Invalid handle"); LOG_ERROR(Service_HID, "Invalid handle");
return NpadInvalidHandle; return NpadInvalidHandle;
} }
const auto& controller = GetControllerFromHandle(sixaxis_handle); const auto& sixaxis = GetSixaxisState(sixaxis_handle);
switch (sixaxis_handle.npad_type) { parameters = sixaxis.fusion;
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;
}
return ResultSuccess; return ResultSuccess;
} }
@ -1547,4 +1399,50 @@ const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpa
return controller_data[npad_index]; 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 } // namespace Service::HID

View File

@ -143,25 +143,25 @@ public:
ResultCode DisconnectNpad(Core::HID::NpadIdType npad_id); 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); GyroscopeZeroDriftMode drift_mode);
ResultCode GetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
GyroscopeZeroDriftMode& drift_mode) const; GyroscopeZeroDriftMode& drift_mode) const;
ResultCode IsSixAxisSensorAtRest(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool& is_at_rest) const; bool& is_at_rest) const;
ResultCode IsFirmwareUpdateAvailableForSixAxisSensor( ResultCode IsFirmwareUpdateAvailableForSixAxisSensor(
Core::HID::SixAxisSensorHandle sixaxis_handle, bool& is_firmware_available) const; const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const;
ResultCode SetSixAxisEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool sixaxis_status); bool sixaxis_status);
ResultCode IsSixAxisSensorFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool& is_fusion_enabled) const; bool& is_fusion_enabled) const;
ResultCode SetSixAxisFusionEnabled(Core::HID::SixAxisSensorHandle sixaxis_handle, ResultCode SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
bool is_fusion_enabled); bool is_fusion_enabled);
ResultCode SetSixAxisFusionParameters( ResultCode SetSixAxisFusionParameters(
Core::HID::SixAxisSensorHandle sixaxis_handle, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters); Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters);
ResultCode GetSixAxisFusionParameters( ResultCode GetSixAxisFusionParameters(
Core::HID::SixAxisSensorHandle sixaxis_handle, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
Core::HID::SixAxisSensorFusionParameters& parameters) const; Core::HID::SixAxisSensorFusionParameters& parameters) const;
ResultCode GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; ResultCode GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
ResultCode IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, ResultCode IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
@ -493,6 +493,7 @@ private:
SixaxisParameters sixaxis_dual_right{}; SixaxisParameters sixaxis_dual_right{};
SixaxisParameters sixaxis_left{}; SixaxisParameters sixaxis_left{};
SixaxisParameters sixaxis_right{}; SixaxisParameters sixaxis_right{};
SixaxisParameters sixaxis_unknown{};
// Current pad state // Current pad state
NPadGenericState npad_pad_state{}; NPadGenericState npad_pad_state{};
@ -524,6 +525,10 @@ private:
NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id); NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const; 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::atomic<u64> press_state{};
std::array<NpadControllerData, NPAD_COUNT> controller_data{}; std::array<NpadControllerData, NPAD_COUNT> controller_data{};