@@ -321,7 +321,7 @@ def close(self) -> None:
321321
322322def find (vid : int = 0x2886 , pid : int = 0x001A ) -> ReSpeaker | None :
323323 """Find and return the ReSpeaker USB device with the given Vendor ID and Product ID."""
324- dev = usb .core .find (idVendor = vid , idProduct = pid )
324+ dev = usb .core .find (idVendor = vid , idProduct = pid , backend = get_libusb1_backend () )
325325 if not dev :
326326 return None
327327
@@ -331,22 +331,29 @@ def find(vid: int = 0x2886, pid: int = 0x001A) -> ReSpeaker | None:
331331def init_respeaker_usb () -> Optional [ReSpeaker ]:
332332 """Initialize the ReSpeaker USB device. Looks for both new and beta device IDs."""
333333 try :
334+ # Try new firmware first
334335 dev = usb .core .find (
335336 idVendor = 0x38FB , idProduct = 0x1001 , backend = get_libusb1_backend ()
336337 )
338+
339+ # If not found, try old firmware
337340 if dev is None :
338341 dev = usb .core .find (
339342 idVendor = 0x2886 , idProduct = 0x001A , backend = get_libusb1_backend ()
340343 )
341- if dev is None :
342- logging .error ("No ReSpeaker USB device found !" )
343- return None
344- else :
345- logging .warning ("Old firmware detected on ReSpeaker USB device. Please update the firmware!" )
344+ if dev is not None :
345+ logging .warning ("Old firmware detected. Please update the firmware!" )
346+
347+ # If still not found, raise error
348+ if dev is None :
349+ logging .error ("No Reachy Mini Audio USB device found!" )
350+ return None
351+
346352 return ReSpeaker (dev )
353+
347354 except usb .core .NoBackendError :
348355 logging .error (
349- "No USB backend was found ! Make sure libusb_package is correctly installed with `pip install libusb_package`."
356+ "No USB backend was found! Make sure libusb_package is correctly installed with `pip install libusb_package`."
350357 )
351358 return None
352359
@@ -382,7 +389,12 @@ def main() -> None:
382389
383390 args = parser .parse_args ()
384391
385- dev = find (vid = args .vid , pid = args .pid )
392+ # Allow user overrides if provided, else use known defaults
393+ if args .vid is not None and args .pid is not None :
394+ dev = find (vid = args .vid , pid = args .pid )
395+ else :
396+ dev = init_respeaker_usb ()
397+
386398 if not dev :
387399 print ("No device found" )
388400 sys .exit (1 )
@@ -418,11 +430,18 @@ def main() -> None:
418430 print (f"{ args .command } : { result } " )
419431
420432 except Exception as e :
421- print (f"Error executing command { args .command } : { e } " )
433+ error_msg = f"Error executing command { args .command } : { e } "
434+ print (error_msg )
435+
436+ # Check if it's a permission error, so far only seen on Linux
437+ if "Errno 13" in str (e ) or "Access denied" in str (e ) or "insufficient permissions" in str (e ):
438+ print ("\n This looks like a permissions error." )
439+ print ("\n - You are most likely on Linux and need to adjust udev rules for USB permissions." )
440+ print ("\n - If you are not on Linux or have additional questions contact the team." )
422441 sys .exit (1 )
423442 finally :
424443 dev .close ()
425444
426445
427446if __name__ == "__main__" :
428- main ()
447+ main ()
0 commit comments