From 6106f780a73e74f10392171b3f20b3738f965773 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 17 Nov 2019 17:10:35 -0600 Subject: [PATCH] ControllerInterface/DSUClient: Eliminate m_accl/m_gyro state by accessing the pad data directly like every other input. --- .../DualShockUDPClient/DualShockUDPClient.cpp | 47 +++++++------------ .../DualShockUDPClient/DualShockUDPProto.h | 2 +- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp index 937e1b6f16..b2258b1542 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp @@ -90,7 +90,7 @@ private: bool IsDetectable() override { return false; } }; - class MotionInput final : public AnalogInput + class MotionInput final : public AnalogInput { public: using AnalogInput::AnalogInput; @@ -141,8 +141,6 @@ private: const int m_index; u32 m_client_uid = Common::Random::GenerateValue(); sf::UdpSocket m_socket; - Common::DVec3 m_accel{}; - Common::DVec3 m_gyro{}; SteadyClock::time_point m_next_reregister = SteadyClock::time_point::min(); Proto::MessageType::PadDataResponse m_pad_data{}; Proto::Touch m_prev_touch{}; @@ -367,21 +365,25 @@ Device::Device(Proto::DsModel model, int index) : m_model{model}, m_index{index} AddInput(new TouchInput("Touch Y-", m_touch_y, -TOUCH_Y_AXIS_MAX)); AddInput(new TouchInput("Touch Y+", m_touch_y, TOUCH_Y_AXIS_MAX)); - AddInput(new AccelerometerInput("Accel Left", m_accel.x, 1)); - AddInput(new AccelerometerInput("Accel Right", m_accel.x, -1)); - AddInput(new AccelerometerInput("Accel Backward", m_accel.y, 1)); - AddInput(new AccelerometerInput("Accel Forward", m_accel.y, -1)); - AddInput(new AccelerometerInput("Accel Up", m_accel.z, 1)); - AddInput(new AccelerometerInput("Accel Down", m_accel.z, -1)); + // Convert Gs to meters per second squared + constexpr auto accel_scale = 1.0 / GRAVITY_ACCELERATION; - AddInput(new GyroInput("Gyro Pitch Up", m_gyro.x, -1)); - AddInput(new GyroInput("Gyro Pitch Down", m_gyro.x, 1)); - AddInput(new GyroInput("Gyro Roll Right", m_gyro.y, -1)); - AddInput(new GyroInput("Gyro Roll Left", m_gyro.y, 1)); - AddInput(new GyroInput("Gyro Yaw Right", m_gyro.z, -1)); - AddInput(new GyroInput("Gyro Yaw Left", m_gyro.z, 1)); + AddInput(new AccelerometerInput("Accel Up", m_pad_data.accelerometer_y_g, -accel_scale)); + AddInput(new AccelerometerInput("Accel Down", m_pad_data.accelerometer_y_g, accel_scale)); + AddInput(new AccelerometerInput("Accel Left", m_pad_data.accelerometer_x_g, accel_scale)); + AddInput(new AccelerometerInput("Accel Right", m_pad_data.accelerometer_x_g, -accel_scale)); + AddInput(new AccelerometerInput("Accel Forward", m_pad_data.accelerometer_z_g, accel_scale)); + AddInput(new AccelerometerInput("Accel Backward", m_pad_data.accelerometer_z_g, -accel_scale)); - AddInput(new BatteryInput(m_pad_data.battery_status)); + // Convert degrees per second to radians per second + constexpr auto gyro_scale = 360.0 / MathUtil::TAU; + + AddInput(new GyroInput("Gyro Pitch Up", m_pad_data.gyro_pitch_deg_s, gyro_scale)); + AddInput(new GyroInput("Gyro Pitch Down", m_pad_data.gyro_pitch_deg_s, -gyro_scale)); + AddInput(new GyroInput("Gyro Roll Left", m_pad_data.gyro_roll_deg_s, -gyro_scale)); + AddInput(new GyroInput("Gyro Roll Right", m_pad_data.gyro_roll_deg_s, gyro_scale)); + AddInput(new GyroInput("Gyro Yaw Left", m_pad_data.gyro_yaw_deg_s, -gyro_scale)); + AddInput(new GyroInput("Gyro Yaw Right", m_pad_data.gyro_yaw_deg_s, gyro_scale)); } std::string Device::GetName() const @@ -436,19 +438,6 @@ void Device::UpdateInput() { m_pad_data = *pad_data; - m_accel.x = m_pad_data.accelerometer_x_g; - m_accel.z = -m_pad_data.accelerometer_y_g; - m_accel.y = -m_pad_data.accelerometer_z_inverted_g; - m_gyro.x = -m_pad_data.gyro_pitch_deg_s; - m_gyro.z = -m_pad_data.gyro_yaw_deg_s; - m_gyro.y = -m_pad_data.gyro_roll_deg_s; - - // Convert Gs to meters per second squared - m_accel = m_accel * GRAVITY_ACCELERATION; - - // Convert degrees per second to radians per second - m_gyro = m_gyro * (MathUtil::TAU / 360); - // Update touch pad relative coordinates if (m_pad_data.touch1.id != m_prev_touch.id) m_prev_touch_valid = false; diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h index 4932c22049..5e3e9f0dde 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h @@ -181,7 +181,7 @@ struct PadDataResponse u64 timestamp_us; float accelerometer_x_g; float accelerometer_y_g; - float accelerometer_z_inverted_g; + float accelerometer_z_g; float gyro_pitch_deg_s; float gyro_yaw_deg_s; float gyro_roll_deg_s;