diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/thread.h | 2 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 14 | ||||
| -rw-r--r-- | src/input_common/udp/client.h | 4 | ||||
| -rw-r--r-- | src/input_common/udp/protocol.cpp | 12 |
4 files changed, 18 insertions, 14 deletions
diff --git a/src/common/thread.h b/src/common/thread.h index 5584c3bf3..2fc071685 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -30,7 +30,7 @@ public: | |||
| 30 | 30 | ||
| 31 | template <class Duration> | 31 | template <class Duration> |
| 32 | bool WaitFor(const std::chrono::duration<Duration>& time) { | 32 | bool WaitFor(const std::chrono::duration<Duration>& time) { |
| 33 | std::unique_lock<std::mutex> lk(mutex); | 33 | std::unique_lock lk{mutex}; |
| 34 | if (!condvar.wait_for(lk, time, [this] { return is_set; })) | 34 | if (!condvar.wait_for(lk, time, [this] { return is_set; })) |
| 35 | return false; | 35 | return false; |
| 36 | is_set = false; | 36 | is_set = false; |
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 3c51f72a0..5f5a9989c 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -212,10 +212,11 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie | |||
| 212 | bool result = success_event.WaitFor(std::chrono::seconds(8)); | 212 | bool result = success_event.WaitFor(std::chrono::seconds(8)); |
| 213 | socket.Stop(); | 213 | socket.Stop(); |
| 214 | worker_thread.join(); | 214 | worker_thread.join(); |
| 215 | if (result) | 215 | if (result) { |
| 216 | success_callback(); | 216 | success_callback(); |
| 217 | else | 217 | } else { |
| 218 | failure_callback(); | 218 | failure_callback(); |
| 219 | } | ||
| 219 | }) | 220 | }) |
| 220 | .detach(); | 221 | .detach(); |
| 221 | } | 222 | } |
| @@ -228,8 +229,10 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 228 | std::thread([=] { | 229 | std::thread([=] { |
| 229 | constexpr u16 CALIBRATION_THRESHOLD = 100; | 230 | constexpr u16 CALIBRATION_THRESHOLD = 100; |
| 230 | 231 | ||
| 231 | u16 min_x{UINT16_MAX}, min_y{UINT16_MAX}; | 232 | u16 min_x{UINT16_MAX}; |
| 232 | u16 max_x{}, max_y{}; | 233 | u16 min_y{UINT16_MAX}; |
| 234 | u16 max_x{}; | ||
| 235 | u16 max_y{}; | ||
| 233 | 236 | ||
| 234 | Status current_status{Status::Initialized}; | 237 | Status current_status{Status::Initialized}; |
| 235 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 238 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, |
| @@ -239,8 +242,9 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 239 | current_status = Status::Ready; | 242 | current_status = Status::Ready; |
| 240 | status_callback(current_status); | 243 | status_callback(current_status); |
| 241 | } | 244 | } |
| 242 | if (!data.touch_1.is_active) | 245 | if (!data.touch_1.is_active) { |
| 243 | return; | 246 | return; |
| 247 | } | ||
| 244 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, | 248 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, |
| 245 | data.touch_1.y); | 249 | data.touch_1.y); |
| 246 | min_x = std::min(min_x, static_cast<u16>(data.touch_1.x)); | 250 | min_x = std::min(min_x, static_cast<u16>(data.touch_1.x)); |
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index b06a3f85a..0b21f4da6 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -18,8 +18,8 @@ | |||
| 18 | 18 | ||
| 19 | namespace InputCommon::CemuhookUDP { | 19 | namespace InputCommon::CemuhookUDP { |
| 20 | 20 | ||
| 21 | static constexpr u16 DEFAULT_PORT = 26760; | 21 | constexpr u16 DEFAULT_PORT = 26760; |
| 22 | static constexpr const char* DEFAULT_ADDR = "127.0.0.1"; | 22 | constexpr char DEFAULT_ADDR[] = "127.0.0.1"; |
| 23 | 23 | ||
| 24 | class Socket; | 24 | class Socket; |
| 25 | 25 | ||
diff --git a/src/input_common/udp/protocol.cpp b/src/input_common/udp/protocol.cpp index 16da706d5..a982ac49d 100644 --- a/src/input_common/udp/protocol.cpp +++ b/src/input_common/udp/protocol.cpp | |||
| @@ -32,21 +32,21 @@ namespace Response { | |||
| 32 | std::optional<Type> Validate(u8* data, std::size_t size) { | 32 | std::optional<Type> Validate(u8* data, std::size_t size) { |
| 33 | if (size < sizeof(Header)) { | 33 | if (size < sizeof(Header)) { |
| 34 | LOG_DEBUG(Input, "Invalid UDP packet received"); | 34 | LOG_DEBUG(Input, "Invalid UDP packet received"); |
| 35 | return {}; | 35 | return std::nullopt; |
| 36 | } | 36 | } |
| 37 | Header header{}; | 37 | Header header{}; |
| 38 | std::memcpy(&header, data, sizeof(Header)); | 38 | std::memcpy(&header, data, sizeof(Header)); |
| 39 | if (header.magic != SERVER_MAGIC) { | 39 | if (header.magic != SERVER_MAGIC) { |
| 40 | LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); | 40 | LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); |
| 41 | return {}; | 41 | return std::nullopt; |
| 42 | } | 42 | } |
| 43 | if (header.protocol_version != PROTOCOL_VERSION) { | 43 | if (header.protocol_version != PROTOCOL_VERSION) { |
| 44 | LOG_ERROR(Input, "UDP Packet protocol mismatch"); | 44 | LOG_ERROR(Input, "UDP Packet protocol mismatch"); |
| 45 | return {}; | 45 | return std::nullopt; |
| 46 | } | 46 | } |
| 47 | if (header.type < Type::Version || header.type > Type::PadData) { | 47 | if (header.type < Type::Version || header.type > Type::PadData) { |
| 48 | LOG_ERROR(Input, "UDP Packet is an unknown type"); | 48 | LOG_ERROR(Input, "UDP Packet is an unknown type"); |
| 49 | return {}; | 49 | return std::nullopt; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | // Packet size must equal sizeof(Header) + sizeof(Data) | 52 | // Packet size must equal sizeof(Header) + sizeof(Data) |
| @@ -59,7 +59,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) { | |||
| 59 | Input, | 59 | Input, |
| 60 | "UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", | 60 | "UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", |
| 61 | size, header.payload_length, data_len + sizeof(Type)); | 61 | size, header.payload_length, data_len + sizeof(Type)); |
| 62 | return {}; | 62 | return std::nullopt; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | const u32 crc32 = header.crc; | 65 | const u32 crc32 = header.crc; |
| @@ -70,7 +70,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) { | |||
| 70 | result.process_bytes(data, data_len + sizeof(Header)); | 70 | result.process_bytes(data, data_len + sizeof(Header)); |
| 71 | if (crc32 != result.checksum()) { | 71 | if (crc32 != result.checksum()) { |
| 72 | LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); | 72 | LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); |
| 73 | return {}; | 73 | return std::nullopt; |
| 74 | } | 74 | } |
| 75 | return header.type; | 75 | return header.type; |
| 76 | } | 76 | } |