summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/udp_client.cpp
diff options
context:
space:
mode:
authorGravatar vperus2021-11-29 16:35:54 +0200
committerGravatar vperus2021-11-29 16:37:11 +0200
commit660c6bec22973ad3d4d5d53011c3d87f1f77e1df (patch)
tree1acdfaa909b86cf0df839693a0e75931e39f306c /src/input_common/drivers/udp_client.cpp
parent[input_common] Add completion test for CalibrationConfigurationJob (diff)
downloadyuzu-660c6bec22973ad3d4d5d53011c3d87f1f77e1df.tar.gz
yuzu-660c6bec22973ad3d4d5d53011c3d87f1f77e1df.tar.xz
yuzu-660c6bec22973ad3d4d5d53011c3d87f1f77e1df.zip
Revert of b01aa72
Caused worker_thread to be stuck in Stage1Completed state until job's destruction.
Diffstat (limited to 'src/input_common/drivers/udp_client.cpp')
-rw-r--r--src/input_common/drivers/udp_client.cpp74
1 files changed, 39 insertions, 35 deletions
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
index fdee0f2d5..730e8b2f3 100644
--- a/src/input_common/drivers/udp_client.cpp
+++ b/src/input_common/drivers/udp_client.cpp
@@ -536,42 +536,46 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
536 std::function<void(u16, u16, u16, u16)> data_callback) { 536 std::function<void(u16, u16, u16, u16)> data_callback) {
537 537
538 std::thread([=, this] { 538 std::thread([=, this] {
539 constexpr u16 CALIBRATION_THRESHOLD = 100;
540
541 u16 min_x{UINT16_MAX};
542 u16 min_y{UINT16_MAX};
543 u16 max_x{};
544 u16 max_y{};
545
539 Status current_status{Status::Initialized}; 546 Status current_status{Status::Initialized};
540 SocketCallback callback{ 547 SocketCallback callback{[](Response::Version) {}, [](Response::PortInfo) {},
541 [](Response::Version) {}, [](Response::PortInfo) {}, 548 [&](Response::PadData data) {
542 [&](Response::PadData data) { 549 if (current_status == Status::Initialized) {
543 static constexpr u16 CALIBRATION_THRESHOLD = 100; 550 // Receiving data means the communication is ready now
544 static constexpr u16 MAX_VALUE = UINT16_MAX; 551 current_status = Status::Ready;
545 552 status_callback(current_status);
546 if (current_status == Status::Initialized) { 553 }
547 // Receiving data means the communication is ready now 554 if (data.touch[0].is_active == 0) {
548 current_status = Status::Ready; 555 return;
549 status_callback(current_status); 556 }
550 } 557 LOG_DEBUG(Input, "Current touch: {} {}", data.touch[0].x,
551 const auto& touchpad_0 = data.touch[0]; 558 data.touch[0].y);
552 if (touchpad_0.is_active == 0) { 559 min_x = std::min(min_x, static_cast<u16>(data.touch[0].x));
553 return; 560 min_y = std::min(min_y, static_cast<u16>(data.touch[0].y));
554 } 561 if (current_status == Status::Ready) {
555 LOG_DEBUG(Input, "Current touch: {} {}", touchpad_0.x, touchpad_0.y); 562 // First touch - min data (min_x/min_y)
556 const u16 min_x = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.x)); 563 current_status = Status::Stage1Completed;
557 const u16 min_y = std::min(MAX_VALUE, static_cast<u16>(touchpad_0.y)); 564 status_callback(current_status);
558 if (current_status == Status::Ready) { 565 }
559 // First touch - min data (min_x/min_y) 566 if (data.touch[0].x - min_x > CALIBRATION_THRESHOLD &&
560 current_status = Status::Stage1Completed; 567 data.touch[0].y - min_y > CALIBRATION_THRESHOLD) {
561 status_callback(current_status); 568 // Set the current position as max value and finishes
562 } 569 // configuration
563 if (touchpad_0.x - min_x > CALIBRATION_THRESHOLD && 570 max_x = data.touch[0].x;
564 touchpad_0.y - min_y > CALIBRATION_THRESHOLD) { 571 max_y = data.touch[0].y;
565 // Set the current position as max value and finishes configuration 572 current_status = Status::Completed;
566 const u16 max_x = touchpad_0.x; 573 data_callback(min_x, min_y, max_x, max_y);
567 const u16 max_y = touchpad_0.y; 574 status_callback(current_status);
568 current_status = Status::Completed; 575
569 data_callback(min_x, min_y, max_x, max_y); 576 complete_event.Set();
570 status_callback(current_status); 577 }
571 578 }};
572 complete_event.Set();
573 }
574 }};
575 Socket socket{host, port, std::move(callback)}; 579 Socket socket{host, port, std::move(callback)};
576 std::thread worker_thread{SocketLoop, &socket}; 580 std::thread worker_thread{SocketLoop, &socket};
577 complete_event.Wait(); 581 complete_event.Wait();