@@ -113,12 +113,13 @@ class BootMouse:
113
113
:param was_attached: Whether the usb device was attached to the kernel
114
114
"""
115
115
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
117
117
self .device = device
118
118
self .tilegrid = tilegrid
119
119
self .endpoint = endpoint_address
120
- self .buffer = array .array ("b" , [0 ] * 8 )
120
+ self .buffer = array .array ("b" , [0 ] * 4 )
121
121
self .was_attached = was_attached
122
+ self .scale = scale
122
123
123
124
self .display_size = (supervisor .runtime .display .width , supervisor .runtime .display .height )
124
125
@@ -129,13 +130,21 @@ def x(self):
129
130
"""
130
131
return self .tilegrid .x
131
132
133
+ @x .setter
134
+ def x (self , new_x ):
135
+ self .tilegrid .x = new_x
136
+
132
137
@property
133
138
def y (self ):
134
139
"""
135
140
The y coordinate of the mouse cursor
136
141
"""
137
142
return self .tilegrid .y
138
143
144
+ @y .setter
145
+ def y (self , new_y ):
146
+ self .tilegrid .y = new_y
147
+
139
148
def release (self ):
140
149
"""
141
150
Release the mouse cursor and re-attach it to the kernel
@@ -160,11 +169,17 @@ def update(self):
160
169
except usb .core .USBTimeoutError :
161
170
# skip the rest if there is no data
162
171
return None
172
+ except usb .core .USBError :
173
+ return None
163
174
164
175
# update the mouse tilegrid x and y coordinates
165
176
# 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
+ )
168
183
169
184
pressed_btns = []
170
185
for i , button in enumerate (BUTTONS ):
0 commit comments