]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - flash-hmcfgusb.c
README: Homegear now knows about HM-USB-IF
[hmcfgusb] / flash-hmcfgusb.c
index 571386f8b1bc5e49acc84c84ef0d4444dac9c499..a9ff876d75557bc8a230910cc3936e1cb83f1324 100644 (file)
@@ -93,17 +93,16 @@ int main(int argc, char **argv)
 
        if (!dev->bootloader) {
                fprintf(stderr, "\nHM-CFG-USB not in bootloader mode, entering bootloader.\n");
-               hmcfgusb_enter_bootloader(dev);
                fprintf(stderr, "\nWaiting for device to reappear...\n");
 
                do {
-                       sleep(2);
-               } while ((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL);
-
-               if (!dev->bootloader) {
-                       fprintf(stderr, "Can't enter bootloader, giving up!\n");
-                       exit(EXIT_FAILURE);
-               }
+                       if (dev) {
+                               if (!dev->bootloader)
+                                       hmcfgusb_enter_bootloader(dev);
+                               hmcfgusb_close(dev);
+                       }
+                       sleep(1);
+               } while (((dev = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (!dev->bootloader));
        }
 
        printf("\nHM-CFG-USB opened.\n\n");
@@ -136,10 +135,12 @@ int main(int argc, char **argv)
                        printf("Waiting for ack...\n");
                do {
                        errno = 0;
-                       pfd = hmcfgusb_poll(dev, 1);
+                       pfd = hmcfgusb_poll(dev, 1000);
                        if ((pfd < 0) && errno) {
-                               perror("\n\nhmcfgusb_poll");
-                               exit(EXIT_FAILURE);
+                               if (errno != ETIMEDOUT) {
+                                       perror("\n\nhmcfgusb_poll");
+                                       exit(EXIT_FAILURE);
+                               }
                        }
                        if (rdata.ack) {
                                break;
@@ -165,6 +166,7 @@ int main(int argc, char **argv)
        firmware_free(fw);
 
        hmcfgusb_close(dev);
+       hmcfgusb_exit();
 
        return EXIT_SUCCESS;
 }
Impressum, Datenschutz