From b3cb145d16dee36a6842d340bc07164f9088f376 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 18 Oct 2023 22:56:50 +0800 Subject: [PATCH] docs: update sample --- assets/resource/pipeline/custom_demo.json | 4 ++-- sample/cpp/main.cpp | 26 ++++++++++++----------- sample/python/__main__.py | 8 +++---- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/assets/resource/pipeline/custom_demo.json b/assets/resource/pipeline/custom_demo.json index d71bafd98..1f6902089 100644 --- a/assets/resource/pipeline/custom_demo.json +++ b/assets/resource/pipeline/custom_demo.json @@ -1,5 +1,5 @@ { - "MyTask": { + "MyCustomTask": { "next": [ "MyCustomRecTask" ] @@ -11,4 +11,4 @@ "my_key": "my_value" } } -} +} \ No newline at end of file diff --git a/sample/cpp/main.cpp b/sample/cpp/main.cpp index fc3a125e4..434d67ac6 100644 --- a/sample/cpp/main.cpp +++ b/sample/cpp/main.cpp @@ -24,44 +24,46 @@ int main([[maybe_unused]] int argc, char** argv) } auto cur_dir = std::filesystem::path(argv[0]).parent_path(); - auto agent_path = cur_dir / "MaaAgentBinary"; const int kIndex = 0; // for demo, we just use the first device + auto agent_path = cur_dir / "share" / "MaaAgentBinary"; auto controller_handle = MaaAdbControllerCreateV2(MaaToolKitGetDeviceAdbPath(kIndex), MaaToolKitGetDeviceAdbSerial(kIndex), MaaToolKitGetDeviceAdbControllerType(kIndex), MaaToolKitGetDeviceAdbConfig(kIndex), agent_path.string().c_str(), nullptr, nullptr); auto ctrl_id = MaaControllerPostConnection(controller_handle); - MaaControllerWait(controller_handle, ctrl_id); auto resource_handle = MaaResourceCreate(nullptr, nullptr); - auto resource_dir = cur_dir / "resource"; + auto resource_dir = cur_dir / "share" / "resource"; auto res_id = MaaResourcePostPath(resource_handle, resource_dir.string().c_str()); + + MaaControllerWait(controller_handle, ctrl_id); MaaResourceWait(resource_handle, res_id); auto maa_handle = MaaCreate(nullptr, nullptr); MaaBindResource(maa_handle, resource_handle); MaaBindController(maa_handle, controller_handle); - if (!MaaInited(maa_handle)) { - std::cout << "Failed to init MAA" << std::endl; - + auto destroy = [&]() { MaaDestroy(maa_handle); MaaResourceDestroy(resource_handle); MaaControllerDestroy(controller_handle); MaaToolKitUninit(); - return 0; + }; + + if (!MaaInited(maa_handle)) { + std::cout << "Failed to init MAA" << std::endl; + + destroy(); + return -1; } register_my_recognizer(maa_handle); - auto task_id = MaaPostTask(maa_handle, "VisonTest", MaaTaskParam_Empty); + auto task_id = MaaPostTask(maa_handle, "StartUpAndClickButton", MaaTaskParam_Empty); MaaWaitTask(maa_handle, task_id); - MaaDestroy(maa_handle); - MaaResourceDestroy(resource_handle); - MaaControllerDestroy(controller_handle); - MaaToolKitUninit(); + destroy(); return 0; } diff --git a/sample/python/__main__.py b/sample/python/__main__.py index 06bed01a5..ff2c26d08 100644 --- a/sample/python/__main__.py +++ b/sample/python/__main__.py @@ -5,13 +5,13 @@ if __name__ == "__main__": - Library.open("../../x64/Debug") + Library.open("bin") resource = Resource() - res_id = resource.post_path("../../x64/Debug/resource") + res_id = resource.post_path("share/resource/") resource.wait(res_id) - controller = AdbController("adb", "127.0.0.1:16416") + controller = AdbController("adb", "127.0.0.1:16416", agent_path = "share/MaaAgentBinary/") ctrl_id = controller.post_connection() controller.wait(ctrl_id) @@ -22,5 +22,5 @@ print("Failed to init MAA.") exit() - task_id = maa_inst.post_task("MyTask", {}) + task_id = maa_inst.post_task("StartUpAndClickButton", {}) maa_inst.wait(task_id)