diff options
Diffstat (limited to 'src/input_common/udp/client.cpp')
| -rw-r--r-- | src/input_common/udp/client.cpp | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 9b0aec797..b9512aa2e 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -471,46 +471,42 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 471 | std::function<void(u16, u16, u16, u16)> data_callback) { | 471 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 472 | 472 | ||
| 473 | std::thread([=, this] { | 473 | std::thread([=, this] { |
| 474 | constexpr u16 CALIBRATION_THRESHOLD = 100; | ||
| 475 | |||
| 476 | u16 min_x{UINT16_MAX}; | ||
| 477 | u16 min_y{UINT16_MAX}; | ||
| 478 | u16 max_x{}; | ||
| 479 | u16 max_y{}; | ||
| 480 | |||
| 481 | Status current_status{Status::Initialized}; | 474 | Status current_status{Status::Initialized}; |
| 482 | SocketCallback callback{[](Response::Version) {}, [](Response::PortInfo) {}, | 475 | SocketCallback callback{ |
| 483 | [&](Response::PadData data) { | 476 | [](Response::Version) {}, [](Response::PortInfo) {}, |
| 484 | if (current_status == Status::Initialized) { | 477 | [&](Response::PadData data) { |
| 485 | // Receiving data means the communication is ready now | 478 | static constexpr u16 CALIBRATION_THRESHOLD = 100; |
| 486 | current_status = Status::Ready; | 479 | static constexpr u16 MAX_VALUE = UINT16_MAX; |
| 487 | status_callback(current_status); | 480 | |
| 488 | } | 481 | if (current_status == Status::Initialized) { |
| 489 | if (data.touch[0].is_active == 0) { | 482 | // Receiving data means the communication is ready now |
| 490 | return; | 483 | current_status = Status::Ready; |
| 491 | } | 484 | status_callback(current_status); |
| 492 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch[0].x, | 485 | } |
| 493 | data.touch[0].y); | 486 | const auto& touchpad_0 = data.touch[0]; |
| 494 | min_x = std::min(min_x, static_cast<u16>(data.touch[0].x)); | 487 | if (touchpad_0.is_active == 0) { |
| 495 | min_y = std::min(min_y, static_cast<u16>(data.touch[0].y)); | 488 | return; |
| 496 | if (current_status == Status::Ready) { | 489 | } |
| 497 | // First touch - min data (min_x/min_y) | 490 | LOG_DEBUG(Input, "Current touch: {} {}", touchpad_0.x, touchpad_0.y); |
| 498 | current_status = Status::Stage1Completed; | 491 | const u16 min_x = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.x)); |
| 499 | status_callback(current_status); | 492 | const u16 min_y = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.y)); |
| 500 | } | 493 | if (current_status == Status::Ready) { |
| 501 | if (data.touch[0].x - min_x > CALIBRATION_THRESHOLD && | 494 | // First touch - min data (min_x/min_y) |
| 502 | data.touch[0].y - min_y > CALIBRATION_THRESHOLD) { | 495 | current_status = Status::Stage1Completed; |
| 503 | // Set the current position as max value and finishes | 496 | status_callback(current_status); |
| 504 | // configuration | 497 | } |
| 505 | max_x = data.touch[0].x; | 498 | if (touchpad_0.x - min_x > CALIBRATION_THRESHOLD && |
| 506 | max_y = data.touch[0].y; | 499 | touchpad_0.y - min_y > CALIBRATION_THRESHOLD) { |
| 507 | current_status = Status::Completed; | 500 | // Set the current position as max value and finishes configuration |
| 508 | data_callback(min_x, min_y, max_x, max_y); | 501 | const u16 max_x = touchpad_0.x; |
| 509 | status_callback(current_status); | 502 | const u16 max_y = touchpad_0.y; |
| 510 | 503 | current_status = Status::Completed; | |
| 511 | complete_event.Set(); | 504 | data_callback(min_x, min_y, max_x, max_y); |
| 512 | } | 505 | status_callback(current_status); |
| 513 | }}; | 506 | |
| 507 | complete_event.Set(); | ||
| 508 | } | ||
| 509 | }}; | ||
| 514 | Socket socket{host, port, std::move(callback)}; | 510 | Socket socket{host, port, std::move(callback)}; |
| 515 | std::thread worker_thread{SocketLoop, &socket}; | 511 | std::thread worker_thread{SocketLoop, &socket}; |
| 516 | complete_event.Wait(); | 512 | complete_event.Wait(); |