sanei_usb: Add function sanei_usb_get_endpoint, add range check in sanei_usb_set_endpoint

Since we now have the possibility to change the endpoint used for a particular USB communication type,
we also need a way to retrieve the current endpoint, so that one can e.g. reset the endpoint to the
old value after a single usb operation on a different endpoint.
merge-requests/1/head
Reinhold Kainhofer 2011-01-31 21:13:28 +01:00
rodzic 58d5d64e00
commit c0b26b4568
2 zmienionych plików z 51 dodań i 0 usunięć

Wyświetl plik

@ -267,6 +267,19 @@ extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn);
*/
extern void sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep);
/** Retrieve the endpoint used for the USB communication
*
* Returns the endpoint used for the USB communication of the given type.
* This function can only be called after sanei_usb_open.
*
* @param dn device number
* @param ep_type type of endpoint to retrieve (bitwise or of USB_DIR_IN/OUT
* and USB_ENDPOINT_TYPE_BULK/CONTROL/INTERRUPT/ISOCHRONOUS
* @return endpoint used for the given type
*
*/
extern SANE_Int sanei_usb_get_endpoint (SANE_Int dn, SANE_Int ep_type);
/** Close a USB device.
*
* @param dn device number

Wyświetl plik

@ -1108,6 +1108,12 @@ sanei_usb_find_devices (SANE_Int vendor, SANE_Int product,
void
sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep)
{
if (dn >= device_number || dn < 0)
{
DBG (1, "sanei_usb_set_endpoint: dn >= device number || dn < 0\n");
return;
}
DBG (5, "sanei_usb_set_endpoint: Setting endpoint of type 0x%02x to 0x%02x\n", ep_type, ep);
switch (ep_type)
{
@ -1138,6 +1144,38 @@ sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep)
}
}
SANE_Int
sanei_usb_get_endpoint (SANE_Int dn, SANE_Int ep_type)
{
if (dn >= device_number || dn < 0)
{
DBG (1, "sanei_usb_get_endpoint: dn >= device number || dn < 0\n");
return 0;
}
switch (ep_type)
{
case USB_DIR_IN|USB_ENDPOINT_TYPE_BULK:
return devices[dn].bulk_in_ep;
case USB_DIR_OUT|USB_ENDPOINT_TYPE_BULK:
return devices[dn].bulk_out_ep;
case USB_DIR_IN|USB_ENDPOINT_TYPE_ISOCHRONOUS:
return devices[dn].iso_in_ep;
case USB_DIR_OUT|USB_ENDPOINT_TYPE_ISOCHRONOUS:
return devices[dn].iso_out_ep;
case USB_DIR_IN|USB_ENDPOINT_TYPE_INTERRUPT:
return devices[dn].int_in_ep;
case USB_DIR_OUT|USB_ENDPOINT_TYPE_INTERRUPT:
return devices[dn].int_out_ep;
case USB_DIR_IN|USB_ENDPOINT_TYPE_CONTROL:
return devices[dn].control_in_ep;
case USB_DIR_OUT|USB_ENDPOINT_TYPE_CONTROL:
return devices[dn].control_out_ep;
default:
return 0;
}
}
SANE_Status
sanei_usb_open (SANE_String_Const devname, SANE_Int * dn)
{