From 0896a74d5542e7ba3fa0d497636e651da4a08ef9 Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 23 Oct 2023 01:26:21 +0800 Subject: [PATCH] feat: debugging controller --- MAA.sln | 8 +- include/MaaFramework/MaaDef.h | 18 ++ sample/cpp/main.cpp | 2 +- source/CMakeLists.txt | 1 + .../MaaAdbControlUnit.vcxproj | 2 +- source/MaaDebuggingControlUnit/CMakeLists.txt | 20 +++ .../ControlUnitMgr.cpp | 44 +++++ .../MaaDebuggingControlUnit/ControlUnitMgr.h | 25 +++ .../Directory.Build.props | 6 + .../Directory.Build.targets | 14 ++ .../General/VirtualInfo.cpp | 25 +++ .../General/VirtualInfo.h | 31 ++++ .../MaaDebuggingControlUnit.vcxproj | 170 ++++++++++++++++++ .../Screencap/ReadIndex.cpp | 75 ++++++++ .../Screencap/ReadIndex.h | 29 +++ source/MaaFramework/CMakeLists.txt | 4 +- .../Controller/DebuggingController.cpp | 111 ++++++++++++ .../Controller/DebuggingController.h | 40 +++++ source/MaaFramework/MaaFramework.vcxproj | 8 +- source/include/Conf/Conf.h | 6 + .../ControlUnit/DebuggingControlUnitAPI.h | 62 +++++++ 21 files changed, 692 insertions(+), 9 deletions(-) create mode 100644 source/MaaDebuggingControlUnit/CMakeLists.txt create mode 100644 source/MaaDebuggingControlUnit/ControlUnitMgr.cpp create mode 100644 source/MaaDebuggingControlUnit/ControlUnitMgr.h create mode 100644 source/MaaDebuggingControlUnit/Directory.Build.props create mode 100644 source/MaaDebuggingControlUnit/Directory.Build.targets create mode 100644 source/MaaDebuggingControlUnit/General/VirtualInfo.cpp create mode 100644 source/MaaDebuggingControlUnit/General/VirtualInfo.h create mode 100644 source/MaaDebuggingControlUnit/MaaDebuggingControlUnit.vcxproj create mode 100644 source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp create mode 100644 source/MaaDebuggingControlUnit/Screencap/ReadIndex.h create mode 100644 source/MaaFramework/Controller/DebuggingController.cpp create mode 100644 source/MaaFramework/Controller/DebuggingController.h create mode 100644 source/include/ControlUnit/DebuggingControlUnitAPI.h diff --git a/MAA.sln b/MAA.sln index d83d02e7c..628ad5f89 100644 --- a/MAA.sln +++ b/MAA.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.6.33723.286 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33927.289 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{11F02235-5785-408B-9651-8A4B41FF36F4}" ProjectSection(SolutionItems) = preProject @@ -17,6 +17,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaFramework", "source\MaaF ProjectSection(ProjectDependencies) = postProject {27862F0F-109D-40C8-B48B-9461D15222E3} = {27862F0F-109D-40C8-B48B-9461D15222E3} {DD48546D-48D4-4C84-BAC4-6126D0B5BFB3} = {DD48546D-48D4-4C84-BAC4-6126D0B5BFB3} + {E750209E-FE9B-4897-875A-61BFA73F51F3} = {E750209E-FE9B-4897-875A-61BFA73F51F3} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaAdbControlUnit", "source\MaaAdbControlUnit\MaaAdbControlUnit.vcxproj", "{DD48546D-48D4-4C84-BAC4-6126D0B5BFB3}" @@ -34,6 +35,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaToolKit", "source\MaaToo EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MaaDebuggingControlUnit", "source\MaaDebuggingControlUnit\MaaDebuggingControlUnit.vcxproj", "{E750209E-FE9B-4897-875A-61BFA73F51F3}" + ProjectSection(ProjectDependencies) = postProject + {27862F0F-109D-40C8-B48B-9461D15222E3} = {27862F0F-109D-40C8-B48B-9461D15222E3} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/include/MaaFramework/MaaDef.h b/include/MaaFramework/MaaDef.h index 397185486..79855ee2d 100644 --- a/include/MaaFramework/MaaDef.h +++ b/include/MaaFramework/MaaDef.h @@ -119,6 +119,24 @@ enum MaaAdbControllerTypeEnum MaaAdbControllerType_Screencap_Mask = 0xFF0000, }; +typedef int32_t MaaDebuggingControllerType; +enum MaaDebuggingControllerTypeEnum +{ + MaaDebuggingController_Invalid = 0, + + MaaDebuggingControllerType_Touch_Ignore = 1, + MaaDebuggingControllerType_Touch_Mask = 0xFF, + + MaaDebuggingControllerType_Key_Ignore = 1 << 8, + MaaDebuggingControllerType_Key_Mask = 0xFF00, + + MaaDebuggingControllerType_Input_Preset_Ignore = + MaaDebuggingControllerType_Touch_Ignore | MaaDebuggingControllerType_Key_Ignore, + + MaaDebuggingControllerType_Screencap_ReadIndex = 1 << 16, + MaaDebuggingControllerType_Screencap_Mask = 0xFF0000, +}; + typedef void* MaaTransparentArg; typedef MaaTransparentArg MaaCallbackTransparentArg; diff --git a/sample/cpp/main.cpp b/sample/cpp/main.cpp index 434d67ac6..5cf63a6d6 100644 --- a/sample/cpp/main.cpp +++ b/sample/cpp/main.cpp @@ -60,7 +60,7 @@ int main([[maybe_unused]] int argc, char** argv) register_my_recognizer(maa_handle); - auto task_id = MaaPostTask(maa_handle, "StartUpAndClickButton", MaaTaskParam_Empty); + auto task_id = MaaPostTask(maa_handle, "Psychube", MaaTaskParam_Empty); MaaWaitTask(maa_handle, task_id); destroy(); diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 8738c1871..9d13b0cfb 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(MaaUtils) add_subdirectory(MaaAdbControlUnit) +add_subdirectory(MaaDebuggingControlUnit) if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) add_subdirectory(MaaThriftController) endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) diff --git a/source/MaaAdbControlUnit/MaaAdbControlUnit.vcxproj b/source/MaaAdbControlUnit/MaaAdbControlUnit.vcxproj index 6c502fdc8..e7feed3c3 100644 --- a/source/MaaAdbControlUnit/MaaAdbControlUnit.vcxproj +++ b/source/MaaAdbControlUnit/MaaAdbControlUnit.vcxproj @@ -15,7 +15,7 @@ - + diff --git a/source/MaaDebuggingControlUnit/CMakeLists.txt b/source/MaaDebuggingControlUnit/CMakeLists.txt new file mode 100644 index 000000000..3143557ea --- /dev/null +++ b/source/MaaDebuggingControlUnit/CMakeLists.txt @@ -0,0 +1,20 @@ +file(GLOB_RECURSE maa_debugging_control_unit_src *.h *.hpp *.cpp ../include) + +add_library(MaaDebuggingControlUnit SHARED ${maa_debugging_control_unit_src}) + +target_include_directories(MaaDebuggingControlUnit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR}/../../include) + +target_link_libraries(MaaDebuggingControlUnit MaaUtils HeaderOnlyLibraries ${OpenCV_LIBS}) + +target_compile_definitions(MaaDebuggingControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) + +add_dependencies(MaaDebuggingControlUnit MaaUtils) + +install( + TARGETS MaaDebuggingControlUnit + RUNTIME DESTINATION bin + LIBRARY DESTINATION bin + ARCHIVE DESTINATION lib) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_debugging_control_unit_src}) diff --git a/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp b/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp new file mode 100644 index 000000000..1d823933c --- /dev/null +++ b/source/MaaDebuggingControlUnit/ControlUnitMgr.cpp @@ -0,0 +1,44 @@ +#include "ControlUnitMgr.h" + +#include + +#include "General/VirtualInfo.h" +#include "Screencap/ReadIndex.h" +#include "Utils/Logger.h" + +#pragma message("MaaControlUnit MAA_VERSION: " MAA_VERSION) + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +std::shared_ptr create_controller_unit(MaaStringView read_path, MaaStringView wirte_path, + MaaDebuggingControllerType type, MaaStringView config) +{ + LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type); + + auto filepath = MAA_NS::path(read_path); + std::ignore = wirte_path; + + std::shared_ptr screencap_unit = nullptr; + auto screencap_type = type & MaaDebuggingControllerType_Screencap_Mask; + + switch (screencap_type) { + case MaaDebuggingControllerType_Screencap_ReadIndex: + screencap_unit = std::make_shared(filepath); + break; + } + + auto device_info_unit = std::make_shared(filepath); + bool parsed = device_info_unit->parse(config); + if (!parsed) { + LogError << "failed to parse config" << VAR(config); + return nullptr; + } + + auto unit_mgr = std::make_shared(); + unit_mgr->set_screencap_obj(std::move(screencap_unit)); + unit_mgr->set_device_info_obj(std::move(device_info_unit)); + + return unit_mgr; +} + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaDebuggingControlUnit/ControlUnitMgr.h b/source/MaaDebuggingControlUnit/ControlUnitMgr.h new file mode 100644 index 000000000..96b22630b --- /dev/null +++ b/source/MaaDebuggingControlUnit/ControlUnitMgr.h @@ -0,0 +1,25 @@ +#pragma once + +#include "ControlUnit/DebuggingControlUnitAPI.h" + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +class ControlUnitMgr : public ControlUnitAPI +{ +public: + virtual ~ControlUnitMgr() override = default; + +public: // from ControlUnitAPI + virtual std::shared_ptr device_info_obj() override { return device_info_; } + virtual std::shared_ptr screencap_obj() override { return screencap_; } + +public: + void set_device_info_obj(std::shared_ptr obj) { device_info_ = std::move(obj); } + void set_screencap_obj(std::shared_ptr obj) { screencap_ = std::move(obj); } + +private: + std::shared_ptr device_info_ = nullptr; + std::shared_ptr screencap_ = nullptr; +}; + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaDebuggingControlUnit/Directory.Build.props b/source/MaaDebuggingControlUnit/Directory.Build.props new file mode 100644 index 000000000..e83e25b35 --- /dev/null +++ b/source/MaaDebuggingControlUnit/Directory.Build.props @@ -0,0 +1,6 @@ + + + $(MSBuildThisFileDirectory)..\..\MaaDeps\msbuild\maadeps.props + + + diff --git a/source/MaaDebuggingControlUnit/Directory.Build.targets b/source/MaaDebuggingControlUnit/Directory.Build.targets new file mode 100644 index 000000000..9d5887d0c --- /dev/null +++ b/source/MaaDebuggingControlUnit/Directory.Build.targets @@ -0,0 +1,14 @@ + + + $(MSBuildThisFileDirectory)..\..\MaaDeps\msbuild\maadeps.targets + $(MSBuildThisFileDirectory)..\..\MSBUILD_DISABLE_MAADEPS + true + true + Missing third-party dependencies, run `python maadeps-download.py`. / 缺少第三方依赖,请运行 `python maadeps-download.py`。 +Alternatively, run `python maadeps-build.py` to build third-party dependencies from source, or create a file named `MSBUILD_DISABLE_MAADEPS` next to MAA.sln file and bring your own libraries to MSBuild. + + + + + + diff --git a/source/MaaDebuggingControlUnit/General/VirtualInfo.cpp b/source/MaaDebuggingControlUnit/General/VirtualInfo.cpp new file mode 100644 index 000000000..63f6c1b62 --- /dev/null +++ b/source/MaaDebuggingControlUnit/General/VirtualInfo.cpp @@ -0,0 +1,25 @@ +#include "ControlUnitMgr.h" + +#include "Utils/ImageIo.h" +#include "Utils/Logger.h" +#include "VirtualInfo.h" + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +bool VirtualInfo::parse(const json::value& config) +{ + auto device_info = config.find("device_info"); + if (!device_info) { + LogError << "device_info not found" << VAR(config); + return false; + } + + uuid_ = device_info->get("uuid", path_to_utf8_string(path_)); + resolution_.width = device_info->get("screen_width", 0); + resolution_.height = device_info->get("screen_height", 0); + orientation_ = device_info->get("orientation", 0); + + return true; +} + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaDebuggingControlUnit/General/VirtualInfo.h b/source/MaaDebuggingControlUnit/General/VirtualInfo.h new file mode 100644 index 000000000..8bd0ce0d1 --- /dev/null +++ b/source/MaaDebuggingControlUnit/General/VirtualInfo.h @@ -0,0 +1,31 @@ +#pragma once + +#include "ControlUnit/DebuggingControlUnitAPI.h" + +#include + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +class VirtualInfo : public DeviceInfoAPI +{ +public: + VirtualInfo(std::filesystem::path path) : path_(std::move(path)) {} + virtual ~VirtualInfo() override = default; + +public: // from DeviceInfoAPI + virtual std::string get_uuid() const override { return uuid_; } + virtual DeviceResolution get_resolution() const override { return resolution_; } + virtual int get_orientation() const override { return orientation_; } + +public: + bool parse(const json::value& config); + +private: + std::filesystem::path path_; + + std::string uuid_; + DeviceResolution resolution_; + int orientation_; +}; + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaDebuggingControlUnit/MaaDebuggingControlUnit.vcxproj b/source/MaaDebuggingControlUnit/MaaDebuggingControlUnit.vcxproj new file mode 100644 index 000000000..05305935c --- /dev/null +++ b/source/MaaDebuggingControlUnit/MaaDebuggingControlUnit.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + x64 + + + Release + x64 + + + DebWithRelDeps + x64 + + + + + + + + + + + + + + + 16.0 + Win32Proj + {E750209E-FE9B-4897-875A-61BFA73F51F3} + 10.0 + x64 + + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + false + v142 + false + Unicode + + + + + + + + + + + + + + + + + + false + $(ProjectDir)..\include;$(ProjectDir)..\..\include;$(ProjectDir)..\..\3rdparty\include; + $(SolutionDir)\$(Platform)\$(Configuration)\;$(LibraryPath) + $(SolutionDir)\$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)..\include;$(ProjectDir)..\..\include;$(ProjectDir)..\..\3rdparty\include; + $(SolutionDir)\$(Platform)\$(Configuration)\;$(LibraryPath) + $(SolutionDir)\$(Platform)\$(Configuration)\ + + + true + $(ProjectDir)..\include;$(ProjectDir)..\..\include;$(ProjectDir)..\..\3rdparty\include; + $(SolutionDir)\$(Platform)\$(Configuration)\;$(LibraryPath) + $(SolutionDir)\$(Platform)\$(Configuration)\ + + + + Level4 + true + true + true + NDEBUG;_CONSOLE;MAA_CONTROL_UNIT_EXPORTS;%(PreprocessorDefinitions) + true + stdcpp20 + stdc11 + MultiThreadedDLL + MinSpace + /utf-8 /MP $(ExternalCompilerOptions) %(AdditionalOptions) + true + $(ProjectDir);%(AdditionalIncludeDirectories) + 4251 + + + Console + true + true + true + MaaUtils.lib;opencv_world4.lib;%(AdditionalDependencies) + true + /ignore:4286 %(AdditionalOptions) + + + + + Level4 + false + true + NDEBUG;_CONSOLE;MAA_CONTROL_UNIT_EXPORTS;MAA_DEBUG;%(PreprocessorDefinitions) + true + stdcpp20 + stdc11 + MultiThreadedDLL + Disabled + EnableFastChecks + /utf-8 /MP $(ExternalCompilerOptions) %(AdditionalOptions) + true + $(ProjectDir);%(AdditionalIncludeDirectories) + 4251 + + + Console + true + true + true + MaaUtils.lib;opencv_world4.lib;%(AdditionalDependencies) + true + + + + + Level4 + false + true + _CONSOLE;_DEBUG;MAA_CONTROL_UNIT_EXPORTS;MAA_DEBUG;%(PreprocessorDefinitions) + true + stdcpp20 + stdc11 + MultiThreadedDebugDLL + Disabled + EnableFastChecks + /utf-8 /MP $(ExternalCompilerOptions) %(AdditionalOptions) + true + EditAndContinue + $(ProjectDir);%(AdditionalIncludeDirectories) + 4251 + + + Console + true + MaaUtils.lib;opencv_world4d.lib;%(AdditionalDependencies) + + + + + + \ No newline at end of file diff --git a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp new file mode 100644 index 000000000..91d1b6b9b --- /dev/null +++ b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp @@ -0,0 +1,75 @@ +#include "ControlUnitMgr.h" + +#include "ReadIndex.h" +#include "Utils/ImageIo.h" +#include "Utils/Logger.h" + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +ReadIndex::ReadIndex(std::filesystem::path indexfile) : indexfile_(std::move(indexfile)) {} + +bool ReadIndex::init(int swidth, int sheight) +{ + LogInfo << VAR(indexfile_) << VAR(swidth) << VAR(sheight); + + swidth_ = swidth; + sheight_ = sheight; + filepaths_.clear(); + index_ = 0; + + if (!std::filesystem::exists(indexfile_)) { + LogError << "indexfile not exist" << VAR(indexfile_); + return false; + } + + std::ifstream ifs(indexfile_); + if (!ifs.is_open()) { + LogError << "open indexfile failed" << VAR(indexfile_); + return false; + } + + std::string line; + while (std::getline(ifs, line)) { + if (line.empty()) { + continue; + } + std::istringstream iss(line); + std::filesystem::path image_path; + if (image_path.is_absolute()) { + image_path = line; + } + else { + image_path = indexfile_.parent_path() / line; + } + if (!std::filesystem::exists(image_path)) { + LogError << "image not exist" << VAR(image_path); + continue; + } + filepaths_.emplace_back(std::move(image_path)); + } + + return !filepaths_.empty(); +} + +std::optional ReadIndex::screencap() +{ + if (index_ >= filepaths_.size()) { + LogInfo << "index_ >= filepaths_.size(), reset index_ to 0"; + index_ = 0; + } + + auto image_path = filepaths_[index_++]; + LogInfo << VAR(image_path); + + LogInfo << "read image" << VAR(image_path); + auto image = imread(image_path); + if (image.empty()) { + LogError << "read image failed" << VAR(image_path); + return std::nullopt; + } + + cv::resize(image, image, cv::Size(swidth_, sheight_)); + return image; +} + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h new file mode 100644 index 000000000..1be1fdcc5 --- /dev/null +++ b/source/MaaDebuggingControlUnit/Screencap/ReadIndex.h @@ -0,0 +1,29 @@ +#pragma once + +#include "ControlUnit/DebuggingControlUnitAPI.h" + +#include + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +class ReadIndex : public ScreencapAPI +{ +public: + ReadIndex(std::filesystem::path indexfile); + virtual ~ReadIndex() override = default; + +public: // from ScreencapAPI + virtual bool init(int swidth, int sheight) override; + + virtual std::optional screencap() override; + +private: + int swidth_ = 0; + int sheight_ = 0; + + std::filesystem::path indexfile_; + std::vector filepaths_; + size_t index_ = 0; +}; + +MAA_DBG_CTRL_UNIT_NS_END diff --git a/source/MaaFramework/CMakeLists.txt b/source/MaaFramework/CMakeLists.txt index e0ebb3ebf..427b1a017 100644 --- a/source/MaaFramework/CMakeLists.txt +++ b/source/MaaFramework/CMakeLists.txt @@ -18,7 +18,7 @@ target_include_directories( target_compile_definitions(MaaFramework PRIVATE MAA_FRAMEWORK_EXPORTS) -target_link_libraries(MaaFramework MaaAdbControlUnit MaaUtils) +target_link_libraries(MaaFramework MaaAdbControlUnit MaaDebuggingControlUnit MaaUtils) if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) target_link_libraries(MaaFramework MaaThriftController) endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) @@ -27,7 +27,7 @@ target_link_libraries(MaaFramework ${OpenCV_LIBS} fastdeploy_ppocr ONNXRuntime:: # clang 15之后有ranges if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") find_package(range-v3 REQUIRED) # target_link_libraries(MaaFramework range-v3::range-v3) endif () -add_dependencies(MaaFramework MaaAdbControlUnit MaaUtils) +add_dependencies(MaaFramework MaaAdbControlUnit MaaDebuggingControlUnit MaaUtils) if(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) add_dependencies(MaaFramework MaaThriftController) endif(WITH_THRIFT AND NOT MAA_CROSSCOMPILE) diff --git a/source/MaaFramework/Controller/DebuggingController.cpp b/source/MaaFramework/Controller/DebuggingController.cpp new file mode 100644 index 000000000..b5af867c8 --- /dev/null +++ b/source/MaaFramework/Controller/DebuggingController.cpp @@ -0,0 +1,111 @@ +#include "DebuggingController.h" + +#include "MaaFramework/MaaMsg.h" +#include "Utils/Logger.h" +#include "Utils/StringMisc.hpp" + +#include + +MAA_CTRL_NS_BEGIN + +DebuggingController::DebuggingController(std::string read_path, std::string write_path, + std::shared_ptr unit_mgr, + MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) + : ControllerMgr(callback, callback_arg), read_path_(std::move(read_path)), write_path_(std::move(write_path)), + unit_mgr_(std::move(unit_mgr)) +{ + LogDebug << VAR(read_path_) << VAR(write_path_) << VAR(unit_mgr_) << VAR(unit_mgr_->device_info_obj()) + << VAR(unit_mgr_->screencap_obj()); +} + +DebuggingController::~DebuggingController() {} + +std::string DebuggingController::get_uuid() const +{ + return read_path_; +} + +bool DebuggingController::_connect() +{ + if (!unit_mgr_ || !unit_mgr_->device_info_obj() || !unit_mgr_->screencap_obj() + /*|| !unit_mgr_->touch_input_obj() || !unit_mgr_->key_input_obj()*/) { + LogError << "unit is nullptr" << VAR(unit_mgr_) << VAR(unit_mgr_->device_info_obj()) + << VAR(unit_mgr_->screencap_obj()); + return false; + } + + auto [screen_width, screen_height] = unit_mgr_->device_info_obj()->get_resolution(); + unit_mgr_->screencap_obj()->init(screen_width, screen_height); + + return true; +} + +std::pair DebuggingController::_get_resolution() const +{ + auto [screen_width, screen_height] = unit_mgr_->device_info_obj()->get_resolution(); + return { screen_width, screen_height }; +} + +bool DebuggingController::_click(ClickParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_swipe(SwipeParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_touch_down(TouchParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_touch_move(TouchParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_touch_up(TouchParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_press_key(PressKeyParam param) +{ + std::ignore = param; + return true; +} + +cv::Mat DebuggingController::_screencap() +{ + if (!unit_mgr_ || !unit_mgr_->screencap_obj()) { + LogError << "unit is nullptr" << VAR(unit_mgr_) << VAR(unit_mgr_->screencap_obj()); + return {}; + } + + auto ret = unit_mgr_->screencap_obj()->screencap(); + if (!ret) { + return cv::Mat(); + } + return std::move(ret.value()); +} + +bool DebuggingController::_start_app(AppParam param) +{ + std::ignore = param; + return true; +} + +bool DebuggingController::_stop_app(AppParam param) +{ + std::ignore = param; + return true; +} + +MAA_CTRL_NS_END diff --git a/source/MaaFramework/Controller/DebuggingController.h b/source/MaaFramework/Controller/DebuggingController.h new file mode 100644 index 000000000..f9f692655 --- /dev/null +++ b/source/MaaFramework/Controller/DebuggingController.h @@ -0,0 +1,40 @@ +#pragma once +#include "ControllerMgr.h" + +#include "ControlUnit/DebuggingControlUnitAPI.h" + +#include + +MAA_CTRL_NS_BEGIN + +class DebuggingController : public ControllerMgr +{ +public: + DebuggingController(std::string read_path, std::string write_path, + std::shared_ptr unit_mgr, MaaControllerCallback callback, + MaaCallbackTransparentArg callback_arg); + virtual ~DebuggingController() override; + + virtual std::string get_uuid() const override; + +protected: + virtual bool _connect() override; + virtual std::pair _get_resolution() const override; + virtual bool _click(ClickParam param) override; + virtual bool _swipe(SwipeParam param) override; + virtual bool _touch_down(TouchParam param) override; + virtual bool _touch_move(TouchParam param) override; + virtual bool _touch_up(TouchParam param) override; + virtual bool _press_key(PressKeyParam param) override; + virtual cv::Mat _screencap() override; + virtual bool _start_app(AppParam param) override; + virtual bool _stop_app(AppParam param) override; + +private: + std::string read_path_; + std::string write_path_; + + std::shared_ptr unit_mgr_ = nullptr; +}; + +MAA_CTRL_NS_END diff --git a/source/MaaFramework/MaaFramework.vcxproj b/source/MaaFramework/MaaFramework.vcxproj index b2a29a061..5aae7d129 100644 --- a/source/MaaFramework/MaaFramework.vcxproj +++ b/source/MaaFramework/MaaFramework.vcxproj @@ -35,6 +35,7 @@ + @@ -94,6 +95,7 @@ + @@ -202,7 +204,7 @@ true true true - MaaUtils.lib;MaaAdbControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4.lib;thriftmd.lib;%(AdditionalDependencies) + MaaUtils.lib;MaaAdbControlUnit.lib;MaaDebuggingControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4.lib;thriftmd.lib;%(AdditionalDependencies) true /ignore:4286 %(AdditionalOptions) @@ -232,7 +234,7 @@ true true true - MaaUtils.lib;MaaAdbControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4.lib;thriftmd.lib;%(AdditionalDependencies) + MaaUtils.lib;MaaAdbControlUnit.lib;MaaDebuggingControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4.lib;thriftmd.lib;%(AdditionalDependencies) true @@ -257,7 +259,7 @@ Console true - MaaUtils.lib;MaaAdbControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4d.lib;thriftmdd.lib;%(AdditionalDependencies) + MaaUtils.lib;MaaAdbControlUnit.lib;MaaDebuggingControlUnit.lib;fastdeploy_ppocr.lib;onnxruntime.lib;opencv_world4d.lib;thriftmdd.lib;%(AdditionalDependencies) diff --git a/source/include/Conf/Conf.h b/source/include/Conf/Conf.h index af98e6262..7f582f1a2 100644 --- a/source/include/Conf/Conf.h +++ b/source/include/Conf/Conf.h @@ -119,6 +119,12 @@ { #define MAA_ADB_CTRL_UNIT_NS_END } +#define MAA_DBG_CTRL_UNIT_NS MAA_CTRL_NS::DbgUnitNs +#define MAA_DBG_CTRL_UNIT_NS_BEGIN \ + namespace MAA_DBG_CTRL_UNIT_NS \ + { +#define MAA_DBG_CTRL_UNIT_NS_END } + /* MaaToolKit */ #define MAA_TOOLKIT_NS MAA_NS::ToolKitNS diff --git a/source/include/ControlUnit/DebuggingControlUnitAPI.h b/source/include/ControlUnit/DebuggingControlUnitAPI.h new file mode 100644 index 000000000..d152fc9ea --- /dev/null +++ b/source/include/ControlUnit/DebuggingControlUnitAPI.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +#include "Conf/Conf.h" +#include "MaaFramework/MaaDef.h" +#include "Utils/NoWarningCVMat.hpp" + +MAA_DBG_CTRL_UNIT_NS_BEGIN + +/* General */ + +struct DeviceResolution +{ + int width = 0; + int height = 0; +}; + +class DeviceInfoAPI +{ +public: + virtual ~DeviceInfoAPI() = default; + + virtual std::string get_uuid() const = 0; + virtual DeviceResolution get_resolution() const = 0; + virtual int get_orientation() const = 0; +}; + +/* Screencap */ + +class ScreencapAPI +{ +public: + virtual ~ScreencapAPI() = default; + + virtual bool init(int swidth, int sheight) = 0; + + virtual std::optional screencap() = 0; +}; + +/* Main */ + +class ControlUnitAPI +{ +public: + virtual ~ControlUnitAPI() = default; + + // virtual std::shared_ptr connection_obj() = 0; + virtual std::shared_ptr device_info_obj() = 0; + // virtual std::shared_ptr activity_obj() = 0; + //virtual std::shared_ptr touch_input_obj() = 0; + //virtual std::shared_ptr key_input_obj() = 0; + virtual std::shared_ptr screencap_obj() = 0; +}; + +std::shared_ptr MAA_CONTROL_UNIT_API create_controller_unit(MaaStringView read_path, + MaaStringView write_path, + MaaDebuggingControllerType type, + MaaStringView config); + +MAA_DBG_CTRL_UNIT_NS_END