Skip to content

Commit

Permalink
docs: update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 18, 2023
1 parent 52725b2 commit b3cb145
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions assets/resource/pipeline/custom_demo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"MyTask": {
"MyCustomTask": {
"next": [
"MyCustomRecTask"
]
Expand All @@ -11,4 +11,4 @@
"my_key": "my_value"
}
}
}
}
26 changes: 14 additions & 12 deletions sample/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions sample/python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

0 comments on commit b3cb145

Please sign in to comment.