From a717c4658a79461628dd3a406fe41dda57c6a9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Voltz?= Date: Sun, 16 May 2010 07:37:34 +0200 Subject: [PATCH] add sanei_usb_reset function --- include/sane/sanei_usb.h | 6 ++++++ sanei/sanei_usb.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/sane/sanei_usb.h b/include/sane/sanei_usb.h index 5622db84c..a42120565 100644 --- a/include/sane/sanei_usb.h +++ b/include/sane/sanei_usb.h @@ -278,6 +278,12 @@ extern SANE_Status sanei_usb_clear_halt (SANE_Int dn); */ #define HAVE_SANEI_USB_CLEAR_HALT +/** Reset device + * + * @param dn device number + */ +extern SANE_Status sanei_usb_reset (SANE_Int dn); + /** Initiate a bulk transfer read. * * Read up to size bytes from the device to buffer. After the read, size diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index eed4ae451..aad77918b 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -2014,6 +2014,34 @@ sanei_usb_clear_halt (SANE_Int dn) return SANE_STATUS_GOOD; } +SANE_Status +sanei_usb_reset (SANE_Int dn) +{ +#ifdef HAVE_LIBUSB + int ret; + + ret = usb_reset (devices[dn].libusb_handle); + if (ret){ + DBG (1, "sanei_usb_reset: ret=%d\n", ret); + return SANE_STATUS_INVAL; + } + +#elif defined(HAVE_LIBUSB_1_0) + int ret; + + ret = libusb_reset_device (devices[dn].lu_handle); + if (ret){ + DBG (1, "sanei_usb_reset: ret=%d\n", ret); + return SANE_STATUS_INVAL; + } + +#else /* not HAVE_LIBUSB && not HAVE_LIBUSB_1_0 */ + DBG (1, "sanei_usb_reset: libusb support missing\n"); +#endif /* HAVE_LIBUSB || HAVE_LIBUSB_1_0 */ + + return SANE_STATUS_GOOD; +} + SANE_Status sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size) {