summaryrefslogtreecommitdiff
path: root/src/core/hid/motion_input.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid/motion_input.h')
-rw-r--r--src/core/hid/motion_input.h119
1 files changed, 0 insertions, 119 deletions
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h
deleted file mode 100644
index 11678983d..000000000
--- a/src/core/hid/motion_input.h
+++ /dev/null
@@ -1,119 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/common_types.h"
7#include "common/quaternion.h"
8#include "common/vector_math.h"
9
10namespace Core::HID {
11
12class MotionInput {
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
23 static constexpr float GyroMaxValue = 5.0f;
24 static constexpr float AccelMaxValue = 7.0f;
25
26 static constexpr std::size_t CalibrationSamples = 300;
27
28 explicit MotionInput();
29
30 MotionInput(const MotionInput&) = default;
31 MotionInput& operator=(const MotionInput&) = default;
32
33 MotionInput(MotionInput&&) = default;
34 MotionInput& operator=(MotionInput&&) = default;
35
36 void SetPID(f32 new_kp, f32 new_ki, f32 new_kd);
37 void SetAcceleration(const Common::Vec3f& acceleration);
38 void SetGyroscope(const Common::Vec3f& gyroscope);
39 void SetQuaternion(const Common::Quaternion<f32>& quaternion);
40 void SetEulerAngles(const Common::Vec3f& euler_angles);
41 void SetGyroBias(const Common::Vec3f& bias);
42 void SetGyroThreshold(f32 threshold);
43
44 /// Applies a modifier on top of the normal gyro threshold
45 void SetUserGyroThreshold(f32 threshold);
46
47 void EnableReset(bool reset);
48 void ResetRotations();
49 void ResetQuaternion();
50
51 void UpdateRotation(u64 elapsed_time);
52 void UpdateOrientation(u64 elapsed_time);
53
54 void Calibrate();
55
56 [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const;
57 [[nodiscard]] Common::Vec3f GetAcceleration() const;
58 [[nodiscard]] Common::Vec3f GetGyroscope() const;
59 [[nodiscard]] Common::Vec3f GetGyroBias() const;
60 [[nodiscard]] Common::Vec3f GetRotations() const;
61 [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const;
62 [[nodiscard]] Common::Vec3f GetEulerAngles() const;
63
64 [[nodiscard]] bool IsMoving(f32 sensitivity) const;
65 [[nodiscard]] bool IsCalibrated(f32 sensitivity) const;
66
67private:
68 void StopCalibration();
69 void ResetOrientation();
70 void SetOrientationFromAccelerometer();
71
72 // PID constants
73 f32 kp;
74 f32 ki;
75 f32 kd;
76
77 // PID errors
78 Common::Vec3f real_error;
79 Common::Vec3f integral_error;
80 Common::Vec3f derivative_error;
81
82 // Quaternion containing the device orientation
83 Common::Quaternion<f32> quat;
84
85 // Number of full rotations in each axis
86 Common::Vec3f rotations;
87
88 // Acceleration vector measurement in G force
89 Common::Vec3f accel;
90
91 // Gyroscope vector measurement in radians/s.
92 Common::Vec3f gyro;
93
94 // Vector to be subtracted from gyro measurements
95 Common::Vec3f gyro_bias;
96
97 // Minimum gyro amplitude to detect if the device is moving
98 f32 gyro_threshold = 0.0f;
99
100 // Multiplies gyro_threshold by this value
101 f32 user_gyro_threshold = 0.0f;
102
103 // Number of invalid sequential data
104 u32 reset_counter = 0;
105
106 // If the provided data is invalid the device will be autocalibrated
107 bool reset_enabled = true;
108
109 // Use accelerometer values to calculate position
110 bool only_accelerometer = true;
111
112 // When enabled it will aggressively adjust for gyro drift
113 bool calibration_mode = false;
114
115 // Used to auto disable calibration mode
116 std::size_t calibration_counter = 0;
117};
118
119} // namespace Core::HID