rusEFI console to has "Erase via DFU" button #2250

This commit is contained in:
rusefillc 2021-11-23 16:23:57 -05:00
parent a4a490fcb7
commit 6d1474d76b
3 changed files with 27 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20211122;
public static final int CONSOLE_VERSION = 20211123;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -52,15 +52,19 @@ public class DfuFlasher {
wnd.appendMsg("rusEFI console can only program on Windows");
return;
}
ExecHelper.submitAction(() -> {
submitAction(() -> {
timeForDfuSwitch(wnd);
executeDFU(wnd);
}, DfuFlasher.class + " thread");
});
} else {
wnd.appendMsg("Please use manual DFU to change bundle type.");
}
}
private static void submitAction(Runnable r) {
ExecHelper.submitAction(r, DfuFlasher.class + " thread");
}
@Nullable
public static AtomicBoolean rebootToDfu(JComponent parent, String port, StatusWindow wnd) {
AtomicBoolean isSignatureValidated = new AtomicBoolean(true);
@ -108,15 +112,22 @@ public class DfuFlasher {
return wnd;
}
public static void runDfuErase() {
StatusWindow wnd = createStatusWindow();
submitAction(() -> ExecHelper.executeCommand(DFU_BINARY_LOCATION,
getDfuEraseCommand(),
DFU_BINARY, wnd, new StringBuffer()));
}
public static void runDfuProgramming() {
StatusWindow wnd = createStatusWindow();
ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread");
submitAction(() -> executeDFU(wnd));
}
private static void executeDFU(StatusWindow wnd) {
StringBuffer stdout = new StringBuffer();
String errorResponse = ExecHelper.executeCommand(DFU_BINARY_LOCATION,
getDfuCommand(),
getDfuWriteCommand(),
DFU_BINARY, wnd, stdout);
if (stdout.toString().contains("Download verified successfully")) {
// looks like sometimes we are not catching the last line of the response? 'Upgrade' happens before 'Verify'
@ -157,13 +168,17 @@ public class DfuFlasher {
}
}
private static String getDfuCommand() {
String fileName = IniFileModel.findFile(Launcher.INPUT_FILES_PATH, "rusefi", ".hex");
if (fileName == null)
private static String getDfuWriteCommand() {
String hexFileName = IniFileModel.findFile(Launcher.INPUT_FILES_PATH, "rusefi", ".hex");
if (hexFileName == null)
return "File not found";
String absolutePath = new File(fileName).getAbsolutePath();
String hexAbsolutePath = new File(hexFileName).getAbsolutePath();
return DFU_BINARY_LOCATION + "/" + DFU_BINARY + " -c port=usb1 -w " + absolutePath + " -v -s";
return DFU_BINARY_LOCATION + "/" + DFU_BINARY + " -c port=usb1 -w " + hexAbsolutePath + " -v -s";
}
private static String getDfuEraseCommand() {
return DFU_BINARY_LOCATION + "/" + DFU_BINARY + " -c port=usb1 -e all";
}
@NotNull

View File

@ -70,6 +70,8 @@ public class ProgramSelector {
Object selected = comboPorts.getSelectedItem();
String port = selected == null ? PortDetector.AUTO : selected.toString();
DfuFlasher.rebootToDfu(comboPorts, port, wnd);
} else if (selectedMode.equals(DFU_ERASE)) {
DfuFlasher.runDfuErase();
} else {
throw new IllegalArgumentException("How did you " + selectedMode);
}