summaryrefslogtreecommitdiff
path: root/src/core/hid
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_controller.cpp22
-rw-r--r--src/core/hid/emulated_controller.h5
-rw-r--r--src/core/hid/hid_types.h7
-rw-r--r--src/core/hid/motion_input.cpp12
-rw-r--r--src/core/hid/motion_input.h15
5 files changed, 55 insertions, 6 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
1287void 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
1287void EmulatedController::SetSupportedNpadStyleTag(NpadStyleTag supported_styles) { 1307void 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
286enum 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
286struct NpadStyleTag { 293struct 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 {
9MotionInput::MotionInput() { 9MotionInput::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
15void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { 15void 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
52void MotionInput::SetUserGyroThreshold(f32 threshold) {
53 user_gyro_threshold = threshold / ThresholdStandard;
54}
55
52void MotionInput::EnableReset(bool reset) { 56void 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
12class MotionInput { 12class MotionInput {
13public: 13public:
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