-
-int gl_open(int vid)
-{
- int ret;
- struct libusb_device **devs;
- struct libusb_device *dev;
- size_t i = 0;
- struct libusb_device_descriptor desc;
-
- ret = libusb_init(NULL);
- if (ret < 0)
- return GL_ELIBUSB;
-
- libusb_set_debug(NULL, 0);
-
- if (libusb_get_device_list(NULL, &devs) < 0) {
- ret = GL_EOPEN;
- goto gl_open_error;
- }
-
- while ((dev = devs[i++]) != NULL) {
- if (libusb_get_device_descriptor(dev, &desc) < 0)
- break;
-
- if (desc.idVendor == vid) {
- if (libusb_open(dev, &g_devh) < 0)
- g_devh = NULL;
- break;
- }
- }
-
- libusb_free_device_list(devs, 1);
-
- if (!g_devh) {
- ret = GL_EOPEN;
- goto gl_open_error;
- }
-
- ret = libusb_set_configuration(g_devh, 1);
- if (ret < 0) {
- ret = GL_ESETCONFIG;
- goto gl_open_error;
- }
-
- ret = libusb_claim_interface(g_devh, 0);
- if (ret < 0) {
- ret = GL_ECLAIM;
- goto gl_open_error;
- }
-
- return GL_OK;
-
-gl_open_error:
- gl_close();
- return ret;
-}
-
-int gl_close(void)
-{
- if (g_devh) {
- libusb_release_interface(g_devh, 0);
- libusb_reset_device(g_devh);
- libusb_close(g_devh);
- }
- libusb_exit(NULL);
-
- return 0;
-}