From f6daad73c9f5b3c9b0af8abc9985ce9eaa8b622e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 23 Mar 2022 21:03:44 +0100 Subject: [PATCH] fix: use ppab device instead of subprocess, need refactoring --- src/garage.py | 8 ++++---- src/init.py | 3 +-- src/main.py | 17 +++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/garage.py b/src/garage.py index f87b77b..168d580 100644 --- a/src/garage.py +++ b/src/garage.py @@ -1,10 +1,11 @@ import itertools import logging -from subprocess import call from time import sleep import numpy as np +import init + CENTER = (1000, 500) STICKER_MENU_BTN = (220, 60) @@ -47,12 +48,11 @@ old_team = None def tap(pos): - call(["adb", "shell", "input", "tap", str(pos[0]), str(pos[1])]) - # device.shell(f"input tap {pos[0]} {pos[1]}") + init.device.shell(f"input tap {pos[0]} {pos[1]}") def motion(pos, type): - call(["adb", "shell", "input", "motionevent", type, str(pos[0]), str(pos[1])]) + init.device.shell(f"input motionevent {type} {pos[0]} {pos[1]}") def selectColor(team: int, primary_color: float, secondary_color: float): diff --git a/src/init.py b/src/init.py index 0267d3b..4ad51fe 100644 --- a/src/init.py +++ b/src/init.py @@ -20,6 +20,7 @@ def connect_adb(): logging.debug(f"devices detected: {devices_names}") + global device if len(devices) == 1: device = devices[0] elif len(devices) == 0: @@ -31,8 +32,6 @@ def connect_adb(): logging.debug(f"device selected: {device.serial}") - return device - def get_users(device): device_users = device.shell("pm list users") diff --git a/src/main.py b/src/main.py index fa2ca84..0c78d37 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ import logging from time import sleep +import init from database import connect_to_database, insert_into_database, take_screenshot from garage import generate_loadouts, newCar, rotate from init import ( @@ -22,18 +23,18 @@ logging.getLogger("PIL.PngImagePlugin").setLevel(logging.ERROR) if __name__ == "__main__": - device = connect_adb() - users = get_users(device) - users = detect_game(device, users) - start_game(device, users) - set_notifications(device, False) + connect_adb() + users = get_users(init.device) + users = detect_game(init.device, users) + start_game(init.device, users) + set_notifications(init.device, False) database = connect_to_database("dataset.db") loadouts = generate_loadouts() NB_ROTATIONS = 20 - while detect_focus(device): + while detect_focus(init.device): for (i, loadout) in enumerate(loadouts): ((model, sticker), wheel, hat, team, primary_color, secondary_color) = loadout @@ -43,9 +44,9 @@ if __name__ == "__main__": sleep(0.5) for x_rotation in range(NB_ROTATIONS): rotate(130, 0) - uuid = take_screenshot(device) + uuid = take_screenshot(init.device) insert_into_database(database, uuid, loadout, x_rotation, 0) - set_notifications(device, True) + set_notifications(init.device, True) database.close()