Skip to content
Snippets Groups Projects
Commit 67548ad4 authored by Hannes Tiltmann's avatar Hannes Tiltmann
Browse files

new frontend for py3

parent 91f1488d
Branches
No related tags found
No related merge requests found
__pycache__
\ No newline at end of file
from leap import LeapController
l = LeapController("127.0.0.1", logging=True)
l.run()
input()
\ No newline at end of file
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment