opendevice.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. * ___.
  11. * __ __ _____\_ |__
  12. * | | \/ ___/| __ \
  13. * | | /\___ \ | \_\ \
  14. * |____//____ >|___ /
  15. * \/ \/
  16. *
  17. * www.optixx.org
  18. *
  19. *
  20. * Version: 1.0
  21. * Created: 07/21/2009 03:32:16 PM
  22. * Author: david@optixx.org
  23. * Based on: custom-class, a basic USB example
  24. * Author: Christian Starkjohann
  25. * =====================================================================================
  26. */
  27. #ifndef __OPENDEVICE_H_INCLUDED__
  28. #define __OPENDEVICE_H_INCLUDED__
  29. #include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */
  30. #include <stdio.h>
  31. int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen);
  32. /* This function gets a string descriptor from the device. 'index' is the
  33. * string descriptor index. The string is returned in ISO Latin 1 encoding in
  34. * 'buf' and it is terminated with a 0-character. The buffer size must be
  35. * passed in 'buflen' to prevent buffer overflows. A libusb device handle
  36. * must be given in 'dev'.
  37. * Returns: The length of the string (excluding the terminating 0) or
  38. * a negative number in case of an error. If there was an error, use
  39. * usb_strerror() to obtain the error message.
  40. */
  41. int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp);
  42. /* This function iterates over all devices on all USB busses and searches for
  43. * a device. Matching is done first by means of Vendor- and Product-ID (passed
  44. * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard).
  45. * When a device matches by its IDs, matching by names is performed. Name
  46. * matching can be done on textual vendor name ('vendorNamePattern'), product
  47. * name ('productNamePattern') and serial number ('serialNamePattern'). A
  48. * device matches only if all non-null pattern match. If you don't care about
  49. * a string, pass NULL for the pattern. Patterns are Unix shell style pattern:
  50. * '*' stands for 0 or more characters, '?' for one single character, a list
  51. * of characters in square brackets for a single character from the list
  52. * (dashes are allowed to specify a range) and if the lis of characters begins
  53. * with a caret ('^'), it matches one character which is NOT in the list.
  54. * Other parameters to the function: If 'warningsFp' is not NULL, warning
  55. * messages are printed to this file descriptor with fprintf(). If
  56. * 'printMatchingDevicesFp' is not NULL, no device is opened but matching
  57. * devices are printed to the given file descriptor with fprintf().
  58. * If a device is opened, the resulting USB handle is stored in '*device'. A
  59. * pointer to a "usb_dev_handle *" type variable must be passed here.
  60. * Returns: 0 on success, an error code (see defines below) on failure.
  61. */
  62. /* usbOpenDevice() error codes: */
  63. #define USBOPEN_SUCCESS 0 /* no error */
  64. #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
  65. #define USBOPEN_ERR_IO 2 /* I/O error */
  66. #define USBOPEN_ERR_NOTFOUND 3 /* device not found */
  67. /* Obdev's free USB IDs, see USBID-License.txt for details */
  68. #define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */
  69. #define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */
  70. #define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */
  71. #define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */
  72. #define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */
  73. #endif /* __OPENDEVICE_H_INCLUDED__ */