feat: 完成minitouch的push

This commit is contained in:
MistEO
2022-11-07 01:10:04 +08:00
parent 2fbce68afb
commit 5fd85a4e9a
11 changed files with 69 additions and 10 deletions

View File

@@ -997,7 +997,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
}
auto& uuid_str = uuid_ret.value();
std::erase(uuid_str, ' ');
std::erase_if(uuid_str, [](char c) { return !std::isdigit(c) && !std::isalpha(c); });
m_uuid = std::move(uuid_str);
json::value info = get_info_json() | json::object {
@@ -1166,6 +1166,23 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
return false;
}
if (m_enable_minitouch) {
auto minitouch_cmd_rep = [&](const std::string& cfg_cmd) -> std::string {
return utils::string_replace_all(
cmd_replace(cfg_cmd),
{
// TODO: 用 adb shell getprop ro.product.cpu.abilist 来判断该用哪个文件夹里的
{ "[minitouchLocalPath]", (m_resource_path / "minitouch" / "armeabi-v7a" / "minitouch").string() },
{ "[minitouchWorkingFile]", m_uuid },
});
};
call_command(minitouch_cmd_rep(adb_cfg.push_minitouch));
call_command(minitouch_cmd_rep(adb_cfg.chmod_minitouch));
m_adb.call_minitouch = minitouch_cmd_rep(adb_cfg.push_minitouch);
}
// try to find the fastest way
if (!screencap()) {
Log.error("Cannot find a proper way to screencap!");

View File

@@ -12,6 +12,7 @@
#include <atomic>
#include <condition_variable>
#include <filesystem>
#include <memory>
#include <mutex>
#include <optional>
@@ -40,6 +41,7 @@ namespace asst
bool connect(const std::string& adb_path, const std::string& address, const std::string& config);
bool inited() const noexcept;
void set_exit_flag(bool* flag);
inline static void set_resource_path(const std::filesystem::path& path) { m_resource_path = path; }
const std::string& get_uuid() const;
cv::Mat get_image(bool raw = false);
@@ -133,6 +135,8 @@ namespace asst
std::string start;
std::string stop;
std::string call_minitouch;
/* properties */
enum class ScreencapEndOfLine
{
@@ -152,6 +156,10 @@ namespace asst
} screencap_method = ScreencapMethod::UnknownYet;
} m_adb;
bool m_enable_minitouch = true;
inline static std::filesystem::path m_resource_path;
std::string m_uuid;
inline static std::string m_adb_release; // 开了 adb daemon但是没连上模拟器的时候
// m_adb 并不会存下 release 的命令,但最后仍然需要一次释放。

View File

@@ -46,7 +46,9 @@ bool asst::GeneralConfiger::parse(const json::value& json)
adb.release = cfg_json.at("release").as_string();
adb.start = cfg_json.at("start").as_string();
adb.stop = cfg_json.at("stop").as_string();
// adb.pullscreen = cfg_json.at("pullscreen").as_string();
adb.push_minitouch = cfg_json.at("pushMinitouch").as_string();
adb.chmod_minitouch = cfg_json.at("chmodMinitouch").as_string();
adb.call_minitouch = cfg_json.at("callMinitouch").as_string();
m_adb_cfg[name] = std::move(adb);
}

View File

@@ -68,6 +68,9 @@ namespace asst
std::string release;
std::string start;
std::string stop;
std::string push_minitouch;
std::string chmod_minitouch;
std::string call_minitouch;
};
class GeneralConfiger final : public SingletonHolder<GeneralConfiger>, public AbstractConfiger

View File

@@ -4,6 +4,7 @@
#include "Utils/Logger.hpp"
#include "Controller.h"
#include "Resource/BattleDataConfiger.h"
#include "Resource/CopilotConfiger.h"
#include "Resource/GeneralConfiger.h"
@@ -67,6 +68,10 @@ bool asst::ResourceLoader::load(const std::filesystem::path& path)
LoadResourceAndCheckRet(WordOcr, "PaddleOCR"_p);
LoadResourceAndCheckRet(CharOcr, "PaddleCharOCR"_p);
if (!m_loaded) {
Controller::set_resource_path(path);
}
m_loaded = true;
#undef LoadTemplByConfigerAndCheckRet