altosui: Retry device enumeration after rebooting for self flash
authorKeith Packard <keithp@keithp.com>
Sat, 1 Mar 2014 05:16:57 +0000 (21:16 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 1 Mar 2014 05:16:57 +0000 (21:16 -0800)
Windows takes 'a while' to include the rebooted device in the list of
available devices, so try a few times with a 100ms delay so that we
can avoid asking the user to select from an empty list.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosFlashUI.java

index 5913e50699c2f390a597b1b828407476f608661f..793a8af3d156dd142c5b8724a486fb71ca99e032 100644 (file)
@@ -377,7 +377,15 @@ public class AltosFlashUI
                        while (!link.is_loader()) {
                                link.to_loader();
 
-                               java.util.List<AltosDevice> devices = AltosUSBDevice.list(AltosLib.product_altusmetrum);
+                               java.util.List<AltosDevice> devices = null;
+
+                               for (int tries = 0; tries < 10; tries++) {
+                                       Thread.sleep(100);
+                                       devices = AltosUSBDevice.list(AltosLib.product_altusmetrum);
+                                       if (devices.size() != 0)
+                                               break;
+                               }
+
                                if (devices.size() == 1)
                                        device = devices.get(0);
                                else {
@@ -429,4 +437,4 @@ public class AltosFlashUI
 
                frame = in_frame;
        }
-}
\ No newline at end of file
+}