@@ -113,12 +113,13 @@ class BootMouse:
113113 :param was_attached: Whether the usb device was attached to the kernel
114114 """
115115
116- def __init__ (self , device , endpoint_address , tilegrid , was_attached ):
116+ def __init__ (self , device , endpoint_address , tilegrid , was_attached , scale = 1 ): # noqa: PLR0913, too many args
117117 self .device = device
118118 self .tilegrid = tilegrid
119119 self .endpoint = endpoint_address
120- self .buffer = array .array ("b" , [0 ] * 8 )
120+ self .buffer = array .array ("b" , [0 ] * 4 )
121121 self .was_attached = was_attached
122+ self .scale = scale
122123
123124 self .display_size = (supervisor .runtime .display .width , supervisor .runtime .display .height )
124125
@@ -129,13 +130,21 @@ def x(self):
129130 """
130131 return self .tilegrid .x
131132
133+ @x .setter
134+ def x (self , new_x ):
135+ self .tilegrid .x = new_x
136+
132137 @property
133138 def y (self ):
134139 """
135140 The y coordinate of the mouse cursor
136141 """
137142 return self .tilegrid .y
138143
144+ @y .setter
145+ def y (self , new_y ):
146+ self .tilegrid .y = new_y
147+
139148 def release (self ):
140149 """
141150 Release the mouse cursor and re-attach it to the kernel
@@ -160,11 +169,17 @@ def update(self):
160169 except usb .core .USBTimeoutError :
161170 # skip the rest if there is no data
162171 return None
172+ except usb .core .USBError :
173+ return None
163174
164175 # update the mouse tilegrid x and y coordinates
165176 # based on the delta values read from the mouse
166- self .tilegrid .x = max (0 , min ((self .display_size [0 ]) - 1 , self .tilegrid .x + self .buffer [1 ]))
167- self .tilegrid .y = max (0 , min ((self .display_size [1 ]) - 1 , self .tilegrid .y + self .buffer [2 ]))
177+ self .tilegrid .x = max (
178+ 0 , min ((self .display_size [0 ] // self .scale ) - 1 , self .tilegrid .x + self .buffer [1 ])
179+ )
180+ self .tilegrid .y = max (
181+ 0 , min ((self .display_size [1 ] // self .scale ) - 1 , self .tilegrid .y + self .buffer [2 ])
182+ )
168183
169184 pressed_btns = []
170185 for i , button in enumerate (BUTTONS ):
0 commit comments