43
43
44
44
45
45
def find_and_init_boot_mouse ():
46
+ """
47
+ Scan for an attached boot mouse connected via USB host.
48
+ If one is found initialize an instance of BootMouse class
49
+ and return it.
50
+ :return: The BootMouse instance or None if no mouse was found.
51
+ """
46
52
mouse_interface_index , mouse_endpoint_address = None , None
47
53
mouse_device = None
48
54
@@ -96,6 +102,17 @@ def find_and_init_boot_mouse():
96
102
97
103
98
104
class BootMouse :
105
+ """
106
+ Helpler class that encapsulates the objects needed to interact with a boot
107
+ mouse, show a visible cursor on the display, and determine when buttons
108
+ were pressed.
109
+
110
+ :param device: The usb device instance for the mouse
111
+ :param endpoint_address: The address of the mouse endpoint
112
+ :param tilegrid: The TileGrid that holds the visible mouse cursor
113
+ :param was_attached: Whether the usb device was attached to the kernel
114
+ """
115
+
99
116
def __init__ (self , device , endpoint_address , tilegrid , was_attached ):
100
117
self .device = device
101
118
self .tilegrid = tilegrid
@@ -107,17 +124,34 @@ def __init__(self, device, endpoint_address, tilegrid, was_attached):
107
124
108
125
@property
109
126
def x (self ):
127
+ """
128
+ The x coordinate of the mouse cursor
129
+ """
110
130
return self .tilegrid .x
111
131
112
132
@property
113
133
def y (self ):
134
+ """
135
+ The y coordinate of the mouse cursor
136
+ """
114
137
return self .tilegrid .y
115
138
116
139
def release (self ):
140
+ """
141
+ Release the mouse cursor and re-attach it to the kernel
142
+ if it was attached previously.
143
+ """
117
144
if self .was_attached and not self .device .is_kernel_driver_active (0 ):
118
145
self .device .attach_kernel_driver (0 )
119
146
120
147
def update (self ):
148
+ """
149
+ Read data from the USB mouse and update the location of the visible cursor
150
+ and check if any buttons are pressed.
151
+
152
+ :return: a List containing one or more of the strings "left", "right", "middle"
153
+ indicating which buttons are pressed.
154
+ """
121
155
try :
122
156
# attempt to read data from the mouse
123
157
# 20ms timeout, so we don't block long if there
0 commit comments