@@ -179,10 +179,10 @@ class MousePoller(object):
179
179
"""Get 'pressed' and location updates from a USB mouse."""
180
180
181
181
def __init__ (self , splash , cursor_bmp , screen_width , screen_height ):
182
- logger = logging .getLogger ("Paint" )
183
- if not logger .hasHandlers ():
184
- logger .addHandler (logging .StreamHandler ())
185
- logger .debug ("Creating a MousePoller" )
182
+ self . _logger = logging .getLogger ("Paint" )
183
+ if not self . _logger .hasHandlers ():
184
+ self . _logger .addHandler (logging .StreamHandler ())
185
+ self . _logger .debug ("Creating a MousePoller" )
186
186
self ._display_grp = splash
187
187
self ._cursor_grp = displayio .Group ()
188
188
self ._cur_palette = displayio .Palette (3 )
@@ -217,8 +217,8 @@ def __init__(self, splash, cursor_bmp, screen_width, screen_height):
217
217
if self .find_mouse ():
218
218
mouse_found = True
219
219
else :
220
- print ("WARNING: Mouse not found after multiple attempts." )
221
- print ("The application will run, but mouse control may not work." )
220
+ self . _logger . debug ("WARNING: Mouse not found after multiple attempts." )
221
+ self . _logger . debug ("The application will run, but mouse control may not work." )
222
222
223
223
224
224
def find_mouse (self ):
@@ -227,12 +227,12 @@ def find_mouse(self):
227
227
RETRY_DELAY = 1 # seconds
228
228
229
229
if not usb_available :
230
- print ("USB library not available; cannot find mouse." )
230
+ self . _logger . debug ("USB library not available; cannot find mouse." )
231
231
return False
232
232
233
233
for attempt in range (MAX_ATTEMPTS ):
234
234
try :
235
- print (f"Mouse detection attempt { attempt + 1 } /{ MAX_ATTEMPTS } " )
235
+ self . _logger . debug (f"Mouse detection attempt { attempt + 1 } /{ MAX_ATTEMPTS } " )
236
236
237
237
# Constants for USB control transfers
238
238
DIR_OUT = 0
@@ -246,7 +246,7 @@ def find_mouse(self):
246
246
247
247
for device in usb .core .find (find_all = True ):
248
248
devices_found = True
249
- print (f"Found device: { device .idVendor :04x} :{ device .idProduct :04x} " )
249
+ self . _logger . debug (f"Found device: { device .idVendor :04x} :{ device .idProduct :04x} " )
250
250
251
251
try :
252
252
# Try to get device info
@@ -266,18 +266,18 @@ def find_mouse(self):
266
266
if has_kernel_driver and device .is_kernel_driver_active (0 ):
267
267
device .detach_kernel_driver (0 )
268
268
except Exception as e : # pylint: disable=broad-except
269
- print (f"Error detaching kernel driver: { e } " )
269
+ self . _logger . debug (f"Error detaching kernel driver: { e } " )
270
270
271
271
# Set configuration
272
272
try :
273
273
device .set_configuration ()
274
274
except Exception as e : # pylint: disable=broad-except
275
- print (f"Error setting configuration: { e } " )
275
+ self . _logger . debug (f"Error setting configuration: { e } " )
276
276
continue # Try next device
277
277
278
278
# Just assume endpoint 0x81 (common for mice)
279
279
self .in_endpoint = 0x81
280
- print (f"Using mouse: { manufacturer } , { product } " )
280
+ self . _logger . debug (f"Using mouse: { manufacturer } , { product } " )
281
281
282
282
# Set to report protocol mode
283
283
try :
@@ -288,49 +288,49 @@ def find_mouse(self):
288
288
289
289
buf = bytearray (1 )
290
290
device .ctrl_transfer (bmRequestType , bRequest , wValue , wIndex , buf )
291
- print ("Set to report protocol mode" )
291
+ self . _logger . debug ("Set to report protocol mode" )
292
292
except Exception as e : # pylint: disable=broad-except
293
- print (f"Could not set protocol: { e } " )
293
+ self . _logger . debug (f"Could not set protocol: { e } " )
294
294
295
295
# Buffer for reading data
296
296
self .buf = array .array ("B" , [0 ] * 4 )
297
- print ("Created 4-byte buffer for mouse data" )
297
+ self . _logger . debug ("Created 4-byte buffer for mouse data" )
298
298
299
299
# Verify mouse works by reading from it
300
300
try :
301
301
# Try to read some data with a short timeout
302
302
data = device .read (self .in_endpoint , self .buf , timeout = 100 )
303
- print (f"Mouse test read successful: { data } bytes" )
303
+ self . _logger . debug (f"Mouse test read successful: { data } bytes" )
304
304
return True
305
305
except usb .core .USBTimeoutError :
306
306
# Timeout is normal if mouse isn't moving
307
- print ("Mouse connected but not sending data (normal)" )
307
+ self . _logger . debug ("Mouse connected but not sending data (normal)" )
308
308
return True
309
309
except Exception as e : # pylint: disable=broad-except
310
- print (f"Mouse test read failed: { e } " )
310
+ self . _logger . debug (f"Mouse test read failed: { e } " )
311
311
# Continue to try next device or retry
312
312
self .mouse = None
313
313
self .in_endpoint = None
314
314
continue
315
315
316
316
except Exception as e : # pylint: disable=broad-except
317
- print (f"Error initializing device: { e } " )
317
+ self . _logger . debug (f"Error initializing device: { e } " )
318
318
continue
319
319
320
320
if not devices_found :
321
- print ("No USB devices found" )
321
+ self . _logger . debug ("No USB devices found" )
322
322
323
323
# If we get here without returning, no suitable mouse was found
324
- print (f"No working mouse found on attempt { attempt + 1 } , retrying..." )
324
+ self . _logger . debug (f"No working mouse found on attempt { attempt + 1 } , retrying..." )
325
325
gc .collect ()
326
326
time .sleep (RETRY_DELAY )
327
327
328
328
except Exception as e : # pylint: disable=broad-except
329
- print (f"Error during mouse detection: { e } " )
329
+ self . _logger . debug (f"Error during mouse detection: { e } " )
330
330
gc .collect ()
331
331
time .sleep (RETRY_DELAY )
332
332
333
- print ("Failed to find a working mouse after multiple attempts" )
333
+ self . _logger . debug ("Failed to find a working mouse after multiple attempts" )
334
334
return False
335
335
336
336
@@ -381,14 +381,14 @@ def _process_mouse_input(self):
381
381
382
382
# Handle disconnections
383
383
if e .errno == 19 : # No such device
384
- print ("Mouse disconnected" )
384
+ self . _logger . debug ("Mouse disconnected" )
385
385
self .mouse = None
386
386
self .in_endpoint = None
387
387
gc .collect ()
388
388
389
389
return False
390
390
except Exception as e : # pylint: disable=broad-except
391
- print (f"Error reading mouse: { type (e ).__name__ } " )
391
+ self . _logger . debug (f"Error reading mouse: { type (e ).__name__ } " )
392
392
return False
393
393
394
394
if count >= 3 : # We need at least buttons, X and Y
0 commit comments