diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2019-11-17 10:42:49 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-01-13 16:29:24 -0600 |
| commit | f0534cabc6da4a090b61b8723ddddee76b36deb3 (patch) | |
| tree | 3d855d83287365fd26df10905d58fb2350296e9c /Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp | |
| parent | 48fd27cdab67061af32f3120534b57d70b23f71e (diff) | |
ControllerInterface: Exposse DSU client battery level as an input.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp index 913e03db2b..cb695018c3 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp @@ -102,6 +102,33 @@ private: using GyroInput = AccelerometerInput; + class BatteryInput final : public Input + { + using BatteryState = Proto::DsBattery; + + public: + BatteryInput(const BatteryState& battery) : m_battery(battery) {} + + std::string GetName() const override { return "Battery"; } + + ControlState GetState() const override + { + switch (m_battery) + { + case BatteryState::Charging: + case BatteryState::Charged: + return BATTERY_INPUT_MAX_VALUE; + default: + return ControlState(m_battery) / ControlState(BatteryState::Full) * BATTERY_INPUT_MAX_VALUE; + } + } + + bool IsDetectable() override { return false; } + + private: + const BatteryState& m_battery; + }; + public: void UpdateInput() override; @@ -355,6 +382,8 @@ Device::Device(Proto::DsModel model, int index) : m_model{model}, m_index{index} 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 BatteryInput(m_pad_data.battery_status)); } std::string Device::GetName() const |
