MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / getMouseValues

Function getMouseValues

Projects/MouseControl/mouse_control_robot.py:50–74  ·  view source on GitHub ↗
(file_input)

Source from the content-addressed store, hash-verified

48# x is the position of the mouse on the x axis
49# y is the position of the mouse on the y axis
50def getMouseValues(file_input):
51
52 buf = file_input.read(3)
53
54 # if ran with Python 3
55 # ord function will throw an exception, since
56 # buf[0] already is an integer, as opposed in Python 2
57 # where buf[0] is a string
58 try:
59 button = ord(buf[0])
60 except TypeError as msg:
61 button = buf[0]
62 if debug is True:
63 print(str(msg))
64
65 print(button)
66 left_button = (button & 0x1) > 0
67 middle_button = (button & 0x4) > 0
68 right_button = (button & 0x2) > 0
69 x_axis, y_axis = struct.unpack("bb", buf[1:])
70
71 if debug is True:
72 print("Left but: {}, Middle but: {}, Right but: {}, x pos: {}, y pos: {}".format(left_button, middle_button, right_button, x_axis, y_axis))
73
74 return (left_button, middle_button, right_button, x_axis, y_axis)
75
76
77def Main():

Callers 1

MainFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected