diff options
author | Paul Kocialkowski | 2016-02-24 11:14:14 +0100 |
---|---|---|
committer | Paul Kocialkowski | 2016-02-24 11:14:48 +0100 |
commit | 21aced27f7af7447b19b2017b5afdefbb55b71b3 (patch) | |
tree | 13a7c8c1e43b7871025f599dceec4adc4c0a708b /src/usb.c | |
parent | 9c8c5264252f98ffb8ad6a2285547d00dd242368 (diff) |
usb: Add Wait for device (-w) option
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'src/usb.c')
-rw-r--r-- | src/usb.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -18,6 +18,7 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> +#include <unistd.h> #include <sys/types.h> #include <libusb.h> @@ -39,8 +40,15 @@ int usb_open(struct context *context) return -1; } - handle = libusb_open_device_with_vid_pid(NULL, USB_VENDOR_LG, USB_DEVICE_DOWNLOAD); - if (handle == NULL) { + do { + handle = libusb_open_device_with_vid_pid(NULL, USB_VENDOR_LG, USB_DEVICE_DOWNLOAD); + if (handle != NULL) + break; + + usleep(300000); + } while (context->wait); + + if (handle == NULL) { fprintf(stderr, "Finding and opening USB device failed\n"); fprintf(stderr, "\nDevice might be missing or you may not have the rights to do this\n"); goto error; |