diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ed8ebf583f771da9150c35db3955987b7d757904 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/custom_py3/example.py b/custom_py3/example.py new file mode 100644 index 0000000000000000000000000000000000000000..493c188ac6b9a45ce9dfbe6d49e82889cd9224a6 --- /dev/null +++ b/custom_py3/example.py @@ -0,0 +1,6 @@ +from leap import LeapController + +l = LeapController("127.0.0.1", logging=True) +l.run() + +input() \ No newline at end of file diff --git a/custom_py3/leap.py b/custom_py3/leap.py new file mode 100644 index 0000000000000000000000000000000000000000..286a94ece2e5e3c93737f41926104b93a0274029 --- /dev/null +++ b/custom_py3/leap.py @@ -0,0 +1,41 @@ +import websocket +import _thread +import json + +class LeapController: + def __init__(self, ip: str, logging :bool=False): + self.ws = websocket.WebSocketApp("ws://"+ip+":6437") + self.ws.on_open = self.__on_open + self.ws.on_close = self.__on_close + self.ws.on_message = self.__on_message + self.logging = logging + + def __on_open(self, ws): + if self.logging: print("jey, connected to leap") + + def __on_close(self, ws, status, message): + if self.logging: print("autsch, disconnected from leap") + + def __on_message(self, ws, m): + self.frame = json.loads(m) + + if self.logging: + print("wow, new frame") + for h in self.frame["hands"]: + print(json.dumps(h["t"], indent=3)) + + def close(self): + self.ws.close() + + def run(self, blocking=False): + def eventloop(): + try: + self.ws.run_forever() + finally: + self.ws.close() + + if not blocking: + _thread.start_new_thread(eventloop,()) + return + + eventloop()