diff options
| author | 2021-11-01 19:49:14 -0600 | |
|---|---|---|
| committer | 2021-11-24 20:30:27 -0600 | |
| commit | 136eb9c4c2b2425c2dd45a79cf444dee7170714d (patch) | |
| tree | 74a055a08126fdd33b2071baa08125177847db6e /src/core | |
| parent | second commit lion review (diff) | |
| download | yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.gz yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.xz yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.zip | |
core/hid: Fully emulate motion from button
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 11 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 1 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 78 | ||||
| -rw-r--r-- | src/core/hid/motion_input.h | 16 |
4 files changed, 70 insertions, 36 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 7bab00bb1..2db2b4da0 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -644,6 +644,7 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std:: | |||
| 644 | }); | 644 | }); |
| 645 | emulated.UpdateRotation(raw_status.delta_timestamp); | 645 | emulated.UpdateRotation(raw_status.delta_timestamp); |
| 646 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 646 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 647 | force_update_motion = raw_status.force_update; | ||
| 647 | 648 | ||
| 648 | if (is_configuring) { | 649 | if (is_configuring) { |
| 649 | TriggerOnChange(ControllerTriggerType::Motion, false); | 650 | TriggerOnChange(ControllerTriggerType::Motion, false); |
| @@ -653,7 +654,7 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std:: | |||
| 653 | auto& motion = controller.motion_state[index]; | 654 | auto& motion = controller.motion_state[index]; |
| 654 | motion.accel = emulated.GetAcceleration(); | 655 | motion.accel = emulated.GetAcceleration(); |
| 655 | motion.gyro = emulated.GetGyroscope(); | 656 | motion.gyro = emulated.GetGyroscope(); |
| 656 | motion.rotation = emulated.GetGyroscope(); | 657 | motion.rotation = emulated.GetRotations(); |
| 657 | motion.orientation = emulated.GetOrientation(); | 658 | motion.orientation = emulated.GetOrientation(); |
| 658 | motion.is_at_rest = emulated.IsMoving(motion_sensitivity); | 659 | motion.is_at_rest = emulated.IsMoving(motion_sensitivity); |
| 659 | 660 | ||
| @@ -962,6 +963,14 @@ NpadGcTriggerState EmulatedController::GetTriggers() const { | |||
| 962 | } | 963 | } |
| 963 | 964 | ||
| 964 | MotionState EmulatedController::GetMotions() const { | 965 | MotionState EmulatedController::GetMotions() const { |
| 966 | if (force_update_motion) { | ||
| 967 | for (auto& device : motion_devices) { | ||
| 968 | if (!device) { | ||
| 969 | continue; | ||
| 970 | } | ||
| 971 | device->ForceUpdate(); | ||
| 972 | } | ||
| 973 | } | ||
| 965 | return controller.motion_state; | 974 | return controller.motion_state; |
| 966 | } | 975 | } |
| 967 | 976 | ||
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index dd9a93364..2f7afff56 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -355,6 +355,7 @@ private: | |||
| 355 | bool is_connected{false}; | 355 | bool is_connected{false}; |
| 356 | bool is_configuring{false}; | 356 | bool is_configuring{false}; |
| 357 | f32 motion_sensitivity{0.01f}; | 357 | f32 motion_sensitivity{0.01f}; |
| 358 | bool force_update_motion{false}; | ||
| 358 | 359 | ||
| 359 | // Temporary values to avoid doing changes while the controller is on configuration mode | 360 | // Temporary values to avoid doing changes while the controller is on configuration mode |
| 360 | NpadType tmp_npad_type{NpadType::None}; | 361 | NpadType tmp_npad_type{NpadType::None}; |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 5b123bd3a..480b862fd 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -74,45 +74,53 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu | |||
| 74 | Common::Input::MotionStatus status{}; | 74 | Common::Input::MotionStatus status{}; |
| 75 | switch (callback.type) { | 75 | switch (callback.type) { |
| 76 | case Common::Input::InputType::Button: { | 76 | case Common::Input::InputType::Button: { |
| 77 | Common::Input::AnalogProperties properties{ | ||
| 78 | .deadzone = 0.0f, | ||
| 79 | .range = 1.0f, | ||
| 80 | .offset = 0.0f, | ||
| 81 | }; | ||
| 82 | status.delta_timestamp = 5000; | ||
| 83 | status.force_update = true; | ||
| 84 | status.accel.x = { | ||
| 85 | .value = 0.0f, | ||
| 86 | .raw_value = 0.0f, | ||
| 87 | .properties = properties, | ||
| 88 | }; | ||
| 89 | status.accel.y = { | ||
| 90 | .value = 0.0f, | ||
| 91 | .raw_value = 0.0f, | ||
| 92 | .properties = properties, | ||
| 93 | }; | ||
| 94 | status.accel.z = { | ||
| 95 | .value = 0.0f, | ||
| 96 | .raw_value = -1.0f, | ||
| 97 | .properties = properties, | ||
| 98 | }; | ||
| 99 | status.gyro.x = { | ||
| 100 | .value = 0.0f, | ||
| 101 | .raw_value = 0.0f, | ||
| 102 | .properties = properties, | ||
| 103 | }; | ||
| 104 | status.gyro.y = { | ||
| 105 | .value = 0.0f, | ||
| 106 | .raw_value = 0.0f, | ||
| 107 | .properties = properties, | ||
| 108 | }; | ||
| 109 | status.gyro.z = { | ||
| 110 | .value = 0.0f, | ||
| 111 | .raw_value = 0.0f, | ||
| 112 | .properties = properties, | ||
| 113 | }; | ||
| 77 | if (TransformToButton(callback).value) { | 114 | if (TransformToButton(callback).value) { |
| 78 | std::random_device device; | 115 | std::random_device device; |
| 79 | std::mt19937 gen(device()); | 116 | std::mt19937 gen(device()); |
| 80 | std::uniform_int_distribution<s16> distribution(-1000, 1000); | 117 | std::uniform_int_distribution<s16> distribution(-1000, 1000); |
| 81 | Common::Input::AnalogProperties properties{ | 118 | status.accel.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 82 | .deadzone = 0.0, | 119 | status.accel.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 83 | .range = 1.0f, | 120 | status.accel.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 84 | .offset = 0.0, | 121 | status.gyro.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 85 | }; | 122 | status.gyro.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 86 | status.accel.x = { | 123 | status.gyro.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f; |
| 87 | .value = 0, | ||
| 88 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 89 | .properties = properties, | ||
| 90 | }; | ||
| 91 | status.accel.y = { | ||
| 92 | .value = 0, | ||
| 93 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 94 | .properties = properties, | ||
| 95 | }; | ||
| 96 | status.accel.z = { | ||
| 97 | .value = 0, | ||
| 98 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 99 | .properties = properties, | ||
| 100 | }; | ||
| 101 | status.gyro.x = { | ||
| 102 | .value = 0, | ||
| 103 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 104 | .properties = properties, | ||
| 105 | }; | ||
| 106 | status.gyro.y = { | ||
| 107 | .value = 0, | ||
| 108 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 109 | .properties = properties, | ||
| 110 | }; | ||
| 111 | status.gyro.z = { | ||
| 112 | .value = 0, | ||
| 113 | .raw_value = static_cast<f32>(distribution(gen)) * 0.001f, | ||
| 114 | .properties = properties, | ||
| 115 | }; | ||
| 116 | } | 124 | } |
| 117 | break; | 125 | break; |
| 118 | } | 126 | } |
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index 3deef5ac3..5b5b420bb 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h | |||
| @@ -56,15 +56,31 @@ private: | |||
| 56 | Common::Vec3f integral_error; | 56 | Common::Vec3f integral_error; |
| 57 | Common::Vec3f derivative_error; | 57 | Common::Vec3f derivative_error; |
| 58 | 58 | ||
| 59 | // Quaternion containing the device orientation | ||
| 59 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; | 60 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; |
| 61 | |||
| 62 | // Number of full rotations in each axis | ||
| 60 | Common::Vec3f rotations; | 63 | Common::Vec3f rotations; |
| 64 | |||
| 65 | // Acceleration vector measurement in G force | ||
| 61 | Common::Vec3f accel; | 66 | Common::Vec3f accel; |
| 67 | |||
| 68 | // Gyroscope vector measurement in radians/s. | ||
| 62 | Common::Vec3f gyro; | 69 | Common::Vec3f gyro; |
| 70 | |||
| 71 | // Vector to be substracted from gyro measurements | ||
| 63 | Common::Vec3f gyro_drift; | 72 | Common::Vec3f gyro_drift; |
| 64 | 73 | ||
| 74 | // Minimum gyro amplitude to detect if the device is moving | ||
| 65 | f32 gyro_threshold = 0.0f; | 75 | f32 gyro_threshold = 0.0f; |
| 76 | |||
| 77 | // Number of invalid sequential data | ||
| 66 | u32 reset_counter = 0; | 78 | u32 reset_counter = 0; |
| 79 | |||
| 80 | // If the provided data is invalid the device will be autocalibrated | ||
| 67 | bool reset_enabled = true; | 81 | bool reset_enabled = true; |
| 82 | |||
| 83 | // Use accelerometer values to calculate position | ||
| 68 | bool only_accelerometer = true; | 84 | bool only_accelerometer = true; |
| 69 | }; | 85 | }; |
| 70 | 86 | ||