int FTDIDevice_Open(FTDIDevice *dev) { int err; memset(dev, 0, sizeof *dev); if ((err = libusb_init(&dev->libusb))) { return err; } libusb_set_debug(dev->libusb, 2); dev->handle = libusb_open_device_with_vid_pid(dev->libusb, OV_VENDOR, OV_PRODUCT); if (!dev->handle) { dev->handle = libusb_open_device_with_vid_pid(dev->libusb, FTDI_VENDOR, FTDI_PRODUCT_FT2232H); } if (!dev->handle) { return LIBUSB_ERROR_NO_DEVICE; } return DeviceInit(dev); }
/* Getting device handle */ int init () { libusb_init(NULL); libusb_set_debug(NULL, 3); // Wireless mode handle = libusb_open_device_with_vid_pid(NULL, DEV_VID, DEV_PID_Wireless); if (handle == NULL) { // Wired mode handle = libusb_open_device_with_vid_pid(NULL, DEV_VID, DEV_PID_Wired); if (handle == NULL) { printf("[Error] Naga Epic not found!\n"); libusb_exit(NULL); return 1; } else { printf("[Info] Naga Epic is connected\n"); } } else { printf("[Info] Naga Epic Dock is connected\n"); } // Detaching mouse from kernel if (libusb_kernel_driver_active(handle,DEV_INTF)) libusb_detach_kernel_driver(handle, DEV_INTF); if (libusb_claim_interface(handle, DEV_INTF) < 0) { printf("[Error] IO exception\n"); libusb_close(handle); libusb_exit(NULL); return 1; } return 0; }
int ADDCALL hackrf_open(hackrf_device** device) { libusb_device_handle* usb_device; if( device == NULL ) { return HACKRF_ERROR_INVALID_PARAM; } usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, hackrf_one_usb_pid); if( usb_device == NULL ) { usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, hackrf_jawbreaker_usb_pid); } if( usb_device == NULL ) { usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, rad1o_usb_pid); } if( usb_device == NULL ) { return HACKRF_ERROR_NOT_FOUND; } return hackrf_open_setup(usb_device, device); }
int main(int argc, char **argv) { void *data; unsigned sz; struct stat s; int fd; int ret; struct libusb_context *ctx = NULL; struct libusb_device_handle *usb = NULL; if (argc != 3) { printf("usage: %s <xloader> <rootfs>\n", argv[0]); return 0; } argv++; fd = open(argv[0], O_RDONLY); if (fd < 0 || fstat(fd, &s)) { printf("cannot open '%s'\n", argv[0]); return -1; } data = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (data == MAP_FAILED) { printf("cannot mmap '%s'\n", argv[0]); return -1; } sz = s.st_size; close(fd); argv++; if (libusb_init(&ctx)) { printf("cannot initialize libusb\n"); return -1; } printf(HFORMAT, HOST_FORMAT); printf("waiting for OMAP44xx device...\n"); while (1) { if (!usb) usb = libusb_open_device_with_vid_pid( ctx, 0x0451, 0xD010); if (!usb) usb = libusb_open_device_with_vid_pid( ctx, 0x0451, 0xD00F); if (usb) { libusb_detach_kernel_driver(usb, 0); ret = libusb_set_configuration(usb, 1); if (ret) break; ret = libusb_claim_interface(usb, 0); if (ret) break; ret = usb_boot(usb, data, sz, argv[0]); break; } usleep(250000); } libusb_release_interface(usb, 0); libusb_close(usb); libusb_exit(ctx); return ret; }
/* Setup is done once, after permission has been obtained. */ int usb_setup(void) { int rc = -1; rc = libusb_init(NULL); if (rc < 0) { LOGE("libusb_init: %s\n", libusb_error_name(rc)); return rc; } devh = libusb_open_device_with_vid_pid(NULL, VID, PID); if (!devh) { LOGE("libusb_open_device_with_vid_pid (%04x) failed.\n", PID); /* Try opening Mark's rigblaster. */ devh = libusb_open_device_with_vid_pid(NULL, VID, 0x2904); if (!devh) { LOGE("libusb_open_device_with_vid_pid (0x2904) failed.\n"); rc = -1; goto out; } } rc = libusb_kernel_driver_active(devh, IFACE_NUM); if (rc == 1) { rc = libusb_detach_kernel_driver(devh, IFACE_NUM); if (rc < 0) { LOGE("libusb_detach_kernel_driver: %s.\n", libusb_error_name(rc)); goto out; } } rc = libusb_claim_interface(devh, IFACE_NUM); if (rc < 0) { LOGE("libusb_claim_interface: %s.\n", libusb_error_name(rc)); goto out; } rc = libusb_set_interface_alt_setting(devh, IFACE_NUM, 1); if (rc < 0) { LOGE("libusb_set_interface_alt_setting: %s.\n", libusb_error_name(rc)); goto out; } LOGD("Opened USB device %04x:%04x IFACE %d.\n", VID, PID, IFACE_NUM); is_setup = true; return 0; out: LOGE("Failed to setup USB\n"); if (devh) libusb_close(devh); libusb_exit(NULL); return rc; }
void device_connect() { if ((device = libusb_open_device_with_vid_pid(NULL, VENDOR_ID, RECV_MODE)) == NULL) { if ((device = libusb_open_device_with_vid_pid(NULL, VENDOR_ID, WTF_MODE)) == NULL) { if ((device = libusb_open_device_with_vid_pid(NULL, VENDOR_ID, DFU_MODE)) == NULL) { } } } }
//this is for K4W or 1473 devices - pass in the PID of the audio device that needs the LED set. void freenect_extra_keep_alive(int pid){ int res; int state_to_set = 3; libusb_context* ctx = NULL; libusb_init(&ctx); libusb_device_handle* dev = NULL; //check the default audio device dev = libusb_open_device_with_vid_pid(ctx, 0x045e, pid); //K4W only: //if the firmware is uploaded the device could have a two different PIDs based on which firmware was uploaded. //so we have to check for both //note: it might be better if we pass in the PID of the camera and then find the audio device that is in the same usb tree/hub - might be more reliable when multiple devices are plugged in if( dev == NULL && pid == PID_K4W_AUDIO ){ pid = PID_K4W_AUDIO_ALT_1; dev = libusb_open_device_with_vid_pid(ctx, 0x045e, pid); } if( dev == NULL && pid == PID_K4W_AUDIO_ALT_1 ){ pid = PID_K4W_AUDIO_ALT_2; dev = libusb_open_device_with_vid_pid(ctx, 0x045e, pid); } if(dev == NULL) { LOG("freenect extra keepAlive: Failed to open audio device\n"); libusb_exit(ctx); return; } res = libusb_claim_interface(dev, 0); if (res != 0) { LOG("freenect extra keepAlive: Failed to claim interface 1: %d\n", res); libusb_close(dev); libusb_exit(ctx); return; } res = set_led(dev, state_to_set); if (res != 0) { LOG("freenect extra keepAlive: set_led failed\n"); libusb_close(dev); libusb_exit(ctx); return; } libusb_close(dev); libusb_exit(ctx); }
int set_native_mode(wheelstruct* w) { // first check if wheel has restriced/native mode at all if (w->native_pid == w->restricted_pid) { printf( "%s is always in native mode.\n", w->name); return 0; } // check if wheel is already in native mode libusb_device_handle *handle = libusb_open_device_with_vid_pid(NULL, VID_LOGITECH, w->native_pid); if ( handle != NULL ) { printf( "Found a %s already in native mode.\n", w->name); return 0; } // try to get handle to device in restricted mode handle = libusb_open_device_with_vid_pid(NULL, VID_LOGITECH, w->restricted_pid ); if ( handle == NULL ) { printf( "Can not find %s in restricted mode (PID %x). This should not happen :-(\n", w->name, w->restricted_pid); return -1; } // check if we know how to set native mode if (!w->get_nativemode_cmd) { printf( "Sorry, do not know how to set %s into native mode.\n", w->name); return -1; } cmdstruct c; memset(&c, 0, sizeof(c)); w->get_nativemode_cmd(&c); send_command(handle, c); // wait until wheel reconfigures to new PID... sleep(CONFIGURE_WAIT_SEC); // If above command was successfully we should now find the wheel in extended mode handle = libusb_open_device_with_vid_pid(NULL, VID_LOGITECH, w->native_pid); if ( handle != NULL ) { printf ( "%s is now set to native mode.\n", w->name); } else { // this should not happen, just in case printf ( "Unable to set %s to native mode.\n", w->name ); return -1; } return 0; }
int main(void) { // Change these as needed to match idVendor and idProduct in your device's device descriptor. static const int VENDOR_ID = 0x03eb; static const int PRODUCT_ID = 0x204f; struct libusb_device_handle *devh = NULL; int device_ready = 0; int result; result = libusb_init(NULL); if (result >= 0) { devh = libusb_open_device_with_vid_pid(NULL, VENDOR_ID, PRODUCT_ID); if (devh != NULL) { // The HID has been detected. // Detach the hidusb driver from the HID to enable using libusb. libusb_detach_kernel_driver(devh, INTERFACE_NUMBER); { result = libusb_claim_interface(devh, INTERFACE_NUMBER); if (result >= 0) { device_ready = 1; } else { fprintf(stderr, "libusb_claim_interface error %d\n", result); } } } else { fprintf(stderr, "Unable to find the device.\n"); } } else { fprintf(stderr, "Unable to initialize libusb.\n"); } if (device_ready) { // Send and receive data. //exchange_input_and_output_reports_via_interrupt_transfers(devh); exchange_input_and_output_reports_via_control_transfers(devh); exchange_feature_reports_via_control_transfers(devh); // Finished using the device. libusb_release_interface(devh, 0); } libusb_close(devh); libusb_exit(NULL); return 0; }
int USBLink::open() { libusb_init(&m_context); m_handle = libusb_open_device_with_vid_pid(m_context, PIXY_VID, PIXY_DID); if (m_handle==NULL) return -1; #ifdef __MACOS__ libusb_reset_device(m_handle); Sleeper::msleep(100); #endif if (libusb_set_configuration(m_handle, 1)<0) { libusb_close(m_handle); m_handle = 0; return -1; } if (libusb_claim_interface(m_handle, 1)<0) { libusb_close(m_handle); m_handle = 0; return -1; } return 0; }
struct cp_usb_async * cp_usb_async_open(void) { struct cp_usb_async *cp; int ret; cp = calloc(sizeof (struct cp_usb_async), 1); if (!cp) return NULL; ret = libusb_init(&cp->ctx); if (ret) { free(cp); return NULL; } cp->handle = libusb_open_device_with_vid_pid(cp->ctx, 0x10c4, 0xea60); cp->ack = -1; if (!cp->handle) { fprintf(stderr, "Cannot find USB device 10c4:ea60\n"); libusb_exit(cp->ctx); free(cp); return NULL; } cp->value = 0; cp->set = 0; return cp; }
int main(int argc, char **argv) { //Pass Interrupt Signal to our handler signal(SIGINT, sighandler); libusb_init(&ctx); libusb_set_debug(ctx, 3); //Open Device with VendorID and ProductID handle = libusb_open_device_with_vid_pid(ctx, USB_VENDOR_ID, USB_PRODUCT_ID); if (!handle) { perror("device not found"); return 1; } int r = 1; //Claim Interface 0 from the device r = libusb_claim_interface(handle, 0); if (r < 0) { fprintf(stderr, "usb_claim_interface error %d\n", r); return 2; } printf("Interface claimed\n"); while (1){ usb_read(); // usb_write(); } //never reached libusb_close(handle); libusb_exit(NULL); return 0; }
int libusb_show_device(uint16_t vendor_id, uint16_t product_id) { struct libusb_device_handle *handle; struct libusb_device_descriptor desc; struct libusb_config_descriptor **config; int ret = 0, i, config_size; handle = libusb_open_device_with_vid_pid(NULL, vendor_id, product_id); if (handle == NULL) return -EIO; ret = libusb_get_device_descriptor(handle->dev, &desc); if (ret < 0) return -EINVAL; printf("usb device has %d configurations \n", desc.bNumConfigurations); config_size = sizeof(struct libusb_config_descriptor *) * desc.bNumConfigurations; config = (struct libusb_config_descriptor **) malloc(config_size); for (i = 0; i < desc.bNumConfigurations; i++) { ret = libusb_get_config_descriptor(handle->dev, i, &config[i]); if (ret < 0) { free(config); return -EINVAL; } } for (i = 0; i < desc.bNumConfigurations; i++) { show_config(config[i], i); } }
int main(int argc, char **argv) { const char *filename; int fd; int rc; if (argc != 2) print_help_and_exit(argv); int result, vid, pid; result = sscanf(argv[1], "%x:%x", &vid, &pid); if(!result) print_help_and_exit(argv); libusb_init(NULL); libusb_device_handle *handle = libusb_open_device_with_vid_pid(NULL, vid, pid); if(!handle) { fprintf(stderr, "Couldn't open device\n"); return 1; } result = libusb_reset_device(handle); if(!handle) { fprintf(stderr, "Couldn't reset device\n"); return 1; } return 0; }
minipro_handle_t *minipro_open(device_t *device) { int ret; minipro_handle_t *handle = malloc(sizeof(minipro_handle_t)); if(handle == NULL) { ERROR("Couldn't malloc"); } ret = libusb_init(&(handle->ctx)); if(ret < 0) { free(handle); ERROR2("Error initializing libusb: %s", libusb_error_name(ret)); } handle->usb_handle = libusb_open_device_with_vid_pid(handle->ctx, 0x04d8, 0xe11c); if(handle->usb_handle == NULL) { free(handle); ERROR("Error opening device"); } // we need to do this as it is possible that the device was not closed properly in a previous session // if we do not do this and the device was not closed properly it will cause an infinite hang // see: https://github.com/OpenKinect/libfreenect/blob/80f74239db4d450ecc0e45aa8b89cfcbc35defc2/src/usb_libusb10.c#L328 libusb_reset_device(handle->usb_handle); handle->device = device; return(handle); }
int main (int argc, char *argv[]) { int err; struct libusb_device_handle* handle; if ((err = libusb_init (&ctx)) != 0) { printf ("libusb_init failed with code %d\n", err); return 1; } libusb_set_debug (ctx, 3); handle = libusb_open_device_with_vid_pid (ctx, GTP_VENDOR, GTP_PRODUCT); if (!handle) printf ("LCD-USB device not found\n"); else { libusb_claim_interface (handle, 0); printf ("LCD-USB device found, version = %s\n", lcd_get_version (handle)); } libusb_close (handle); libusb_exit (ctx); return 0; }
int connectAccessory(void) { int response; int tries = 5; /* Try connecting to Accessory device with proper PID/VID */ for(;;){ tries--; if((handle = libusb_open_device_with_vid_pid(NULL, ACCESSORY_VID, ACCESSORY_PID_DBG)) == NULL){ if(tries < 0){ return -1; } }else{ break; } sleep(1); } /* Set configuration to 1 as per ADK protocol */ response = libusb_set_configuration(handle, 1); if(response < 0){ error(response); return -1; } response = libusb_claim_interface(handle, 0); if(response < 0){ error(response); return -1; } fprintf(stdout, "Interface claimed, ready to transfer data\n"); return 0; }
static int scan_usb(libusb_context *ctx, libusb_device_handle **dev_handle) { libusb_device **devs; const int ret = libusb_init(&ctx); if (ret < 0) { fprintf(stderr, "%s\n", libusb_strerror(ret)); return -1; } libusb_set_debug(ctx, _debug > 3 ? 3 : _debug); const ssize_t cnt = libusb_get_device_list(ctx, &devs); if (cnt == 0) { fprintf(stderr, "Could not get device list: %s\n", libusb_strerror(ret)); return -1; } *dev_handle = libusb_open_device_with_vid_pid(ctx, OWL_VENDOR_ID, CM160_DEV_ID); libusb_free_device_list(devs, 1); if (!*dev_handle) { fprintf(stderr, "Could not find an OWL CM160 plugged.\n"); return -1; } return 0; }
libusb_device_handle * open_vid_pid(struct mach_id *mach, struct sdp_dev *p_id) { int r = libusb_init(NULL); int err; libusb_device_handle *h; h = libusb_open_device_with_vid_pid(NULL, mach->vid, mach->pid); if (!h) { printf("%s:Could not open device vid=0x%x pid=0x%x\n", __func__, mach->vid, mach->pid); goto err1; } if (libusb_kernel_driver_active(h, 0)) libusb_detach_kernel_driver(h, 0); err = libusb_claim_interface(h, 0); if (err) { printf("claim failed, err=%i\n", err); goto err2; } err = do_status(p_id); if (!err) return h; printf("status failed, err=%i\n", err); err2: libusb_release_interface(h, 0); libusb_close(h); err1: libusb_exit(NULL); return NULL; }
bool is_accessory_present(accessory_t *acc) { struct libusb_device_handle *handle; static const uint16_t aoa_pids[] = { AOA_ACCESSORY_PID, AOA_ACCESSORY_ADB_PID, AOA_AUDIO_PID, AOA_AUDIO_ADB_PID, AOA_ACCESSORY_AUDIO_PID, AOA_ACCESSORY_AUDIO_ADB_PID }; /* Trying to open all the AOA IDs possible */ for (size_t i = 0; i < sizeof(aoa_pids) / sizeof(aoa_pids[0]); i++) { uint16_t vid = AOA_ACCESSORY_VID; uint16_t pid = aoa_pids[i]; if (acc->vid == vid && acc->pid == pid) { handle = libusb_open_device_with_vid_pid(NULL, vid, pid); if (handle != NULL) { printf("Found accessory %4.4x:%4.4x\n", vid, pid); acc->handle = handle; return true; } /* present, but unable open device */ return false; } } /* not present */ return false; }
int main (int argc, char *argv[]) { struct libusb_context *ctx; struct libusb_device_handle *handle; int err; if ((err = libusb_init (&ctx)) != 0) { printf ("libusb_init failed with clode %d\n", err); return 1; } // libusb_set_debug (ctx, 3); while (1) { handle = libusb_open_device_with_vid_pid (ctx, BOAT_VENDOR, BOAT_PRODUCT); if (!handle) { printf ("Boat USB device not found, sleep for 10 seconds and try again\n"); sleep (10); } else { printf ("Boat device found, open master socket\n"); libusb_claim_interface (handle, 0); run_daemon (handle); libusb_close (handle); break; } } libusb_exit (ctx); return 0; }
bool UsbComm::open() { if (dh_ != 0) { close(); } if (libusb_init(&ctx_) < 0) { throw std::runtime_error("Error opening libusb"); } // todo: parse vid/pid out of name_ dh_ = libusb_open_device_with_vid_pid(ctx_, 0xf000, 0x0001); if (dh_ == 0) { throw std::runtime_error("Could not find USB device 0xf000/0x0001 for comm board."); } libusb_device_descriptor ldd; int er; er = libusb_get_device_descriptor(libusb_get_device(dh_), &ldd); if (er < 0) { throw std::runtime_error("Could not find USB descriptor for comm board."); } er = libusb_set_configuration(dh_, 1); if (er < 0) { throw std::runtime_error("Could not set configuration on comm board."); } er = libusb_claim_interface(dh_, 0); if (er < 0) { throw std::runtime_error("Could not claim USB interface for comm board. Is another process using it?"); } running_ = true; thread_ = new boost::thread(boost::bind(&UsbComm::read_func, this)); return true; }
/* external interface for testing */ struct fp_img_dev *global_init(void) { int ret; struct fp_img_dev *dev; ret = libusb_init(&fpi_usb_ctx); if (ret != LIBUSB_SUCCESS) { fp_err("libusb_init failed %d", ret); goto cantclaim; } dev = malloc(sizeof(struct fp_img_dev)); if (dev == NULL) { fp_err("cannot allocate memory"); goto cantclaim; } dev->udev = libusb_open_device_with_vid_pid(fpi_usb_ctx, 0x1c7a, 0x0603); if (dev->udev == NULL) { fp_err("libusb_open_device_with_vid_pid failed"); free(dev); dev = NULL; goto cantclaim; } if (dev_init(dev, 0x0603)) dev = NULL; cantclaim: return dev; }
int main(int argc, char *argv[]) { int err; libusb_init(NULL); libusb_set_debug(NULL, 3); /* Try to open directly accessory. If it's not there, try to switch phone to it */ handle = libusb_open_device_with_vid_pid(NULL, ACCESSORY_VID, ACCESSORY_PID_DBG); //if(handle) //libusb_reset_device(handle); if(handle == NULL){ printf("Device not in Accessory mode. Trying to switch it to it...\n"); err = setupAccessory("STMicroelectronics", "adkping", "Just pings data", "2.0", "http://www.st.com", "1234567890123456"); if(err < 0){ fprintf(stdout, "Sorry, can't set up accessory, giving up\n"); deInit(); return -1; } } /* Do some stuff */ if(mainPhase() < 0){ fprintf(stdout, "Error during main phase\n"); deInit(); return -1; } deInit(); fprintf(stdout, "Done, no errors\n"); return 0; }
int cyusb_open_exact(unsigned short vid, unsigned short pid) { int r; cyusb_handle *h = NULL; r = libusb_init(NULL); if (r) { printf("Error in initializing libusb library...\n"); return -1; } h = libusb_open_device_with_vid_pid(NULL, vid, pid); if ( !h ) { printf("Device not found\n"); return -2; } cydev[0].dev = libusb_get_device(h); cydev[0].handle = h; cydev[nid].vid = cyusb_getvendor(h); cydev[nid].pid = cyusb_getproduct(h); cydev[nid].is_open = 1; cydev[nid].busnum = cyusb_get_busnumber(h); cydev[nid].devaddr = cyusb_get_devaddr(h); nid = 1; return 1; }
int main(int argc, char* argv[]) { libusb_context* ctx; libusb_init(&ctx); libusb_device_handle* hndl = libusb_open_device_with_vid_pid(ctx,0x04b4,0x1004); libusb_claim_interface(hndl,0); libusb_set_interface_alt_setting(hndl,0,0); unsigned short buf[100]; for (int i=0;i<100;++i) { buf[i]=i; } int transferred; int rv=libusb_bulk_transfer(hndl,0x02,(unsigned char*)buf,sizeof(buf),&transferred,100); if(rv) { printf ( "OUT Transfer failed: %d\n", rv ); return rv; } unsigned short buf2[100]; rv=libusb_bulk_transfer(hndl,0x86,(unsigned char*)buf2,sizeof(buf2),&transferred,100); if(rv) { printf ( "IN Transfer failed: %d\n", rv ); return rv; } for (int i=0;i<100;++i) { printf ( "%d ", buf2[i] ); } printf("\n"); return 0; }
int InitDevice(AlienFxType_t *all, AlienFxHandle_t *fxh) { int succp = 0; if(0 == libusb_init( & fxh->usb_context)) { libusb_set_debug(fxh->usb_context, 3); int i; for(i = 0 ; (i < AlienFxTypesCount) && ! succp ; ++i) { AlienFxType_t *fxtype = &all[i]; if(verbose) printf("scanning for AlienFX type \"%s\"... ", fxtype->name); if(fxh->usb_handle = libusb_open_device_with_vid_pid(fxh->usb_context, fxtype->idVendor, fxtype->idProduct)) { fxh->info = fxtype; if(verbose) printf("found \"%s\".\n", fxh->info->name); succp = 1; } else if(verbose) puts("no."); } if(fxh->usb_handle) { Detach(fxh->usb_handle); if(0 > libusb_claim_interface(fxh->usb_handle, 0)) { perror("libusb_claim_interface"); fxh->usb_handle = 0; } } } else perror("libusb_init"); return succp; }
int access_button(){ int ret; libusb_init(NULL); //I access the device devh = libusb_open_device_with_vid_pid(NULL, 0x1d34, 0x000d); if (devh == NULL ){ printf("Device not found or you don't have permissions to get to it. (Try root)\n"); return -1; } if ( libusb_kernel_driver_active(devh,0)){ printf("Detach from kernel\n"); ret = libusb_detach_kernel_driver(devh,0); if (ret < 0 ){ printf("Can't detach\n"); return -1; } } }
/* Find a PMD1208FS device. Return a device handle, or NULL. */ libusb_device_handle* pmd_find_first(void) { int i, ret; libusb_device_handle* pmd; ret = libusb_init(NULL); if (ret) { err("failed to init libusb: %s\n", usb_get_errmsg(ret)); return NULL; } pmd = libusb_open_device_with_vid_pid(NULL, PMD_VID, PMD_PID); if (!pmd) { err("device not found\n"); libusb_exit(NULL); return NULL; } for(i = 0; i < 4; i++) { libusb_detach_kernel_driver(pmd, i); } libusb_reset_device(pmd); /* fixes odd-number-of-operations timeout */ libusb_set_configuration(pmd, 1); for(i = 0; i < 4; i++) { ret = libusb_claim_interface(pmd, i); if (ret) { err("failed to claim interface: %s\n", usb_get_errmsg(ret)); libusb_close(pmd); libusb_exit(NULL); return NULL; } } return pmd; }
int main(int argc, char **argv) { int res; libusb_device_handle *dev; printf("Kinect camera test\n"); int i; for (i=0; i<2048; i++) { float v = i/2048.0; v = powf(v, 3)* 6; t_gamma[i] = v*6*256; } g_argc = argc; g_argv = argv; libusb_init(NULL); dev = libusb_open_device_with_vid_pid(NULL, 0x45e, 0x2ae); if (!dev) { printf("Could not open device\n"); return 1; } res = pthread_create(&gl_thread, NULL, gl_threadfunc, NULL); if (res) { printf("pthread_create failed\n"); return 1; } cams_init(dev, depthimg, rgbimg); while(!die && libusb_handle_events(NULL) == 0); pthread_exit(NULL); }