summaryrefslogtreecommitdiffstats
path: root/src/core/hid
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2021-11-02 02:49:14 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2021-11-25 03:30:27 +0100
commit136eb9c4c2b2425c2dd45a79cf444dee7170714d (patch)
tree74a055a08126fdd33b2071baa08125177847db6e /src/core/hid
parentsecond commit lion review (diff)
downloadyuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.gz
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.bz2
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.lz
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.xz
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.zst
yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.zip
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_controller.cpp11
-rw-r--r--src/core/hid/emulated_controller.h1
-rw-r--r--src/core/hid/input_converter.cpp78
-rw-r--r--src/core/hid/motion_input.h16
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::
});
emulated.UpdateRotation(raw_status.delta_timestamp);
emulated.UpdateOrientation(raw_status.delta_timestamp);
+ force_update_motion = raw_status.force_update;
if (is_configuring) {
TriggerOnChange(ControllerTriggerType::Motion, false);
@@ -653,7 +654,7 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::
auto& motion = controller.motion_state[index];
motion.accel = emulated.GetAcceleration();
motion.gyro = emulated.GetGyroscope();
- motion.rotation = emulated.GetGyroscope();
+ motion.rotation = emulated.GetRotations();
motion.orientation = emulated.GetOrientation();
motion.is_at_rest = emulated.IsMoving(motion_sensitivity);
@@ -962,6 +963,14 @@ NpadGcTriggerState EmulatedController::GetTriggers() const {
}
MotionState EmulatedController::GetMotions() const {
+ if (force_update_motion) {
+ for (auto& device : motion_devices) {
+ if (!device) {
+ continue;
+ }
+ device->ForceUpdate();
+ }
+ }
return controller.motion_state;
}
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:
bool is_connected{false};
bool is_configuring{false};
f32 motion_sensitivity{0.01f};
+ bool force_update_motion{false};
// Temporary values to avoid doing changes while the controller is on configuration mode
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
Common::Input::MotionStatus status{};
switch (callback.type) {
case Common::Input::InputType::Button: {
+ Common::Input::AnalogProperties properties{
+ .deadzone = 0.0f,
+ .range = 1.0f,
+ .offset = 0.0f,
+ };
+ status.delta_timestamp = 5000;
+ status.force_update = true;
+ status.accel.x = {
+ .value = 0.0f,
+ .raw_value = 0.0f,
+ .properties = properties,
+ };
+ status.accel.y = {
+ .value = 0.0f,
+ .raw_value = 0.0f,
+ .properties = properties,
+ };
+ status.accel.z = {
+ .value = 0.0f,
+ .raw_value = -1.0f,
+ .properties = properties,
+ };
+ status.gyro.x = {
+ .value = 0.0f,
+ .raw_value = 0.0f,
+ .properties = properties,
+ };
+ status.gyro.y = {
+ .value = 0.0f,
+ .raw_value = 0.0f,
+ .properties = properties,
+ };
+ status.gyro.z = {
+ .value = 0.0f,
+ .raw_value = 0.0f,
+ .properties = properties,
+ };
if (TransformToButton(callback).value) {
std::random_device device;
std::mt19937 gen(device());
std::uniform_int_distribution<s16> distribution(-1000, 1000);
- Common::Input::AnalogProperties properties{
- .deadzone = 0.0,
- .range = 1.0f,
- .offset = 0.0,
- };
- status.accel.x = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
- status.accel.y = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
- status.accel.z = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
- status.gyro.x = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
- status.gyro.y = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
- status.gyro.z = {
- .value = 0,
- .raw_value = static_cast<f32>(distribution(gen)) * 0.001f,
- .properties = properties,
- };
+ status.accel.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
+ status.accel.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
+ status.accel.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
+ status.gyro.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
+ status.gyro.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
+ status.gyro.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
}
break;
}
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:
Common::Vec3f integral_error;
Common::Vec3f derivative_error;
+ // Quaternion containing the device orientation
Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f};
+
+ // Number of full rotations in each axis
Common::Vec3f rotations;
+
+ // Acceleration vector measurement in G force
Common::Vec3f accel;
+
+ // Gyroscope vector measurement in radians/s.
Common::Vec3f gyro;
+
+ // Vector to be substracted from gyro measurements
Common::Vec3f gyro_drift;
+ // Minimum gyro amplitude to detect if the device is moving
f32 gyro_threshold = 0.0f;
+
+ // Number of invalid sequential data
u32 reset_counter = 0;
+
+ // If the provided data is invalid the device will be autocalibrated
bool reset_enabled = true;
+
+ // Use accelerometer values to calculate position
bool only_accelerometer = true;
};