diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 22 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 5 | ||||
| -rw-r--r-- | src/core/hid/hid_types.h | 7 | ||||
| -rw-r--r-- | src/core/hid/motion_input.cpp | 12 | ||||
| -rw-r--r-- | src/core/hid/motion_input.h | 15 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 7 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 14 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 6 |
8 files changed, 67 insertions, 21 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 631aa6ad2..6d5a3dead 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -957,7 +957,7 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback | |||
| 957 | raw_status.gyro.y.value, | 957 | raw_status.gyro.y.value, |
| 958 | raw_status.gyro.z.value, | 958 | raw_status.gyro.z.value, |
| 959 | }); | 959 | }); |
| 960 | emulated.SetGyroThreshold(raw_status.gyro.x.properties.threshold); | 960 | emulated.SetUserGyroThreshold(raw_status.gyro.x.properties.threshold); |
| 961 | emulated.UpdateRotation(raw_status.delta_timestamp); | 961 | emulated.UpdateRotation(raw_status.delta_timestamp); |
| 962 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 962 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 963 | force_update_motion = raw_status.force_update; | 963 | force_update_motion = raw_status.force_update; |
| @@ -1284,6 +1284,26 @@ void EmulatedController::SetLedPattern() { | |||
| 1284 | } | 1284 | } |
| 1285 | } | 1285 | } |
| 1286 | 1286 | ||
| 1287 | void EmulatedController::SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode mode) { | ||
| 1288 | for (auto& motion : controller.motion_values) { | ||
| 1289 | switch (mode) { | ||
| 1290 | case GyroscopeZeroDriftMode::Loose: | ||
| 1291 | motion_sensitivity = motion.emulated.IsAtRestLoose; | ||
| 1292 | motion.emulated.SetGyroThreshold(motion.emulated.ThresholdLoose); | ||
| 1293 | break; | ||
| 1294 | case GyroscopeZeroDriftMode::Tight: | ||
| 1295 | motion_sensitivity = motion.emulated.IsAtRestThight; | ||
| 1296 | motion.emulated.SetGyroThreshold(motion.emulated.ThresholdThight); | ||
| 1297 | break; | ||
| 1298 | case GyroscopeZeroDriftMode::Standard: | ||
| 1299 | default: | ||
| 1300 | motion_sensitivity = motion.emulated.IsAtRestStandard; | ||
| 1301 | motion.emulated.SetGyroThreshold(motion.emulated.ThresholdStandard); | ||
| 1302 | break; | ||
| 1303 | } | ||
| 1304 | } | ||
| 1305 | } | ||
| 1306 | |||
| 1287 | void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles) { | 1307 | void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles) { |
| 1288 | supported_style_tag = supported_styles; | 1308 | supported_style_tag = supported_styles; |
| 1289 | if (!is_connected) { | 1309 | if (!is_connected) { |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index b02bf35c4..a9da465a2 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -398,6 +398,9 @@ public: | |||
| 398 | /// Asks the output device to change the player led pattern | 398 | /// Asks the output device to change the player led pattern |
| 399 | void SetLedPattern(); | 399 | void SetLedPattern(); |
| 400 | 400 | ||
| 401 | /// Changes sensitivity of the motion sensor | ||
| 402 | void SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode mode); | ||
| 403 | |||
| 401 | /** | 404 | /** |
| 402 | * Adds a callback to the list of events | 405 | * Adds a callback to the list of events |
| 403 | * @param update_callback A ConsoleUpdateCallback that will be triggered | 406 | * @param update_callback A ConsoleUpdateCallback that will be triggered |
| @@ -523,7 +526,7 @@ private: | |||
| 523 | bool is_connected{false}; | 526 | bool is_connected{false}; |
| 524 | bool is_configuring{false}; | 527 | bool is_configuring{false}; |
| 525 | bool system_buttons_enabled{true}; | 528 | bool system_buttons_enabled{true}; |
| 526 | f32 motion_sensitivity{0.01f}; | 529 | f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard}; |
| 527 | bool force_update_motion{false}; | 530 | bool force_update_motion{false}; |
| 528 | u32 turbo_button_state{0}; | 531 | u32 turbo_button_state{0}; |
| 529 | 532 | ||
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index e3b1cfbc6..6b35f448c 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h | |||
| @@ -282,6 +282,13 @@ enum class VibrationGcErmCommand : u64 { | |||
| 282 | StopHard = 2, | 282 | StopHard = 2, |
| 283 | }; | 283 | }; |
| 284 | 284 | ||
| 285 | // This is nn::hid::GyroscopeZeroDriftMode | ||
| 286 | enum class GyroscopeZeroDriftMode : u32 { | ||
| 287 | Loose = 0, | ||
| 288 | Standard = 1, | ||
| 289 | Tight = 2, | ||
| 290 | }; | ||
| 291 | |||
| 285 | // This is nn::hid::NpadStyleTag | 292 | // This is nn::hid::NpadStyleTag |
| 286 | struct NpadStyleTag { | 293 | struct NpadStyleTag { |
| 287 | union { | 294 | union { |
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index b1f658e62..eef6edf4b 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -9,7 +9,7 @@ namespace Core::HID { | |||
| 9 | MotionInput::MotionInput() { | 9 | MotionInput::MotionInput() { |
| 10 | // Initialize PID constants with default values | 10 | // Initialize PID constants with default values |
| 11 | SetPID(0.3f, 0.005f, 0.0f); | 11 | SetPID(0.3f, 0.005f, 0.0f); |
| 12 | SetGyroThreshold(0.007f); | 12 | SetGyroThreshold(ThresholdStandard); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { | 15 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { |
| @@ -26,11 +26,11 @@ void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { | |||
| 26 | gyro = gyroscope - gyro_bias; | 26 | gyro = gyroscope - gyro_bias; |
| 27 | 27 | ||
| 28 | // Auto adjust drift to minimize drift | 28 | // Auto adjust drift to minimize drift |
| 29 | if (!IsMoving(0.1f)) { | 29 | if (!IsMoving(IsAtRestRelaxed)) { |
| 30 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); | 30 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | if (gyro.Length() < gyro_threshold) { | 33 | if (gyro.Length() < gyro_threshold * user_gyro_threshold) { |
| 34 | gyro = {}; | 34 | gyro = {}; |
| 35 | } else { | 35 | } else { |
| 36 | only_accelerometer = false; | 36 | only_accelerometer = false; |
| @@ -49,6 +49,10 @@ void MotionInput::SetGyroThreshold(f32 threshold) { | |||
| 49 | gyro_threshold = threshold; | 49 | gyro_threshold = threshold; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | void MotionInput::SetUserGyroThreshold(f32 threshold) { | ||
| 53 | user_gyro_threshold = threshold / ThresholdStandard; | ||
| 54 | } | ||
| 55 | |||
| 52 | void MotionInput::EnableReset(bool reset) { | 56 | void MotionInput::EnableReset(bool reset) { |
| 53 | reset_enabled = reset; | 57 | reset_enabled = reset; |
| 54 | } | 58 | } |
| @@ -208,7 +212,7 @@ void MotionInput::ResetOrientation() { | |||
| 208 | if (!reset_enabled || only_accelerometer) { | 212 | if (!reset_enabled || only_accelerometer) { |
| 209 | return; | 213 | return; |
| 210 | } | 214 | } |
| 211 | if (!IsMoving(0.5f) && accel.z <= -0.9f) { | 215 | if (!IsMoving(IsAtRestRelaxed) && accel.z <= -0.9f) { |
| 212 | ++reset_counter; | 216 | ++reset_counter; |
| 213 | if (reset_counter > 900) { | 217 | if (reset_counter > 900) { |
| 214 | quat.w = 0; | 218 | quat.w = 0; |
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index f5fd90db5..9180bb9aa 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h | |||
| @@ -11,6 +11,15 @@ namespace Core::HID { | |||
| 11 | 11 | ||
| 12 | class MotionInput { | 12 | class MotionInput { |
| 13 | public: | 13 | public: |
| 14 | static constexpr float ThresholdLoose = 0.01f; | ||
| 15 | static constexpr float ThresholdStandard = 0.007f; | ||
| 16 | static constexpr float ThresholdThight = 0.002f; | ||
| 17 | |||
| 18 | static constexpr float IsAtRestRelaxed = 0.05f; | ||
| 19 | static constexpr float IsAtRestLoose = 0.02f; | ||
| 20 | static constexpr float IsAtRestStandard = 0.01f; | ||
| 21 | static constexpr float IsAtRestThight = 0.005f; | ||
| 22 | |||
| 14 | explicit MotionInput(); | 23 | explicit MotionInput(); |
| 15 | 24 | ||
| 16 | MotionInput(const MotionInput&) = default; | 25 | MotionInput(const MotionInput&) = default; |
| @@ -26,6 +35,9 @@ public: | |||
| 26 | void SetGyroBias(const Common::Vec3f& bias); | 35 | void SetGyroBias(const Common::Vec3f& bias); |
| 27 | void SetGyroThreshold(f32 threshold); | 36 | void SetGyroThreshold(f32 threshold); |
| 28 | 37 | ||
| 38 | /// Applies a modifier on top of the normal gyro threshold | ||
| 39 | void SetUserGyroThreshold(f32 threshold); | ||
| 40 | |||
| 29 | void EnableReset(bool reset); | 41 | void EnableReset(bool reset); |
| 30 | void ResetRotations(); | 42 | void ResetRotations(); |
| 31 | 43 | ||
| @@ -74,6 +86,9 @@ private: | |||
| 74 | // Minimum gyro amplitude to detect if the device is moving | 86 | // Minimum gyro amplitude to detect if the device is moving |
| 75 | f32 gyro_threshold = 0.0f; | 87 | f32 gyro_threshold = 0.0f; |
| 76 | 88 | ||
| 89 | // Multiplies gyro_threshold by this value | ||
| 90 | f32 user_gyro_threshold = 0.0f; | ||
| 91 | |||
| 77 | // Number of invalid sequential data | 92 | // Number of invalid sequential data |
| 78 | u32 reset_counter = 0; | 93 | u32 reset_counter = 0; |
| 79 | 94 | ||
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 80eba22e8..ba6f04d8d 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -1132,7 +1132,8 @@ Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { | |||
| 1132 | return ResultSuccess; | 1132 | return ResultSuccess; |
| 1133 | } | 1133 | } |
| 1134 | Result Controller_NPad::SetGyroscopeZeroDriftMode( | 1134 | Result Controller_NPad::SetGyroscopeZeroDriftMode( |
| 1135 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, GyroscopeZeroDriftMode drift_mode) { | 1135 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 1136 | Core::HID::GyroscopeZeroDriftMode drift_mode) { | ||
| 1136 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); | 1137 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); |
| 1137 | if (is_valid.IsError()) { | 1138 | if (is_valid.IsError()) { |
| 1138 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); | 1139 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); |
| @@ -1140,14 +1141,16 @@ Result Controller_NPad::SetGyroscopeZeroDriftMode( | |||
| 1140 | } | 1141 | } |
| 1141 | 1142 | ||
| 1142 | auto& sixaxis = GetSixaxisState(sixaxis_handle); | 1143 | auto& sixaxis = GetSixaxisState(sixaxis_handle); |
| 1144 | auto& controller = GetControllerFromHandle(sixaxis_handle); | ||
| 1143 | sixaxis.gyroscope_zero_drift_mode = drift_mode; | 1145 | sixaxis.gyroscope_zero_drift_mode = drift_mode; |
| 1146 | controller.device->SetGyroscopeZeroDriftMode(drift_mode); | ||
| 1144 | 1147 | ||
| 1145 | return ResultSuccess; | 1148 | return ResultSuccess; |
| 1146 | } | 1149 | } |
| 1147 | 1150 | ||
| 1148 | Result Controller_NPad::GetGyroscopeZeroDriftMode( | 1151 | Result Controller_NPad::GetGyroscopeZeroDriftMode( |
| 1149 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 1152 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 1150 | GyroscopeZeroDriftMode& drift_mode) const { | 1153 | Core::HID::GyroscopeZeroDriftMode& drift_mode) const { |
| 1151 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); | 1154 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); |
| 1152 | if (is_valid.IsError()) { | 1155 | if (is_valid.IsError()) { |
| 1153 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); | 1156 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 02cc00920..a5998c453 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -52,13 +52,6 @@ public: | |||
| 52 | // When the controller is requesting a motion update for the shared memory | 52 | // When the controller is requesting a motion update for the shared memory |
| 53 | void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) override; | 53 | void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 54 | 54 | ||
| 55 | // This is nn::hid::GyroscopeZeroDriftMode | ||
| 56 | enum class GyroscopeZeroDriftMode : u32 { | ||
| 57 | Loose = 0, | ||
| 58 | Standard = 1, | ||
| 59 | Tight = 2, | ||
| 60 | }; | ||
| 61 | |||
| 62 | // This is nn::hid::NpadJoyHoldType | 55 | // This is nn::hid::NpadJoyHoldType |
| 63 | enum class NpadJoyHoldType : u64 { | 56 | enum class NpadJoyHoldType : u64 { |
| 64 | Vertical = 0, | 57 | Vertical = 0, |
| @@ -146,9 +139,9 @@ public: | |||
| 146 | Result DisconnectNpad(Core::HID::NpadIdType npad_id); | 139 | Result DisconnectNpad(Core::HID::NpadIdType npad_id); |
| 147 | 140 | ||
| 148 | Result SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 141 | Result SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 149 | GyroscopeZeroDriftMode drift_mode); | 142 | Core::HID::GyroscopeZeroDriftMode drift_mode); |
| 150 | Result GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 143 | Result GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 151 | GyroscopeZeroDriftMode& drift_mode) const; | 144 | Core::HID::GyroscopeZeroDriftMode& drift_mode) const; |
| 152 | Result IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 145 | Result IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 153 | bool& is_at_rest) const; | 146 | bool& is_at_rest) const; |
| 154 | Result IsFirmwareUpdateAvailableForSixAxisSensor( | 147 | Result IsFirmwareUpdateAvailableForSixAxisSensor( |
| @@ -489,7 +482,8 @@ private: | |||
| 489 | Core::HID::SixAxisSensorFusionParameters fusion{}; | 482 | Core::HID::SixAxisSensorFusionParameters fusion{}; |
| 490 | Core::HID::SixAxisSensorCalibrationParameter calibration{}; | 483 | Core::HID::SixAxisSensorCalibrationParameter calibration{}; |
| 491 | Core::HID::SixAxisSensorIcInformation ic_information{}; | 484 | Core::HID::SixAxisSensorIcInformation ic_information{}; |
| 492 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | 485 | Core::HID::GyroscopeZeroDriftMode gyroscope_zero_drift_mode{ |
| 486 | Core::HID::GyroscopeZeroDriftMode::Standard}; | ||
| 493 | }; | 487 | }; |
| 494 | 488 | ||
| 495 | struct NpadControllerData { | 489 | struct NpadControllerData { |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index ac2c0c76d..5a1aa0903 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -712,7 +712,7 @@ void Hid::ResetSixAxisSensorFusionParameters(Kernel::HLERequestContext& ctx) { | |||
| 712 | void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | 712 | void Hid::SetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { |
| 713 | IPC::RequestParser rp{ctx}; | 713 | IPC::RequestParser rp{ctx}; |
| 714 | const auto sixaxis_handle{rp.PopRaw<Core::HID::SixAxisSensorHandle>()}; | 714 | const auto sixaxis_handle{rp.PopRaw<Core::HID::SixAxisSensorHandle>()}; |
| 715 | const auto drift_mode{rp.PopEnum<Controller_NPad::GyroscopeZeroDriftMode>()}; | 715 | const auto drift_mode{rp.PopEnum<Core::HID::GyroscopeZeroDriftMode>()}; |
| 716 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 716 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 717 | 717 | ||
| 718 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); | 718 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); |
| @@ -739,7 +739,7 @@ void Hid::GetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | |||
| 739 | 739 | ||
| 740 | const auto parameters{rp.PopRaw<Parameters>()}; | 740 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 741 | 741 | ||
| 742 | auto drift_mode{Controller_NPad::GyroscopeZeroDriftMode::Standard}; | 742 | auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; |
| 743 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); | 743 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); |
| 744 | const auto result = controller.GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); | 744 | const auto result = controller.GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); |
| 745 | 745 | ||
| @@ -764,7 +764,7 @@ void Hid::ResetGyroscopeZeroDriftMode(Kernel::HLERequestContext& ctx) { | |||
| 764 | 764 | ||
| 765 | const auto parameters{rp.PopRaw<Parameters>()}; | 765 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 766 | 766 | ||
| 767 | const auto drift_mode{Controller_NPad::GyroscopeZeroDriftMode::Standard}; | 767 | const auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; |
| 768 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); | 768 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); |
| 769 | const auto result = controller.SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); | 769 | const auto result = controller.SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); |
| 770 | 770 | ||