4343
4444
4545def 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+ """
4652 mouse_interface_index , mouse_endpoint_address = None , None
4753 mouse_device = None
4854
@@ -96,6 +102,17 @@ def find_and_init_boot_mouse():
96102
97103
98104class 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+
99116 def __init__ (self , device , endpoint_address , tilegrid , was_attached ):
100117 self .device = device
101118 self .tilegrid = tilegrid
@@ -107,17 +124,34 @@ def __init__(self, device, endpoint_address, tilegrid, was_attached):
107124
108125 @property
109126 def x (self ):
127+ """
128+ The x coordinate of the mouse cursor
129+ """
110130 return self .tilegrid .x
111131
112132 @property
113133 def y (self ):
134+ """
135+ The y coordinate of the mouse cursor
136+ """
114137 return self .tilegrid .y
115138
116139 def release (self ):
140+ """
141+ Release the mouse cursor and re-attach it to the kernel
142+ if it was attached previously.
143+ """
117144 if self .was_attached and not self .device .is_kernel_driver_active (0 ):
118145 self .device .attach_kernel_driver (0 )
119146
120147 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+ """
121155 try :
122156 # attempt to read data from the mouse
123157 # 20ms timeout, so we don't block long if there
0 commit comments