def run(): mousereader.initMouseTrack() while True: x, y = mousereader.getMousePosition() print("%8.3f %8.3f" % (x, y)) time.sleep(1)
import math import time import mousereader #import threading mousereader.initMouseTrack() host = '10.44.15.37' port = 5814 server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print("Socket created") time.sleep(.1) server_socket.bind((host, port)) server_socket.listen(1) print("Listening in socket") conn, addr = server_socket.accept() print("Connected with " + addr[0] + ":" + str(addr[1])) while 1: x, y = mousereader.getMousePosition() data = conn.recv(1024) print(type(data)) a = conn.recv(1024) theta = data print("Recieved data from client:" + str(data)) # reply "OK..." + data # server_socket.send(data) # if not data: break conn.send(data) conn.close() server_socket.close()
conn.settimeout(1) while serverConnected == True: xm0 = xm1 ym0 = ym1 xf0 = xf1 yf0 = yf1 try: data = conn.recv(1024) except socket.timeout: print("Socket timed out at gyro angle read operation") serverConnected = False if not data: serverConnected = False else: theta = float(data) xm1, ym1 = mousereader.getMousePosition() deltaXm = xm1 - xm0 deltaYm = ym1 - ym0 if (deltaYm < 0): theta = theta + 180 deltaYm = deltaYm * -1.0 deltaXm = deltaXm * -1.0 if (deltaYm == 0): alpha = -1.0 * theta else: alpha = 90.0 - theta - math.degrees( math.atan((deltaXm) / (deltaYm))) # is atan returning in radians or degrees? if (deltaYm == 0.0 and deltaXm < 0.0): xf1 = xf0 - math.sqrt((deltaXm)**2 +