end of day 3

This commit is contained in:
Narr the Reg 2023-08-15 00:09:24 -06:00
parent c45078844c
commit bb6b22482f
5 changed files with 363 additions and 81 deletions

View File

@ -1679,7 +1679,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) { void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
struct Parameters { struct Parameters {
bool analog_stick_use_center_clamp; bool use_center_clamp;
INSERT_PADDING_BYTES_NOINIT(7); INSERT_PADDING_BYTES_NOINIT(7);
u64 applet_resource_user_id; u64 applet_resource_user_id;
}; };
@ -1688,11 +1688,11 @@ void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
const auto parameters{rp.PopRaw<Parameters>()}; const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_HID, LOG_WARNING(Service_HID,
"(STUBBED) called, analog_stick_use_center_clamp={}, applet_resource_user_id={}", "(STUBBED) called, use_center_clamp={}, applet_resource_user_id={}",
parameters.analog_stick_use_center_clamp, parameters.applet_resource_user_id); parameters.use_center_clamp, parameters.applet_resource_user_id);
GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp( GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(
parameters.applet_resource_user_id, parameters.analog_stick_use_center_clamp); parameters.applet_resource_user_id, parameters.use_center_clamp);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
@ -1730,7 +1730,7 @@ void IHidServer::ClearNpadCaptureButtonAssignment(HLERequestContext& ctx) {
applet_resource_user_id); applet_resource_user_id);
const auto npad = GetResourceManager()->GetNpad(); const auto npad = GetResourceManager()->GetNpad();
const auto result = npad->ClearNpadCaptureButtonAssignment(parameters.applet_resource_user_id); const auto result = npad->ClearNpadCaptureButtonAssignment(applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result); rb.Push(result);

View File

@ -40,7 +40,7 @@ u32 NpadControllerState::GetConnectedControllerIndex() {
u32 connected_controllers = 0; u32 connected_controllers = 0;
u32 connected_index = 0; u32 connected_index = 0;
u32 index = 0; // u32 index = 0;
if (connected_controllers == 0) { if (connected_controllers == 0) {
return 0; return 0;
@ -75,7 +75,7 @@ void NpadState::SetNpadJoyHoldType(const NpadJoyHoldType hold_type) {
npad_hold_type = hold_type; npad_hold_type = hold_type;
} }
NpadJoyHoldType NpadState::GetNpadJoyHoldType() { NpadJoyHoldType NpadState::GetNpadJoyHoldType() const {
return npad_hold_type; return npad_hold_type;
} }
@ -96,10 +96,34 @@ void NpadState::SetSupportedNpadStyleSet(const NpadStyleSet supported_style_set)
supported_npad_style_set = supported_style_set; supported_npad_style_set = supported_style_set;
} }
NpadStyleSet NpadState::GetSupportedNpadStyleSet() { NpadStyleSet NpadState::GetSupportedNpadStyleSet() const {
return supported_npad_style_set; return supported_npad_style_set;
} }
void NpadState::SetLrAssignmentMode(const bool is_enabled) {
status.lr_assignment_mode.Assign(is_enabled);
}
bool NpadState::GetLrAssignmentMode() const {
return status.lr_assignment_mode != 0;
}
void NpadState::SetNpadHandheldActivationMode(const NpadHandheldActivationMode mode) {
handheld_activation_mode = mode;
}
NpadHandheldActivationMode NpadState::GetNpadHandheldActivationMode() const {
return handheld_activation_mode;
}
bool NpadState::IsUnintendedHomeButtonInputProtectionEnabled() const {
return unintended_home_button_input_proptection;
}
void NpadState::SetNpadAnalogStickUseCenterClampImpl(const bool is_enabled) {
status.use_center_clamp.Assign(is_enabled);
}
Npad::Npad() { Npad::Npad() {
for (auto& npad : npad_state) { for (auto& npad : npad_state) {
npad = std::make_shared<NpadState>(); npad = std::make_shared<NpadState>();
@ -153,7 +177,7 @@ Result Npad::SetNpadJoyHoldType(const u64 aruid, const NpadJoyHoldType hold_type
return ResultSuccess; return ResultSuccess;
} }
Result Npad::GetNpadJoyHoldType(const u64 aruid, NpadJoyHoldType& hold_type) { Result Npad::GetNpadJoyHoldType(const u64 aruid, NpadJoyHoldType& out_hold_type) const {
const auto index = GetIndexFromAruid(aruid); const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) { if (index >= ARUID_MAX) {
@ -161,9 +185,9 @@ Result Npad::GetNpadJoyHoldType(const u64 aruid, NpadJoyHoldType& hold_type) {
} }
const auto state = npad_state[index]; const auto state = npad_state[index];
hold_type = state->GetNpadJoyHoldType(); out_hold_type = state->GetNpadJoyHoldType();
if ((state->status.raw & 0x30) != 0) { if ((state->status.raw & 0x30) != 0) {
hold_type = active_npad_state->GetNpadJoyHoldType(); out_hold_type = active_npad_state->GetNpadJoyHoldType();
} }
return ResultSuccess; return ResultSuccess;
@ -231,18 +255,20 @@ Result Npad::SetSupportedNpadStyleSetImpl(const u64 aruid, const NpadStyleSet su
return ResultSuccess; return ResultSuccess;
} }
Result Npad::GetSupportedNpadStyleSet(const u64 aruid, NpadStyleSet& supported_style_set) { Result Npad::GetSupportedNpadStyleSet(const u64 aruid,
const Result result = GetSupportedNpadStyleSetImpl(aruid, supported_style_set); NpadStyleSet& out_supported_style_set) const {
const Result result = GetSupportedNpadStyleSetImpl(aruid, out_supported_style_set);
if (result == ResultNpadNotConnected) { if (result == ResultNpadNotConnected) {
supported_style_set = NpadStyleSet::None; out_supported_style_set = NpadStyleSet::None;
return ResultSuccess; return ResultSuccess;
} }
return result; return result;
} }
Result Npad::GetSupportedNpadStyleSetImpl(const u64 aruid, NpadStyleSet& supported_style_set) { Result Npad::GetSupportedNpadStyleSetImpl(const u64 aruid,
NpadStyleSet& out_supported_style_set) const {
const auto index = GetIndexFromAruid(aruid); const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) { if (index >= ARUID_MAX) {
@ -253,12 +279,12 @@ Result Npad::GetSupportedNpadStyleSetImpl(const u64 aruid, NpadStyleSet& support
return ResultUndefinedStyleSet; return ResultUndefinedStyleSet;
} }
supported_style_set = npad_state[index]->GetSupportedNpadStyleSet(); out_supported_style_set = npad_state[index]->GetSupportedNpadStyleSet();
return ResultSuccess; return ResultSuccess;
} }
bool Npad::IsFirmwareUpdateAvailableForSixAxisSensor(const SixAxisSensorHandle& handle) { bool Npad::IsFirmwareUpdateAvailableForSixAxisSensor(const SixAxisSensorHandle& handle) const {
// Not implemented // Not implemented
return false; return false;
} }
@ -391,6 +417,145 @@ Result Npad::SwapNpadAssignment(const u64 aruid, const NpadIdType npad_id_1,
if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) {
return ResultSuccess; return ResultSuccess;
} }
return ResultSuccess;
}
Result Npad::StartLrAssignmentMode(const u64 aruid) {
bool is_enabled{};
Result result = GetLrAssignmentMode(is_enabled, aruid);
if (result.IsSuccess() && !is_enabled) {
result = SetLrAssignmentMode(aruid, true);
}
return result;
}
Result Npad::StopLrAssignmentMode(const u64 aruid) {
bool is_enabled{};
Result result = GetLrAssignmentMode(is_enabled, aruid);
if (result.IsSuccess() && is_enabled) {
result = SetLrAssignmentMode(aruid, false);
}
return result;
}
Result Npad::SetLrAssignmentMode(const u64 aruid, const bool is_enabled) {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
npad_state[index]->SetLrAssignmentMode(is_enabled);
if (active_aruid == aruid) {
active_npad_state->SetLrAssignmentMode(is_enabled);
}
return ResultSuccess;
}
Result Npad::GetLrAssignmentMode(bool& out_is_enabled, const u64 aruid) const {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
out_is_enabled = npad_state[index]->GetLrAssignmentMode();
return ResultSuccess;
}
Result Npad::SetNpadHandheldActivationMode(const u64 aruid, const NpadHandheldActivationMode mode) {
const Result result = SetNpadHandheldActivationModeImpl(aruid, mode);
if (result.IsSuccess()) {
active_npad_state->GetControllerState(NpadIdType::Handheld)->Update();
}
return result;
}
Result Npad::SetNpadHandheldActivationModeImpl(const u64 aruid,
const NpadHandheldActivationMode mode) {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
npad_state[index]->SetNpadHandheldActivationMode(mode);
if (active_aruid == aruid) {
active_npad_state->SetNpadHandheldActivationMode(mode);
}
return ResultSuccess;
}
Result Npad::GetNpadHandheldActivationMode(const u64 aruid,
NpadHandheldActivationMode& out_mode) const {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
out_mode = npad_state[index]->GetNpadHandheldActivationMode();
return ResultSuccess;
}
Result Npad::IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, const u64 aruid,
const NpadIdType npad_id) const {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
out_is_enabled = npad_state[index]->IsUnintendedHomeButtonInputProtectionEnabled();
return ResultSuccess;
}
Result Npad::EnableUnintendedHomeButtonInputProtection(const u64 aruid, const NpadIdType npad_id,
const bool is_enabled) {
// tooo complicated
return ResultSuccess;
}
void Npad::SetNpadAnalogStickUseCenterClamp(const u64 aruid, const bool use_center_clamp) {
SetNpadAnalogStickUseCenterClampImpl(aruid, use_center_clamp);
}
Result Npad::SetNpadAnalogStickUseCenterClampImpl(const u64 aruid, const bool use_center_clamp) {
const auto index = GetIndexFromAruid(aruid);
if (index >= ARUID_MAX) {
return ResultNpadNotConnected;
}
npad_state[index]->SetNpadAnalogStickUseCenterClampImpl(use_center_clamp);
if (active_aruid == aruid) {
active_npad_state->SetNpadAnalogStickUseCenterClampImpl(use_center_clamp);
}
return ResultSuccess;
}
Result Npad::SetNpadCaptureButtonAssignment(const u64 aruid, const NpadStyleSet npad_styleset,
const NpadButton buttons) {
// tooo complicated
return ResultSuccess;
}
Result Npad::ClearNpadCaptureButtonAssignment(const u64 aruid) {
return ResultSuccess;
} }
Result Npad::AcquireNpadStyleSetUpdateEventHandle(const u64 aruid, Result Npad::AcquireNpadStyleSetUpdateEventHandle(const u64 aruid,

View File

@ -17,8 +17,12 @@ class KReadableEvent;
namespace Service::HID { namespace Service::HID {
enum class NpadIdType : u32; enum class NpadIdType : u32;
enum class NpadJoyAssignmentMode : u32;
enum class NpadHandheldActivationMode : u64;
enum class NpadJoyDeviceType : s64;
enum class NpadStyleSet : u32; enum class NpadStyleSet : u32;
enum class NpadJoyHoldType : u64; enum class NpadJoyHoldType : u64;
enum class NpadButton : u64;
struct SixAxisSensorHandle; struct SixAxisSensorHandle;
} // namespace Service::HID } // namespace Service::HID
@ -56,6 +60,8 @@ public:
BitField<0, 1, u32> is_supported_style_set; BitField<0, 1, u32> is_supported_style_set;
BitField<1, 1, u32> is_hold_type_set; BitField<1, 1, u32> is_hold_type_set;
BitField<2, 1, u32> lr_assignment_mode;
BitField<7, 1, u32> use_center_clamp;
}; };
}; };
static_assert(sizeof(NpadStatus) == 4, "NpadStatus is an invalid size"); static_assert(sizeof(NpadStatus) == 4, "NpadStatus is an invalid size");
@ -66,18 +72,29 @@ public:
std::shared_ptr<NpadControllerState> GetControllerState(const NpadIdType& npad_id) const; std::shared_ptr<NpadControllerState> GetControllerState(const NpadIdType& npad_id) const;
void SetNpadJoyHoldType(const NpadJoyHoldType hold_type); void SetNpadJoyHoldType(const NpadJoyHoldType hold_type);
NpadJoyHoldType GetNpadJoyHoldType(); NpadJoyHoldType GetNpadJoyHoldType() const;
Result SetSupportedNpadIdType(std::span<const NpadIdType> list); Result SetSupportedNpadIdType(std::span<const NpadIdType> list);
void SetSupportedNpadStyleSet(const NpadStyleSet supported_style_set); void SetSupportedNpadStyleSet(const NpadStyleSet supported_style_set);
NpadStyleSet GetSupportedNpadStyleSet(); NpadStyleSet GetSupportedNpadStyleSet() const;
void SetLrAssignmentMode(const bool is_enabled);
bool GetLrAssignmentMode() const;
void SetNpadHandheldActivationMode(const NpadHandheldActivationMode mode);
NpadHandheldActivationMode GetNpadHandheldActivationMode() const;
bool IsUnintendedHomeButtonInputProtectionEnabled() const;
void SetNpadAnalogStickUseCenterClampImpl(const bool is_enabled);
NpadStatus status{}; NpadStatus status{};
private: private:
NpadJoyHoldType npad_hold_type{}; NpadJoyHoldType npad_hold_type{};
NpadStyleSet supported_npad_style_set{}; NpadStyleSet supported_npad_style_set{};
NpadHandheldActivationMode handheld_activation_mode{};
bool unintended_home_button_input_proptection{};
std::size_t supported_npad_id_types_count{}; std::size_t supported_npad_id_types_count{};
std::array<NpadIdType, SUPPORTED_NPAD_TYPES_MAX> supported_npad_id_types{}; std::array<NpadIdType, SUPPORTED_NPAD_TYPES_MAX> supported_npad_id_types{};
@ -98,17 +115,17 @@ public:
// Config // Config
Result SetNpadJoyHoldType(const u64 aruid, const NpadJoyHoldType hold_type); Result SetNpadJoyHoldType(const u64 aruid, const NpadJoyHoldType hold_type);
Result GetNpadJoyHoldType(const u64 aruid, NpadJoyHoldType& hold_type); Result GetNpadJoyHoldType(const u64 aruid, NpadJoyHoldType& out_hold_type) const;
Result SetSupportedNpadIdType(const u64 aruid, std::span<const NpadIdType> list); Result SetSupportedNpadIdType(const u64 aruid, std::span<const NpadIdType> list);
Result SetSupportedNpadStyleSet(const u64 aruid, const NpadStyleSet supported_style_set); Result SetSupportedNpadStyleSet(const u64 aruid, const NpadStyleSet supported_style_set);
Result GetSupportedNpadStyleSet(const u64 aruid, NpadStyleSet& supported_style_set); Result GetSupportedNpadStyleSet(const u64 aruid, NpadStyleSet& out_supported_style_set) const;
// Sixaxis // Sixaxis
bool IsFirmwareUpdateAvailableForSixAxisSensor(const SixAxisSensorHandle& handle); bool IsFirmwareUpdateAvailableForSixAxisSensor(const SixAxisSensorHandle& handle) const;
Result ResetIsSixAxisSensorDeviceNewlyAssigned(const u64 aruid, Result ResetIsSixAxisSensorDeviceNewlyAssigned(const u64 aruid,
const SixAxisSensorHandle& handle); const SixAxisSensorHandle& handle);
// Merge, swap or split npad // Assignment, merge, swap or split npad
void SetNpadJoyAssignmentModeSingleByDefault(const u64 aruid, const NpadIdType npad_id); void SetNpadJoyAssignmentModeSingleByDefault(const u64 aruid, const NpadIdType npad_id);
void SetNpadJoyAssignmentModeSingle(const u64 aruid, const NpadIdType npad_id, void SetNpadJoyAssignmentModeSingle(const u64 aruid, const NpadIdType npad_id,
const NpadJoyDeviceType npad_joy_device_type); const NpadJoyDeviceType npad_joy_device_type);
@ -120,6 +137,21 @@ public:
const NpadIdType npad_id_2); const NpadIdType npad_id_2);
Result SwapNpadAssignment(const u64 aruid, const NpadIdType npad_id_1, Result SwapNpadAssignment(const u64 aruid, const NpadIdType npad_id_1,
const NpadIdType npad_id_2); const NpadIdType npad_id_2);
Result StartLrAssignmentMode(const u64 aruid);
Result StopLrAssignmentMode(const u64 aruid);
Result SetNpadHandheldActivationMode(const u64 aruid, const NpadHandheldActivationMode mode);
Result GetNpadHandheldActivationMode(const u64 aruid,
NpadHandheldActivationMode& out_mode) const;
// Sticks and Button
Result IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, const u64 aruid,
const NpadIdType npad_id) const;
Result EnableUnintendedHomeButtonInputProtection(const u64 aruid, const NpadIdType npad_id,
const bool is_enabled);
void SetNpadAnalogStickUseCenterClamp(const u64 aruid, const bool use_center_clamp);
Result SetNpadCaptureButtonAssignment(const u64 aruid, const NpadStyleSet npad_styleset,
const NpadButton buttons);
Result ClearNpadCaptureButtonAssignment(const u64 aruid);
// Events // Events
Result AcquireNpadStyleSetUpdateEventHandle(const u64 aruid, Kernel::KReadableEvent** out_event, Result AcquireNpadStyleSetUpdateEventHandle(const u64 aruid, Kernel::KReadableEvent** out_event,
@ -129,10 +161,16 @@ private:
// Interface implementations // Interface implementations
Result SetSupportedNpadIdTypeImpl(const u64 aruid, std::span<const NpadIdType> list); Result SetSupportedNpadIdTypeImpl(const u64 aruid, std::span<const NpadIdType> list);
Result SetSupportedNpadStyleSetImpl(const u64 aruid, const NpadStyleSet supported_style_set); Result SetSupportedNpadStyleSetImpl(const u64 aruid, const NpadStyleSet supported_style_set);
Result GetSupportedNpadStyleSetImpl(const u64 aruid, NpadStyleSet& supported_style_set); Result GetSupportedNpadStyleSetImpl(const u64 aruid,
bool SetNpadJoyAssignmentMode(NpadIdType* out_npad_id, const u64 aruid, const NpadIdType npad_id, NpadStyleSet& out_supported_style_set) const;
bool SetNpadJoyAssignmentMode(NpadIdType* out_npad_id, const u64 aruid,
const NpadIdType npad_id,
const NpadJoyDeviceType npad_joy_device_type); const NpadJoyDeviceType npad_joy_device_type);
Result SetLrAssignmentMode(const u64 aruid, const bool is_enabled);
Result GetLrAssignmentMode(bool& out_is_enabled, const u64 aruid) const;
Result SetNpadHandheldActivationModeImpl(const u64 aruid,
const NpadHandheldActivationMode mode);
Result SetNpadAnalogStickUseCenterClampImpl(const u64 aruid, const bool use_center_clamp);
// Update state // Update state
void UpdateSupportedNpadIdType(); void UpdateSupportedNpadIdType();

View File

@ -13,6 +13,7 @@ SixAxis::~SixAxis() = default;
Result SixAxis::GetSensorState(std::shared_ptr<SixAxisSensorState>& out_state, u64 aruid, Result SixAxis::GetSensorState(std::shared_ptr<SixAxisSensorState>& out_state, u64 aruid,
const SixAxisSensorHandle& handle) { const SixAxisSensorHandle& handle) {
std::scoped_lock lock{mutex};
const auto state = GetStateFromAruid(aruid); const auto state = GetStateFromAruid(aruid);
if (state == nullptr) { if (state == nullptr) {
@ -71,119 +72,169 @@ std::shared_ptr<SixAxisSensorState> SixAxisState::GetSensorState(
} }
SixAxisSensorState::SixAxisSensorState() { SixAxisSensorState::SixAxisSensorState() {
ResetFusionParameters(); Initialize();
ResetAccelerometerParameters();
ResetAccelerometerPlayMode();
ResetGyroscopeZeroDriftMode();
} }
SixAxisSensorState::~SixAxisSensorState() = default; SixAxisSensorState::~SixAxisSensorState() = default;
void SixAxisSensorState::SetRunningState(const bool state) { void SixAxisSensorState::SetRunningState(const bool state) {
is_running = state; sensor_state.sensor.is_running = state;
} }
void SixAxisSensorState::SetUnalteredPassthrough(const bool is_enabled) { void SixAxisSensorState::SetUnalteredPassthrough(const bool is_enabled) {
is_passthrough_enabled = is_enabled; sensor_state.sensor.is_passthrough_enabled = is_enabled;
} }
bool SixAxisSensorState::GetUnalteredPassthrough() { bool SixAxisSensorState::GetUnalteredPassthrough() {
return is_passthrough_enabled; return sensor_state.sensor.is_passthrough_enabled;
} }
bool SixAxisSensorState::IsFusionEnabled() const { bool SixAxisSensorState::IsFusionEnabled() const {
return is_fusion_enabled; return sensor_state.accel.is_fusion_enabled;
} }
void SixAxisSensorState::ResetFusionParameters() { void SixAxisSensorState::ResetFusionParameters() {
is_fusion_enabled = true; sensor_state.accel.is_fusion_enabled = true;
fusion_parameter_1 = 0.03f; sensor_state.accel.fusion_parameter_1 = 0.03f;
fusion_parameter_2 = 0.4f; sensor_state.accel.fusion_parameter_2 = 0.4f;
} }
void SixAxisSensorState::SetFusionState(const bool is_enabled) { void SixAxisSensorState::SetFusionState(const bool is_enabled) {
is_fusion_enabled = is_enabled; sensor_state.accel.is_fusion_enabled = is_enabled;
} }
void SixAxisSensorState::SetFusionParameters(const SixAxisSensorFusionParameters& parameters) { void SixAxisSensorState::SetFusionParameters(const SixAxisSensorFusionParameters& parameters) {
fusion_parameter_1 = parameters.parameter1; sensor_state.accel.fusion_parameter_1 = parameters.parameter1;
fusion_parameter_2 = parameters.parameter2; sensor_state.accel.fusion_parameter_2 = parameters.parameter2;
} }
SixAxisSensorFusionParameters SixAxisSensorState::GetFusionParameters() const { SixAxisSensorFusionParameters SixAxisSensorState::GetFusionParameters() const {
return { return {
.parameter1 = fusion_parameter_1, .parameter1 = sensor_state.accel.fusion_parameter_1,
.parameter2 = fusion_parameter_2, .parameter2 = sensor_state.accel.fusion_parameter_2,
}; };
} }
void SixAxisSensorState::ResetAccelerometerParameters() { void SixAxisSensorState::ResetAccelerometerParameters() {
accelerometer_parameter_1 = 0.0f; sensor_state.accel.accelerometer_parameter_1 = 0.0f;
accelerometer_parameter_2 = 1.0f; sensor_state.accel.accelerometer_parameter_2 = 1.0f;
} }
void SixAxisSensorState::SetAccelerometerParameters( void SixAxisSensorState::SetAccelerometerParameters(
const SixAxisAccelerometerParameters& parameters) { const SixAxisAccelerometerParameters& parameters) {
accelerometer_parameter_1 = parameters.parameter1; sensor_state.accel.accelerometer_parameter_1 = parameters.parameter1;
accelerometer_parameter_2 = parameters.parameter2; sensor_state.accel.accelerometer_parameter_2 = parameters.parameter2;
} }
SixAxisAccelerometerParameters SixAxisSensorState::GetAccelerometerParameters() const { SixAxisAccelerometerParameters SixAxisSensorState::GetAccelerometerParameters() const {
return { return {
.parameter1 = accelerometer_parameter_1, .parameter1 = sensor_state.accel.accelerometer_parameter_1,
.parameter2 = accelerometer_parameter_2, .parameter2 = sensor_state.accel.accelerometer_parameter_2,
}; };
} }
void SixAxisSensorState::SetShiftAccelerometerCalibrationValue( void SixAxisSensorState::SetShiftAccelerometerCalibrationValue(
const SixAxisSensorShiftAccelerometerCalibration& calibration) { const SixAxisSensorShiftAccelerometerCalibration& calibration) {
shift_accelerometer_calibration_1 = calibration.calibration1; sensor_state.accel.shift_calibration_1 = calibration.calibration1;
shift_accelerometer_calibration_2 = calibration.calibration1; sensor_state.accel.shift_calibration_2 = calibration.calibration1;
} }
SixAxisSensorShiftAccelerometerCalibration SixAxisSensorShiftAccelerometerCalibration
SixAxisSensorState::GetShiftAccelerometerCalibrationValue() const { SixAxisSensorState::GetShiftAccelerometerCalibrationValue() const {
return { return {
.calibration1 = shift_accelerometer_calibration_1, .calibration1 = sensor_state.accel.shift_calibration_1,
.calibration2 = shift_accelerometer_calibration_2, .calibration2 = sensor_state.accel.shift_calibration_2,
}; };
} }
void SixAxisSensorState::ResetAccelerometerPlayMode() { void SixAxisSensorState::ResetAccelerometerPlayMode() {
play_mode = AccelerometerPlayMode::Tight; sensor_state.accel.play_mode = AccelerometerPlayMode::Tight;
} }
void SixAxisSensorState::SetAccelerometerPlayMode(const AccelerometerPlayMode mode) { void SixAxisSensorState::SetAccelerometerPlayMode(const AccelerometerPlayMode mode) {
play_mode = mode; sensor_state.accel.play_mode = mode;
} }
AccelerometerPlayMode SixAxisSensorState::GetAccelerometerPlayMode() const { AccelerometerPlayMode SixAxisSensorState::GetAccelerometerPlayMode() const {
return play_mode; return sensor_state.accel.play_mode;
} }
void SixAxisSensorState::ResetGyroscopeZeroDriftMode() { void SixAxisSensorState::ResetGyroscopeZeroDriftMode() {
zero_drift_mode = GyroscopeZeroDriftMode::Standard; sensor_state.gyro.zero_drift_mode = GyroscopeZeroDriftMode::Standard;
} }
void SixAxisSensorState::SetGyroscopeZeroDriftMode(const GyroscopeZeroDriftMode mode) { void SixAxisSensorState::SetGyroscopeZeroDriftMode(const GyroscopeZeroDriftMode mode) {
zero_drift_mode = mode; sensor_state.gyro.zero_drift_mode = mode;
} }
GyroscopeZeroDriftMode SixAxisSensorState::GetGyroscopeZeroDriftMode() const { GyroscopeZeroDriftMode SixAxisSensorState::GetGyroscopeZeroDriftMode() const {
return zero_drift_mode; return sensor_state.gyro.zero_drift_mode;
} }
void SixAxisSensorState::SetShiftGyroscopeCalibrationValue( void SixAxisSensorState::SetShiftGyroscopeCalibrationValue(
const SixAxisSensorShiftGyroscopeCalibration& calibration) { const SixAxisSensorShiftGyroscopeCalibration& calibration) {
shift_gyroscope_calibration_1 = calibration.calibration1; sensor_state.gyro.shift_calibration_1 = calibration.calibration1;
shift_gyroscope_calibration_2 = calibration.calibration1; sensor_state.gyro.shift_calibration_2 = calibration.calibration1;
} }
SixAxisSensorShiftGyroscopeCalibration SixAxisSensorState::GetShiftGyroscopeCalibrationValue() SixAxisSensorShiftGyroscopeCalibration SixAxisSensorState::GetShiftGyroscopeCalibrationValue()
const { const {
return { return {
.calibration1 = shift_gyroscope_calibration_1, .calibration1 = sensor_state.gyro.shift_calibration_1,
.calibration2 = shift_gyroscope_calibration_2, .calibration2 = sensor_state.gyro.shift_calibration_2,
}; };
} }
void SixAxisSensorState::Initialize() {
InitializeAccelerometerValues(true);
InitializeGyroValues(true);
InitializeSensorValues();
}
void SixAxisSensorState::InitializeAccelerometerValues(const bool is_enabled) {
sensor_state.accel.play_mode = AccelerometerPlayMode::Tight;
sensor_state.accel.is_fusion_enabled = true;
sensor_state.accel.unknown_value = 8;
sensor_state.accel.accelerometer_parameter_1 = 0.0f;
sensor_state.accel.accelerometer_parameter_2 = 1.0f;
sensor_state.accel.fusion_parameter_1 = 0.03f;
sensor_state.accel.fusion_parameter_2 = 0.4f;
if (is_enabled) {
sensor_state.accel.shift_calibration_1 = 0.0f;
sensor_state.accel.shift_calibration_2 = 1.0f;
}
}
void SixAxisSensorState::InitializeGyroValues(const bool is_enabled) {
sensor_state.gyro.shift_calibration_1 = 9.463809e-41f;
sensor_state.gyro.shift_calibration_2 = 0.0f;
sensor_state.gyro.zero_drift_mode = GyroscopeZeroDriftMode::Standard;
sensor_state.gyro.unknown_gyro[0] = 1.0f;
sensor_state.gyro.unknown_gyro[1] = 1.0f;
sensor_state.gyro.unknown_gyro[2] = 1.0f;
sensor_state.gyro.unknown_gyro[3] = 1.0f;
sensor_state.gyro.unknown_gyro[4] = 1.0f;
sensor_state.gyro.unknown_gyro[5] = 1.0f;
if (is_enabled) {
sensor_state.gyro.unknown_gyro[6] = 0.0f;
sensor_state.gyro.unknown_gyro[7] = 1.0f;
}
}
void SixAxisSensorState::InitializeSensorValues() {
sensor_state.sensor.is_running = false;
sensor_state.sensor.unknown_bool = false;
sensor_state.sensor.is_passthrough_enabled = false;
// This pretty much looks like an identity matrix
sensor_state.sensor.unknown_sensor[0] = 1.0f;
sensor_state.sensor.unknown_sensor[1] = 0.0f;
sensor_state.sensor.unknown_sensor[2] = 0.0f;
sensor_state.sensor.unknown_sensor[3] = 0.0f;
sensor_state.sensor.unknown_sensor[4] = 1.0f;
sensor_state.sensor.unknown_sensor[5] = 0.0f;
sensor_state.sensor.unknown_sensor[6] = 0.0f;
sensor_state.sensor.unknown_sensor[7] = 0.0f;
sensor_state.sensor.unknown_sensor[8] = 1.0f;
sensor_state.sensor.unknown_sensor[9] = 0.0f;
}
} // namespace Service::HID } // namespace Service::HID

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <mutex>
#include "core/hle/service/hid/resource_manager/base_resource.h" #include "core/hle/service/hid/resource_manager/base_resource.h"
@ -63,25 +64,51 @@ public:
SixAxisSensorShiftGyroscopeCalibration GetShiftGyroscopeCalibrationValue() const; SixAxisSensorShiftGyroscopeCalibration GetShiftGyroscopeCalibrationValue() const;
private: private:
bool is_running{}; void Initialize();
bool is_passthrough_enabled{}; void InitializeAccelerometerValues(const bool is_enabled);
void InitializeGyroValues(const bool is_enabled);
void InitializeSensorValues();
// Sensor fusion struct AccelerometerParams {
bool is_fusion_enabled{}; u32 unknown_value{};
float fusion_parameter_1{}; AccelerometerPlayMode play_mode{};
float fusion_parameter_2{};
// Accelerometer
float accelerometer_parameter_1{}; float accelerometer_parameter_1{};
float accelerometer_parameter_2{}; float accelerometer_parameter_2{};
float shift_accelerometer_calibration_1{}; bool is_fusion_enabled{};
float shift_accelerometer_calibration_2{}; INSERT_PADDING_BYTES(0x3);
AccelerometerPlayMode play_mode{}; float fusion_parameter_1{};
float fusion_parameter_2{};
float shift_calibration_1{};
float shift_calibration_2{};
};
static_assert(sizeof(AccelerometerParams) == 0x24, "AccelerometerParams is an invalid size");
// Gyroscope struct GyroscopeParams {
float shift_gyroscope_calibration_1{}; float shift_calibration_1{};
float shift_gyroscope_calibration_2{}; float shift_calibration_2{};
GyroscopeZeroDriftMode zero_drift_mode{}; GyroscopeZeroDriftMode zero_drift_mode{};
std::array<float, 8> unknown_gyro{};
};
static_assert(sizeof(GyroscopeParams) == 0x2c, "GyroscopeParams is an invalid size");
struct SensorParams {
bool is_running{};
bool unknown_bool{};
INSERT_PADDING_BYTES(0x2);
std::array<float, 10> unknown_sensor{};
bool is_passthrough_enabled{};
INSERT_PADDING_BYTES(0x3);
};
static_assert(sizeof(SensorParams) == 0x30, "SensorParams is an invalid size");
struct SensorState {
AccelerometerParams accel;
GyroscopeParams gyro;
SensorParams sensor;
};
static_assert(sizeof(SensorState) == 0x80, "SensorState is an invalid size");
SensorState sensor_state{};
}; };
class SixAxisState { class SixAxisState {
@ -116,6 +143,7 @@ public:
private: private:
std::shared_ptr<SixAxisState> GetStateFromAruid(const u64 aruid) const; std::shared_ptr<SixAxisState> GetStateFromAruid(const u64 aruid) const;
mutable std::mutex mutex;
std::shared_ptr<SixAxisState> active_sixaxis_state = nullptr; std::shared_ptr<SixAxisState> active_sixaxis_state = nullptr;
std::array<std::shared_ptr<SixAxisState>, ARUID_MAX> sixaxis_state{}; std::array<std::shared_ptr<SixAxisState>, ARUID_MAX> sixaxis_state{};
}; };