From 3fda7305f141dd6fb9d7b35df811f6e74760ec02 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 22 Oct 2021 14:36:54 -0400 Subject: [PATCH] Better Windows build-in DFU #3338 no sleep in case of manual DFU --- .../com/rusefi/maintenance/DfuFlasher.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java b/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java index 0b1458e20c..245db0a730 100644 --- a/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java +++ b/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java @@ -80,7 +80,10 @@ public class DfuFlasher { wnd.appendMsg("rusEFI console can only program on Windows"); return; } - ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread"); + ExecHelper.submitAction(() -> { + timeForDfuSwitch(wnd); + executeDFU(wnd); + }, DfuFlasher.class + " thread"); } else { wnd.appendMsg("Please use manual DFU to change bundle type."); } @@ -93,12 +96,6 @@ public class DfuFlasher { } private static void executeDFU(StatusWindow wnd) { - wnd.appendMsg("Giving time for USB enumeration..."); - try { - Thread.sleep(3 * Timeouts.SECOND); - } catch (InterruptedException e) { - throw new IllegalStateException(e); - } AtomicBoolean errorReported = new AtomicBoolean(); StringBuffer stdout = new StringBuffer(); String errorResponse = ExecHelper.executeCommand(FirmwareFlasher.BINARY_LOCATION, @@ -140,6 +137,15 @@ public class DfuFlasher { wnd.appendMsg("Please power cycle device to exit DFU mode"); } + private static void timeForDfuSwitch(StatusWindow wnd) { + wnd.appendMsg("Giving time for USB enumeration..."); + try { + Thread.sleep(2 * Timeouts.SECOND); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } + private static String getDfuCommand() { String fileName = IniFileModel.findFile(Launcher.INPUT_FILES_PATH, "rusefi", ".dfu");