summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hid/emulated_console.cpp3
-rw-r--r--src/core/hid/emulated_console.h2
-rw-r--r--src/core/hid/motion_input.cpp12
-rw-r--r--src/core/hid/motion_input.h5
-rw-r--r--src/core/hle/service/hid/controllers/console_sixaxis.cpp20
-rw-r--r--src/core/hle/service/hid/controllers/console_sixaxis.h10
6 files changed, 32 insertions, 20 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 685ec080c..08f8af551 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -161,7 +161,10 @@ void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) {
161 motion.rotation = emulated.GetGyroscope(); 161 motion.rotation = emulated.GetGyroscope();
162 motion.orientation = emulated.GetOrientation(); 162 motion.orientation = emulated.GetOrientation();
163 motion.quaternion = emulated.GetQuaternion(); 163 motion.quaternion = emulated.GetQuaternion();
164 motion.gyro_bias = emulated.GetGyroBias();
164 motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); 165 motion.is_at_rest = !emulated.IsMoving(motion_sensitivity);
166 // Find what is this value
167 motion.verticalization_error = 0.0f;
165 168
166 TriggerOnChange(ConsoleTriggerType::Motion); 169 TriggerOnChange(ConsoleTriggerType::Motion);
167} 170}
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index 3afd284d5..707419102 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -50,6 +50,8 @@ struct ConsoleMotion {
50 Common::Vec3f rotation{}; 50 Common::Vec3f rotation{};
51 std::array<Common::Vec3f, 3> orientation{}; 51 std::array<Common::Vec3f, 3> orientation{};
52 Common::Quaternion<f32> quaternion{}; 52 Common::Quaternion<f32> quaternion{};
53 Common::Vec3f gyro_bias{};
54 f32 verticalization_error{};
53 bool is_at_rest{}; 55 bool is_at_rest{};
54}; 56};
55 57
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp
index c25fea966..a23f192d7 100644
--- a/src/core/hid/motion_input.cpp
+++ b/src/core/hid/motion_input.cpp
@@ -23,11 +23,11 @@ void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) {
23} 23}
24 24
25void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { 25void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) {
26 gyro = gyroscope - gyro_drift; 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(0.1f)) {
30 gyro_drift = (gyro_drift * 0.9999f) + (gyroscope * 0.0001f); 30 gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f);
31 } 31 }
32 32
33 if (gyro.Length2() < gyro_threshold) { 33 if (gyro.Length2() < gyro_threshold) {
@@ -41,8 +41,8 @@ void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) {
41 quat = quaternion; 41 quat = quaternion;
42} 42}
43 43
44void MotionInput::SetGyroDrift(const Common::Vec3f& drift) { 44void MotionInput::SetGyroBias(const Common::Vec3f& bias) {
45 gyro_drift = drift; 45 gyro_bias = bias;
46} 46}
47 47
48void MotionInput::SetGyroThreshold(f32 threshold) { 48void MotionInput::SetGyroThreshold(f32 threshold) {
@@ -192,6 +192,10 @@ Common::Vec3f MotionInput::GetGyroscope() const {
192 return gyro; 192 return gyro;
193} 193}
194 194
195Common::Vec3f MotionInput::GetGyroBias() const {
196 return gyro_bias;
197}
198
195Common::Quaternion<f32> MotionInput::GetQuaternion() const { 199Common::Quaternion<f32> MotionInput::GetQuaternion() const {
196 return quat; 200 return quat;
197} 201}
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h
index 5b5b420bb..bca4520fa 100644
--- a/src/core/hid/motion_input.h
+++ b/src/core/hid/motion_input.h
@@ -24,7 +24,7 @@ public:
24 void SetAcceleration(const Common::Vec3f& acceleration); 24 void SetAcceleration(const Common::Vec3f& acceleration);
25 void SetGyroscope(const Common::Vec3f& gyroscope); 25 void SetGyroscope(const Common::Vec3f& gyroscope);
26 void SetQuaternion(const Common::Quaternion<f32>& quaternion); 26 void SetQuaternion(const Common::Quaternion<f32>& quaternion);
27 void SetGyroDrift(const Common::Vec3f& drift); 27 void SetGyroBias(const Common::Vec3f& bias);
28 void SetGyroThreshold(f32 threshold); 28 void SetGyroThreshold(f32 threshold);
29 29
30 void EnableReset(bool reset); 30 void EnableReset(bool reset);
@@ -36,6 +36,7 @@ public:
36 [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const; 36 [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const;
37 [[nodiscard]] Common::Vec3f GetAcceleration() const; 37 [[nodiscard]] Common::Vec3f GetAcceleration() const;
38 [[nodiscard]] Common::Vec3f GetGyroscope() const; 38 [[nodiscard]] Common::Vec3f GetGyroscope() const;
39 [[nodiscard]] Common::Vec3f GetGyroBias() const;
39 [[nodiscard]] Common::Vec3f GetRotations() const; 40 [[nodiscard]] Common::Vec3f GetRotations() const;
40 [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; 41 [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const;
41 42
@@ -69,7 +70,7 @@ private:
69 Common::Vec3f gyro; 70 Common::Vec3f gyro;
70 71
71 // Vector to be substracted from gyro measurements 72 // Vector to be substracted from gyro measurements
72 Common::Vec3f gyro_drift; 73 Common::Vec3f gyro_bias;
73 74
74 // Minimum gyro amplitude to detect if the device is moving 75 // Minimum gyro amplitude to detect if the device is moving
75 f32 gyro_threshold = 0.0f; 76 f32 gyro_threshold = 0.0f;
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp
index f0f3105dc..a727b3582 100644
--- a/src/core/hle/service/hid/controllers/console_sixaxis.cpp
+++ b/src/core/hle/service/hid/controllers/console_sixaxis.cpp
@@ -33,15 +33,14 @@ void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_ti
33 const auto& last_entry = seven_sixaxis_lifo.ReadCurrentEntry().state; 33 const auto& last_entry = seven_sixaxis_lifo.ReadCurrentEntry().state;
34 next_seven_sixaxis_state.sampling_number = last_entry.sampling_number + 1; 34 next_seven_sixaxis_state.sampling_number = last_entry.sampling_number + 1;
35 35
36 // Try to read sixaxis sensor states
37 const auto motion_status = console->GetMotion(); 36 const auto motion_status = console->GetMotion();
37 last_global_timestamp = core_timing.GetGlobalTimeNs().count();
38 38
39 console_six_axis.is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest; 39 // This value increments every time the switch goes to sleep
40 40 next_seven_sixaxis_state.unknown = 1;
41 next_seven_sixaxis_state.timestamp = last_global_timestamp - last_saved_timestamp;
41 next_seven_sixaxis_state.accel = motion_status.accel; 42 next_seven_sixaxis_state.accel = motion_status.accel;
42 // Zero gyro values as they just mess up with the camera 43 next_seven_sixaxis_state.gyro = motion_status.gyro;
43 // Note: Probably a correct sensivity setting must be set
44 next_seven_sixaxis_state.gyro = {};
45 next_seven_sixaxis_state.quaternion = { 44 next_seven_sixaxis_state.quaternion = {
46 { 45 {
47 motion_status.quaternion.xyz.y, 46 motion_status.quaternion.xyz.y,
@@ -52,9 +51,9 @@ void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_ti
52 }; 51 };
53 52
54 console_six_axis.sampling_number++; 53 console_six_axis.sampling_number++;
55 // TODO(German77): Find the purpose of those values 54 console_six_axis.is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest;
56 console_six_axis.verticalization_error = 0.0f; 55 console_six_axis.verticalization_error = motion_status.verticalization_error;
57 console_six_axis.gyro_bias = {0.0f, 0.0f, 0.0f}; 56 console_six_axis.gyro_bias = motion_status.gyro_bias;
58 57
59 // Update console six axis shared memory 58 // Update console six axis shared memory
60 std::memcpy(data + SHARED_MEMORY_OFFSET, &console_six_axis, sizeof(console_six_axis)); 59 std::memcpy(data + SHARED_MEMORY_OFFSET, &console_six_axis, sizeof(console_six_axis));
@@ -69,7 +68,6 @@ void Controller_ConsoleSixAxis::SetTransferMemoryPointer(u8* t_mem) {
69} 68}
70 69
71void Controller_ConsoleSixAxis::ResetTimestamp() { 70void Controller_ConsoleSixAxis::ResetTimestamp() {
72 seven_sixaxis_lifo.buffer_count = 0; 71 last_saved_timestamp = last_global_timestamp;
73 seven_sixaxis_lifo.buffer_tail = 0;
74} 72}
75} // namespace Service::HID 73} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h
index 279241858..26d153f0c 100644
--- a/src/core/hle/service/hid/controllers/console_sixaxis.h
+++ b/src/core/hle/service/hid/controllers/console_sixaxis.h
@@ -39,8 +39,9 @@ public:
39 39
40private: 40private:
41 struct SevenSixAxisState { 41 struct SevenSixAxisState {
42 INSERT_PADDING_WORDS(4); // unused 42 INSERT_PADDING_WORDS(2); // unused
43 s64 sampling_number{}; 43 u64 timestamp{};
44 u64 sampling_number{};
44 u64 unknown{}; 45 u64 unknown{};
45 Common::Vec3f accel{}; 46 Common::Vec3f accel{};
46 Common::Vec3f gyro{}; 47 Common::Vec3f gyro{};
@@ -52,9 +53,10 @@ private:
52 struct ConsoleSharedMemory { 53 struct ConsoleSharedMemory {
53 u64 sampling_number{}; 54 u64 sampling_number{};
54 bool is_seven_six_axis_sensor_at_rest{}; 55 bool is_seven_six_axis_sensor_at_rest{};
55 INSERT_PADDING_BYTES(4); // padding 56 INSERT_PADDING_BYTES(3); // padding
56 f32 verticalization_error{}; 57 f32 verticalization_error{};
57 Common::Vec3f gyro_bias{}; 58 Common::Vec3f gyro_bias{};
59 INSERT_PADDING_BYTES(4); // padding
58 }; 60 };
59 static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size"); 61 static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size");
60 62
@@ -64,6 +66,8 @@ private:
64 Core::HID::EmulatedConsole* console; 66 Core::HID::EmulatedConsole* console;
65 u8* transfer_memory = nullptr; 67 u8* transfer_memory = nullptr;
66 bool is_transfer_memory_set = false; 68 bool is_transfer_memory_set = false;
69 u64 last_saved_timestamp{};
70 u64 last_global_timestamp{};
67 ConsoleSharedMemory console_six_axis{}; 71 ConsoleSharedMemory console_six_axis{};
68 SevenSixAxisState next_seven_sixaxis_state{}; 72 SevenSixAxisState next_seven_sixaxis_state{};
69}; 73};