From 98b00a28e4a2116984ee37f25dfe2598f591862c Mon Sep 17 00:00:00 2001 From: Filoppi Date: Mon, 10 May 2021 22:43:41 +0300 Subject: [PATCH] ControllerInterface: make DSU inputs start from resting pose instead of 0. Add battery level --- .../DualShockUDPClient/DualShockUDPClient.cpp | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp index 0f331f329d..6511af49c1 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp @@ -114,7 +114,7 @@ private: { switch (m_battery) { - case BatteryState::Charging: + case BatteryState::Charging: // We don't actually know the battery level in this case case BatteryState::Charged: return BATTERY_INPUT_MAX_VALUE; default: @@ -138,6 +138,8 @@ public: std::optional GetPreferredId() const final override; private: + void ResetPadData(); + const std::string m_name; const int m_index; sf::UdpSocket m_socket; @@ -149,6 +151,11 @@ private: int m_touch_y = 0; std::string m_server_address; u16 m_server_port; + + s16 m_touch_x_min; + s16 m_touch_y_min; + s16 m_touch_x_max; + s16 m_touch_y_max; }; using MathUtil::GRAVITY_ACCELERATION; @@ -528,6 +535,31 @@ Device::Device(std::string name, int index, std::string server_address, u16 serv 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)); + + AddInput(new BatteryInput(m_pad_data.battery_status)); + + m_touch_x_min = 0; + m_touch_y_min = 0; + // DS4 touchpad max values + m_touch_x_max = 1919; + m_touch_y_max = 941; + + ResetPadData(); +} + +void Device::ResetPadData() +{ + m_pad_data = Proto::MessageType::PadDataResponse{}; + + // Make sure they start from resting values, not from 0 + m_touch_x = m_touch_x_min + ((m_touch_x_max - m_touch_x_min) / 2.0); + m_touch_y = m_touch_y_min + ((m_touch_y_max - m_touch_y_min) / 2.0); + m_pad_data.left_stick_x = 128; + m_pad_data.left_stick_y_inverted = 128; + m_pad_data.right_stick_x = 128; + m_pad_data.right_stick_y_inverted = 128; + m_pad_data.touch1.x = m_touch_x; + m_pad_data.touch1.y = m_touch_y; } std::string Device::GetName() const