diff options
| author | 2022-01-22 01:28:14 -0800 | |
|---|---|---|
| committer | 2022-01-22 01:28:14 -0800 | |
| commit | 8433edacb34be3e3db9462c91d91c4a78987871d (patch) | |
| tree | 34116e9c9f4f6384c76641b893a90021e290c475 | |
| parent | Merge pull request #7737 from bunnei/fix-dummy-thread-leak (diff) | |
| parent | input_common: Report battery for UDP controllers (diff) | |
| download | yuzu-8433edacb34be3e3db9462c91d91c4a78987871d.tar.gz yuzu-8433edacb34be3e3db9462c91d91c4a78987871d.tar.xz yuzu-8433edacb34be3e3db9462c91d91c4a78987871d.zip | |
Merge pull request #7735 from german77/udp_battery
input_common: Report battery for UDP controllers
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 21 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 4 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index c8a12c7d5..9aaeb91be 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -192,6 +192,25 @@ std::size_t UDPClient::GetClientNumber(std::string_view host, u16 port) const { | |||
| 192 | return MAX_UDP_CLIENTS; | 192 | return MAX_UDP_CLIENTS; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | BatteryLevel UDPClient::GetBatteryLevel(Response::Battery battery) const { | ||
| 196 | switch (battery) { | ||
| 197 | case Response::Battery::Dying: | ||
| 198 | return BatteryLevel::Empty; | ||
| 199 | case Response::Battery::Low: | ||
| 200 | return BatteryLevel::Critical; | ||
| 201 | case Response::Battery::Medium: | ||
| 202 | return BatteryLevel::Low; | ||
| 203 | case Response::Battery::High: | ||
| 204 | return BatteryLevel::Medium; | ||
| 205 | case Response::Battery::Full: | ||
| 206 | case Response::Battery::Charged: | ||
| 207 | return BatteryLevel::Full; | ||
| 208 | case Response::Battery::Charging: | ||
| 209 | default: | ||
| 210 | return BatteryLevel::Charging; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 195 | void UDPClient::OnVersion([[maybe_unused]] Response::Version data) { | 214 | void UDPClient::OnVersion([[maybe_unused]] Response::Version data) { |
| 196 | LOG_TRACE(Input, "Version packet received: {}", data.version); | 215 | LOG_TRACE(Input, "Version packet received: {}", data.version); |
| 197 | } | 216 | } |
| @@ -299,6 +318,8 @@ void UDPClient::OnPadData(Response::PadData data, std::size_t client) { | |||
| 299 | const int button = static_cast<int>(buttons[i]); | 318 | const int button = static_cast<int>(buttons[i]); |
| 300 | SetButton(identifier, button, button_status); | 319 | SetButton(identifier, button, button_status); |
| 301 | } | 320 | } |
| 321 | |||
| 322 | SetBattery(identifier, GetBatteryLevel(data.info.battery)); | ||
| 302 | } | 323 | } |
| 303 | 324 | ||
| 304 | void UDPClient::StartCommunication(std::size_t client, const std::string& host, u16 port) { | 325 | void UDPClient::StartCommunication(std::size_t client, const std::string& host, u16 port) { |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index 1adc947c4..61a1fff37 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -15,6 +15,7 @@ namespace InputCommon::CemuhookUDP { | |||
| 15 | class Socket; | 15 | class Socket; |
| 16 | 16 | ||
| 17 | namespace Response { | 17 | namespace Response { |
| 18 | enum class Battery : u8; | ||
| 18 | struct PadData; | 19 | struct PadData; |
| 19 | struct PortInfo; | 20 | struct PortInfo; |
| 20 | struct TouchPad; | 21 | struct TouchPad; |
| @@ -137,6 +138,9 @@ private: | |||
| 137 | // Translates configuration to client number | 138 | // Translates configuration to client number |
| 138 | std::size_t GetClientNumber(std::string_view host, u16 port) const; | 139 | std::size_t GetClientNumber(std::string_view host, u16 port) const; |
| 139 | 140 | ||
| 141 | // Translates UDP battery level to input engine battery level | ||
| 142 | BatteryLevel GetBatteryLevel(Response::Battery battery) const; | ||
| 143 | |||
| 140 | void OnVersion(Response::Version); | 144 | void OnVersion(Response::Version); |
| 141 | void OnPortInfo(Response::PortInfo); | 145 | void OnPortInfo(Response::PortInfo); |
| 142 | void OnPadData(Response::PadData, std::size_t client); | 146 | void OnPadData(Response::PadData, std::size_t client); |