Auto DFU throws NPE in case of no ports connected fix #2949

This commit is contained in:
rusefi 2021-07-11 17:01:52 -04:00
parent 7eba706d2e
commit a81f83bd1a
3 changed files with 11 additions and 6 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 = 20210618;
public static final int CONSOLE_VERSION = 20210711;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -8,7 +8,6 @@ import com.rusefi.autodetect.PortDetector;
import com.rusefi.io.DfuHelper;
import com.rusefi.io.IoStream;
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
import com.rusefi.ui.StatusConsumer;
import com.rusefi.ui.StatusWindow;
import com.rusefi.ui.util.URLLabel;
@ -33,15 +32,21 @@ public class DfuFlasher {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
doAutoDfu(comboPorts);
// todo: better usability would be to disable "Program" port in case of no ports found
Object selectedItem = comboPorts.getSelectedItem();
if (selectedItem == null) {
JOptionPane.showMessageDialog(comboPorts, "Failed to located serial ports");
} else {
doAutoDfu(selectedItem);
}
}
});
manualButton.addActionListener(e -> runDfuProgramming());
}
public static void doAutoDfu(JComboBox<String> comboPorts) {
String port = comboPorts.getSelectedItem().toString();
public static void doAutoDfu(Object selectedItem) {
String port = selectedItem.toString();
StringBuilder messages = new StringBuilder();
if (!PortDetector.isAutoPort(port)) {

View File

@ -56,7 +56,7 @@ public class ProgramSelector {
// todo: add ST-LINK no-assert mode
if (isAutoDfu) {
DfuFlasher.doAutoDfu(comboPorts);
DfuFlasher.doAutoDfu(comboPorts.getSelectedItem());
} else if (isManualDfu){
DfuFlasher.runDfuProgramming();
} else {