Add connect() and disconnect() to backend API

This commit is contained in:
Samuel Sloniker 2021-07-09 18:47:29 -07:00
parent 185e515c66
commit 1fc8aa4505
3 changed files with 19 additions and 0 deletions

View File

@ -12,3 +12,11 @@ def get_img():
def touch(x, y, is_long): def touch(x, y, is_long):
requests.get(f'http://localhost:8080/set_touch?x={x}&y={y}&hold={1 if is_long else 0}') requests.get(f'http://localhost:8080/set_touch?x={x}&y={y}&hold={1 if is_long else 0}')
def connect():
pass
def disconnect():
pass

View File

@ -25,3 +25,11 @@ def touch(x, y, is_long):
threading.Thread(target=_long_touch, args=(x, y,)).start() threading.Thread(target=_long_touch, args=(x, y,)).start()
else: else:
subprocess.run(['xdotool', 'mousemove', str(x), str(y), 'click', '1']) subprocess.run(['xdotool', 'mousemove', str(x), str(y), 'click', '1'])
def connect():
pass
def disconnect():
pass

View File

@ -83,6 +83,7 @@ class HCRAServer(tornado.websocket.WebSocketHandler):
self.client.good = None self.client.good = None
client = None client = None
self.is_open = False self.is_open = False
imgproc.backend.disconnect()
def on_message(self, message): def on_message(self, message):
action = message.split(' ', 1)[0] action = message.split(' ', 1)[0]
@ -113,6 +114,8 @@ class HCRAServer(tornado.websocket.WebSocketHandler):
self.write_message(str(e)) self.write_message(str(e))
return return
imgproc.backend.connect()
try: try:
imgname = imgproc.get_full_img() imgname = imgproc.get_full_img()
except Exception as e: except Exception as e: