From eb6157eec15a434ed1fb7f061d4315455a1f7eae Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Fri, 21 Jan 2022 04:04:34 +0100 Subject: [PATCH] early-access version 2422 --- README.md | 2 +- src/common/bit_util.h | 6 ++++++ src/input_common/drivers/udp_client.cpp | 21 +++++++++++++++++++++ src/input_common/drivers/udp_client.h | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14360ad7c..76e4ca15f 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2420. +This is the source code for early-access 2422. ## Legal Notice diff --git a/src/common/bit_util.h b/src/common/bit_util.h index eef8c1c5a..f50d3308a 100755 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -45,6 +45,12 @@ template return static_cast(log2_f + static_cast((value ^ (1ULL << log2_f)) != 0ULL)); } +template +requires std::is_unsigned_v +[[nodiscard]] constexpr bool IsPow2(T value) { + return std::has_single_bit(value); +} + template requires std::is_integral_v [[nodiscard]] T NextPow2(T value) { diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index c8a12c7d5..9aaeb91be 100755 --- 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 { return MAX_UDP_CLIENTS; } +BatteryLevel UDPClient::GetBatteryLevel(Response::Battery battery) const { + switch (battery) { + case Response::Battery::Dying: + return BatteryLevel::Empty; + case Response::Battery::Low: + return BatteryLevel::Critical; + case Response::Battery::Medium: + return BatteryLevel::Low; + case Response::Battery::High: + return BatteryLevel::Medium; + case Response::Battery::Full: + case Response::Battery::Charged: + return BatteryLevel::Full; + case Response::Battery::Charging: + default: + return BatteryLevel::Charging; + } +} + void UDPClient::OnVersion([[maybe_unused]] Response::Version data) { LOG_TRACE(Input, "Version packet received: {}", data.version); } @@ -299,6 +318,8 @@ void UDPClient::OnPadData(Response::PadData data, std::size_t client) { const int button = static_cast(buttons[i]); SetButton(identifier, button, button_status); } + + SetBattery(identifier, GetBatteryLevel(data.info.battery)); } 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 100755 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h @@ -15,6 +15,7 @@ namespace InputCommon::CemuhookUDP { class Socket; namespace Response { +enum class Battery : u8; struct PadData; struct PortInfo; struct TouchPad; @@ -137,6 +138,9 @@ private: // Translates configuration to client number std::size_t GetClientNumber(std::string_view host, u16 port) const; + // Translates UDP battery level to input engine battery level + BatteryLevel GetBatteryLevel(Response::Battery battery) const; + void OnVersion(Response::Version); void OnPortInfo(Response::PortInfo); void OnPadData(Response::PadData, std::size_t client);