diff options
| author | 2020-06-21 12:36:28 -0400 | |
|---|---|---|
| committer | 2020-06-21 12:36:28 -0400 | |
| commit | 0248614add99c1df1bc7c9ff97091f678ff75aca (patch) | |
| tree | e7a4a8e629039f940b4bef76e69d51ddbf2a0639 /src/input_common/udp/client.cpp | |
| parent | Merge pull request #4120 from lioncash/arb (diff) | |
| download | yuzu-0248614add99c1df1bc7c9ff97091f678ff75aca.tar.gz yuzu-0248614add99c1df1bc7c9ff97091f678ff75aca.tar.xz yuzu-0248614add99c1df1bc7c9ff97091f678ff75aca.zip | |
GC Adapter Implementation
Diffstat (limited to 'src/input_common/udp/client.cpp')
| -rw-r--r-- | src/input_common/udp/client.cpp | 140 |
1 files changed, 77 insertions, 63 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..befa4c86d 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -59,7 +59,8 @@ public: | |||
| 59 | void StartReceive() { | 59 | void StartReceive() { |
| 60 | socket.async_receive_from( | 60 | socket.async_receive_from( |
| 61 | boost::asio::buffer(receive_buffer), receive_endpoint, | 61 | boost::asio::buffer(receive_buffer), receive_endpoint, |
| 62 | [this](const boost::system::error_code& error, std::size_t bytes_transferred) { | 62 | [this](const boost::system::error_code& error, std::size_t bytes_transferred) |
| 63 | { | ||
| 63 | HandleReceive(error, bytes_transferred); | 64 | HandleReceive(error, bytes_transferred); |
| 64 | }); | 65 | }); |
| 65 | } | 66 | } |
| @@ -211,21 +212,27 @@ void Client::StartCommunication(const std::string& host, u16 port, u8 pad_index, | |||
| 211 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 212 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, |
| 212 | std::function<void()> success_callback, | 213 | std::function<void()> success_callback, |
| 213 | std::function<void()> failure_callback) { | 214 | std::function<void()> failure_callback) { |
| 214 | std::thread([=] { | 215 | std::thread([=] |
| 215 | Common::Event success_event; | 216 | { |
| 216 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 217 | Common::Event success_event; |
| 217 | [&](Response::PadData data) { success_event.Set(); }}; | 218 | SocketCallback callback{[](Response::Version version) |
| 218 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 219 | { |
| 219 | std::thread worker_thread{SocketLoop, &socket}; | 220 | }, |
| 220 | bool result = success_event.WaitFor(std::chrono::seconds(8)); | 221 | [](Response::PortInfo info) |
| 221 | socket.Stop(); | 222 | { |
| 222 | worker_thread.join(); | 223 | }, |
| 223 | if (result) { | 224 | [&](Response::PadData data) { success_event.Set(); }}; |
| 224 | success_callback(); | 225 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; |
| 225 | } else { | 226 | std::thread worker_thread{SocketLoop, &socket}; |
| 226 | failure_callback(); | 227 | bool result = success_event.WaitFor(std::chrono::seconds(8)); |
| 227 | } | 228 | socket.Stop(); |
| 228 | }) | 229 | worker_thread.join(); |
| 230 | if (result) { | ||
| 231 | success_callback(); | ||
| 232 | } else { | ||
| 233 | failure_callback(); | ||
| 234 | } | ||
| 235 | }) | ||
| 229 | .detach(); | 236 | .detach(); |
| 230 | } | 237 | } |
| 231 | 238 | ||
| @@ -234,53 +241,60 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 234 | std::function<void(Status)> status_callback, | 241 | std::function<void(Status)> status_callback, |
| 235 | std::function<void(u16, u16, u16, u16)> data_callback) { | 242 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 236 | 243 | ||
| 237 | std::thread([=] { | 244 | std::thread([=] |
| 238 | constexpr u16 CALIBRATION_THRESHOLD = 100; | 245 | { |
| 239 | 246 | constexpr u16 CALIBRATION_THRESHOLD = 100; | |
| 240 | u16 min_x{UINT16_MAX}; | 247 | |
| 241 | u16 min_y{UINT16_MAX}; | 248 | u16 min_x{UINT16_MAX}; |
| 242 | u16 max_x{}; | 249 | u16 min_y{UINT16_MAX}; |
| 243 | u16 max_y{}; | 250 | u16 max_x{}; |
| 244 | 251 | u16 max_y{}; | |
| 245 | Status current_status{Status::Initialized}; | 252 | |
| 246 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 253 | Status current_status{Status::Initialized}; |
| 247 | [&](Response::PadData data) { | 254 | SocketCallback callback{[](Response::Version version) |
| 248 | if (current_status == Status::Initialized) { | 255 | { |
| 249 | // Receiving data means the communication is ready now | 256 | }, |
| 250 | current_status = Status::Ready; | 257 | [](Response::PortInfo info) |
| 251 | status_callback(current_status); | 258 | { |
| 252 | } | 259 | }, |
| 253 | if (!data.touch_1.is_active) { | 260 | [&](Response::PadData data) |
| 254 | return; | 261 | { |
| 255 | } | 262 | if (current_status == Status::Initialized) { |
| 256 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, | 263 | // Receiving data means the communication is ready now |
| 257 | data.touch_1.y); | 264 | current_status = Status::Ready; |
| 258 | min_x = std::min(min_x, static_cast<u16>(data.touch_1.x)); | 265 | status_callback(current_status); |
| 259 | min_y = std::min(min_y, static_cast<u16>(data.touch_1.y)); | 266 | } |
| 260 | if (current_status == Status::Ready) { | 267 | if (!data.touch_1.is_active) { |
| 261 | // First touch - min data (min_x/min_y) | 268 | return; |
| 262 | current_status = Status::Stage1Completed; | 269 | } |
| 263 | status_callback(current_status); | 270 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, |
| 264 | } | 271 | data.touch_1.y); |
| 265 | if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD && | 272 | min_x = std::min(min_x, static_cast<u16>(data.touch_1.x)); |
| 266 | data.touch_1.y - min_y > CALIBRATION_THRESHOLD) { | 273 | min_y = std::min(min_y, static_cast<u16>(data.touch_1.y)); |
| 267 | // Set the current position as max value and finishes | 274 | if (current_status == Status::Ready) { |
| 268 | // configuration | 275 | // First touch - min data (min_x/min_y) |
| 269 | max_x = data.touch_1.x; | 276 | current_status = Status::Stage1Completed; |
| 270 | max_y = data.touch_1.y; | 277 | status_callback(current_status); |
| 271 | current_status = Status::Completed; | 278 | } |
| 272 | data_callback(min_x, min_y, max_x, max_y); | 279 | if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD && |
| 273 | status_callback(current_status); | 280 | data.touch_1.y - min_y > CALIBRATION_THRESHOLD) { |
| 274 | 281 | // Set the current position as max value and finishes | |
| 275 | complete_event.Set(); | 282 | // configuration |
| 276 | } | 283 | max_x = data.touch_1.x; |
| 277 | }}; | 284 | max_y = data.touch_1.y; |
| 278 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 285 | current_status = Status::Completed; |
| 279 | std::thread worker_thread{SocketLoop, &socket}; | 286 | data_callback(min_x, min_y, max_x, max_y); |
| 280 | complete_event.Wait(); | 287 | status_callback(current_status); |
| 281 | socket.Stop(); | 288 | |
| 282 | worker_thread.join(); | 289 | complete_event.Set(); |
| 283 | }) | 290 | } |
| 291 | }}; | ||
| 292 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | ||
| 293 | std::thread worker_thread{SocketLoop, &socket}; | ||
| 294 | complete_event.Wait(); | ||
| 295 | socket.Stop(); | ||
| 296 | worker_thread.join(); | ||
| 297 | }) | ||
| 284 | .detach(); | 298 | .detach(); |
| 285 | } | 299 | } |
| 286 | 300 | ||