@@ -137,15 +137,28 @@ class BootMouse:
137137 :param endpoint_address: The address of the mouse endpoint
138138 :param was_attached: Whether the usb device was attached to the kernel
139139 :param tilegrid: The TileGrid that holds the visible mouse cursor
140+ :param scale: The scale of the group that the Mouse TileGrid will be put into.
141+ Needed in order to properly clamp the mouse to the display bounds
140142 """
141143
142144 def __init__ (self , device , endpoint_address , was_attached , tilegrid = None , scale = 1 ): # noqa: PLR0913, too many args
143145 self .device = device
146+
147+ self .tilegrid = tilegrid
148+ """TileGrid containing the Mouse cursor graphic."""
149+
144150 self .endpoint = endpoint_address
145151 self .buffer = array .array ("b" , [0 ] * 4 )
146152 self .was_attached = was_attached
147- self . tilegrid = tilegrid
153+
148154 self .scale = scale
155+ """The scale of the group that the Mouse TileGrid will be put into.
156+ Needed in order to properly clamp the mouse to the display bounds."""
157+
158+ self .sensitivity = 1
159+ """The sensitivity of the mouse cursor. Larger values will make
160+ the mouse cursor move slower relative to physical mouse movement. Default is 1."""
161+
149162 if tilegrid is not None :
150163 self .display_size = (
151164 supervisor .runtime .display .width ,
@@ -158,28 +171,28 @@ def __init__(self, device, endpoint_address, was_attached, tilegrid=None, scale=
158171 self ._x , self ._y = 0 , 0
159172
160173 @property
161- def x (self ):
174+ def x (self ) -> int :
162175 """
163176 The x coordinate of the mouse cursor
164177 """
165178 return self .tilegrid .x if self .tilegrid else self ._x
166179
167180 @x .setter
168- def x (self , new_x ) :
181+ def x (self , new_x : int ) -> None :
169182 if self .tilegrid :
170183 self .tilegrid .x = new_x
171184 else :
172185 self ._x = new_x
173186
174187 @property
175- def y (self ):
188+ def y (self ) -> int :
176189 """
177190 The y coordinate of the mouse cursor
178191 """
179192 return self .tilegrid .y if self .tilegrid else self ._y
180193
181194 @y .setter
182- def y (self , new_y ) :
195+ def y (self , new_y : int ) -> None :
183196 if self .tilegrid :
184197 self .tilegrid .y = new_y
185198 else :
@@ -198,8 +211,9 @@ def update(self):
198211 Read data from the USB mouse and update the location of the visible cursor
199212 and check if any buttons are pressed.
200213
201- :return: a List containing one or more of the strings "left", "right", "middle"
202- indicating which buttons are pressed.
214+ :return: a tuple containing one or more of the strings "left", "right", "middle"
215+ indicating which buttons are pressed. If no buttons are pressed, the tuple will be empty.
216+ If a error occurred while trying to read from the usb device, `None` will be returned.
203217 """
204218 try :
205219 # attempt to read data from the mouse
@@ -215,6 +229,8 @@ def update(self):
215229 # update the mouse x and y coordinates
216230 # based on the delta values read from the mouse
217231 dx , dy = self .buffer [1 :3 ]
232+ dx = int (round ((dx / self .sensitivity ), 0 ))
233+ dy = int (round ((dy / self .sensitivity ), 0 ))
218234 if self .tilegrid :
219235 self .tilegrid .x = max (
220236 0 , min ((self .display_size [0 ] // self .scale ) - 1 , self .tilegrid .x + dx )
@@ -235,5 +251,4 @@ def update(self):
235251 # it is being clicked.
236252 pressed_btns .append (button )
237253
238- if len (pressed_btns ) > 0 :
239- return pressed_btns
254+ return tuple (pressed_btns )
0 commit comments