2323#include < assert.h>
2424#include < iostream>
2525#include < iomanip>
26- #include < libusb.h>
2726#include < bitset>
2827
2928
@@ -459,7 +458,7 @@ int XhcWhb04b6Component::run()
459458 *mInitCout << " ok" << endl;
460459 }
461460 process ();
462- teardownUsb ();
461+ mUsb . teardown ();
463462 }
464463 }
465464 teardownHal ();
@@ -483,34 +482,13 @@ void XhcWhb04b6Component::setSimulationMode(bool enableSimulationMode)
483482 mUsb .setSimulationMode (mIsSimulationMode );
484483}
485484// ----------------------------------------------------------------------
486- void XhcWhb04b6Component::setUsbContext (libusb_context* context)
487- {
488- mUsb .setContext (context);
489- }
490- // ----------------------------------------------------------------------
491- libusb_device_handle* XhcWhb04b6Component::getUsbDeviceHandle ()
492- {
493- return mUsb .getDeviceHandle ();
494- }
495- // ----------------------------------------------------------------------
496- libusb_context* XhcWhb04b6Component::getUsbContext ()
497- {
498- return mUsb .getContext ();
499- }
500- // ----------------------------------------------------------------------
501485void XhcWhb04b6Component::process ()
502486{
503487 if (mUsb .isDeviceOpen ())
504488 {
505489 while (isRunning () && !mUsb .getDoReconnect ())
506490 {
507- struct timeval timeout;
508- timeout.tv_sec = 0 ;
509- timeout.tv_usec = 200 * 1000 ;
510-
511- int r = libusb_handle_events_timeout_completed (getUsbContext (), &timeout, nullptr );
512- assert ((r == LIBUSB_SUCCESS) || (r == LIBUSB_ERROR_NO_DEVICE) || (r == LIBUSB_ERROR_BUSY) ||
513- (r == LIBUSB_ERROR_TIMEOUT) || (r == LIBUSB_ERROR_INTERRUPTED));
491+ mUsb .handleTimeouts ();
514492 if (mHal .isSimulationModeEnabled ())
515493 {
516494 linuxcncSimulate ();
@@ -521,24 +499,10 @@ void XhcWhb04b6Component::process()
521499
522500 mHal .setIsPendantConnected (false );
523501 *mInitCout << " connection lost, cleaning up" << endl;
524- struct timeval tv;
525- tv.tv_sec = 1 ;
526- tv.tv_usec = 0 ;
527- int r = libusb_handle_events_timeout_completed (getUsbContext (), &tv, nullptr );
528- assert (0 == r);
529- r = libusb_release_interface (getUsbDeviceHandle (), 0 );
530- assert ((0 == r) || (r == LIBUSB_ERROR_NO_DEVICE));
531- libusb_close (getUsbDeviceHandle ());
532- mUsb .setDeviceHandle (nullptr );
502+ mUsb .close ();
533503 }
534504}
535505// ----------------------------------------------------------------------
536- void XhcWhb04b6Component::teardownUsb ()
537- {
538- libusb_exit (getUsbContext ());
539- mUsb .setContext (nullptr );
540- }
541- // ----------------------------------------------------------------------
542506void XhcWhb04b6Component::enableVerbosePendant (bool enable)
543507{
544508 mPendant .enableVerbose (enable);
0 commit comments