From cd38cec87f53e7e2f7957876863bcad1d013e693 Mon Sep 17 00:00:00 2001 From: shxyke Date: Tue, 28 Mar 2023 06:39:59 +0000 Subject: [PATCH] Revert removal of timeout in call_and_hup_minitouch --- .../Controller/MinitouchController.cpp | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/MaaCore/Controller/MinitouchController.cpp b/src/MaaCore/Controller/MinitouchController.cpp index 0840f8e257..4f4d69bec5 100644 --- a/src/MaaCore/Controller/MinitouchController.cpp +++ b/src/MaaCore/Controller/MinitouchController.cpp @@ -36,16 +36,29 @@ bool asst::MinitouchController::call_and_hup_minitouch() return false; } - if (need_exit()) { - release_minitouch(true); - return false; - } + auto check_timeout = [&](const auto& start_time) -> bool { + using namespace std::chrono_literals; + return std::chrono::steady_clock::now() - start_time < 3s; + }; - pipe_str = m_minitouch_handler->read(3); + const auto start_time = std::chrono::steady_clock::now(); + while (true) { + if (need_exit()) { + release_minitouch(true); + return false; + } - if (pipe_str.find('$') == std::string::npos) { - release_minitouch(true); - return false; + pipe_str += m_minitouch_handler->read(3); + + if (!check_timeout(start_time)) { + Log.info("unable to find $ from pipe_str:", Logger::separator::newline, pipe_str); + release_minitouch(true); + return false; + } + + if (pipe_str.find('$') != std::string::npos) { + break; + } } Log.info("pipe str", Logger::separator::newline, pipe_str);