aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2016-02-24 10:14:14 (GMT)
committerPaul Kocialkowski <contact@paulk.fr>2016-02-24 10:14:48 (GMT)
commit21aced27f7af7447b19b2017b5afdefbb55b71b3 (patch)
tree13a7c8c1e43b7871025f599dceec4adc4c0a708b
parent9c8c5264252f98ffb8ad6a2285547d00dd242368 (diff)
downloadlg-downloader-21aced27f7af7447b19b2017b5afdefbb55b71b3.zip
lg-downloader-21aced27f7af7447b19b2017b5afdefbb55b71b3.tar.gz
lg-downloader-21aced27f7af7447b19b2017b5afdefbb55b71b3.tar.bz2
usb: Add Wait for device (-w) option
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--src/lg-downloader.c5
-rw-r--r--src/lg-downloader.h1
-rw-r--r--src/usb.c12
3 files changed, 15 insertions, 3 deletions
diff --git a/src/lg-downloader.c b/src/lg-downloader.c
index fd71a65..827cc4b 100644
--- a/src/lg-downloader.c
+++ b/src/lg-downloader.c
@@ -34,7 +34,8 @@ static int usage_print(void)
printf("Usage: lg-downloader [OPTIONS] [OPERATION]\n\n"
"Options:\n"
" -h help\n"
- " -v verbose\n\n"
+ " -v verbose\n"
+ " -w wait for device\n\n"
"Operations:\n"
" reboot reboot device\n"
" erase [partition] [filename] erase a partition\n"
@@ -89,6 +90,8 @@ static int arguments_parse(struct context *context, int argc, char *argv[])
context->operation = 'h';
} else if (strcmp(argv[i], "-v") == 0) {
context->verbose = 1;
+ } else if (strcmp(argv[i], "-w") == 0) {
+ context->wait = 1;
} else {
return -1;
}
diff --git a/src/lg-downloader.h b/src/lg-downloader.h
index 9a7984b..4e7ff2a 100644
--- a/src/lg-downloader.h
+++ b/src/lg-downloader.h
@@ -28,6 +28,7 @@
struct context {
struct libusb_device_handle *usb_handle;
int verbose;
+ int wait;
char operation;
char *partition;
diff --git a/src/usb.c b/src/usb.c
index 5742d7b..95bf14a 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -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;