mirror of https://github.com/rusefi/rusefi-1.git
console usability: DFU buttons #921
This commit is contained in:
parent
c58eeaaf85
commit
3777b7662f
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
|
@ -48,7 +48,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
|||
* @see EngineSnifferPanel
|
||||
*/
|
||||
public class Launcher {
|
||||
public static final int CONSOLE_VERSION = 20190909;
|
||||
public static final int CONSOLE_VERSION = 20190914;
|
||||
public static final String INI_FILE_PATH = System.getProperty("ini_file_path", "..");
|
||||
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
|
||||
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.rusefi.maintenance.*;
|
|||
import com.rusefi.ui.util.HorizontalLine;
|
||||
import com.rusefi.ui.util.URLLabel;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
||||
|
@ -40,6 +41,7 @@ public class StartupFrame {
|
|||
private static final String LOGO = "logo.gif";
|
||||
public static final String LINK_TEXT = "rusEfi (c) 2012-2019";
|
||||
private static final String URI = "http://rusefi.com/?java_console";
|
||||
// private static final int RUSEFI_ORANGE = 0xff7d03;
|
||||
|
||||
private final JFrame frame;
|
||||
private final JPanel connectPanel = new JPanel(new FlowLayout());
|
||||
|
@ -50,8 +52,8 @@ public class StartupFrame {
|
|||
private boolean isFirstTimeApplyingPorts = true;
|
||||
private JPanel leftPanel = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
private JPanel realHardwarePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.LEADING, 5, 10));
|
||||
private JPanel miscPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TRAILING)) {
|
||||
private JPanel realHardwarePanel = new JPanel(new MigLayout());
|
||||
private JPanel miscPanel = new JPanel(new MigLayout()) {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
// want miscPanel and realHardwarePanel to be the same width
|
||||
|
@ -104,11 +106,11 @@ public class StartupFrame {
|
|||
comboSpeeds.setToolTipText("For 'STMicroelectronics Virtual COM Port' device any speed setting would work the same");
|
||||
connectPanel.add(comboSpeeds);
|
||||
|
||||
final JButton connect = new JButton("Connect");
|
||||
connect.setBackground(new Color(0xff7d03)); // custom orange
|
||||
setToolTip(connect, "Connect to real hardware");
|
||||
connectPanel.add(connect);
|
||||
connect.addActionListener(new ActionListener() {
|
||||
final JButton connectButton = new JButton("Connect", new ImageIcon(getClass().getResource("/com/rusefi/connect48.png")));
|
||||
//connectButton.setBackground(new Color(RUSEFI_ORANGE)); // custom orange
|
||||
setToolTip(connectButton, "Connect to real hardware");
|
||||
connectPanel.add(connectButton);
|
||||
connectButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PortHolder.BAUD_RATE = Integer.parseInt((String) comboSpeeds.getSelectedItem());
|
||||
|
@ -131,23 +133,29 @@ public class StartupFrame {
|
|||
JPanel topButtons = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
|
||||
topButtons.add(createShowDeviceManagerButton());
|
||||
topButtons.add(DriverInstall.createButton());
|
||||
realHardwarePanel.add(topButtons);
|
||||
realHardwarePanel.add(topButtons, "right, wrap");
|
||||
}
|
||||
realHardwarePanel.add(connectPanel);
|
||||
realHardwarePanel.add(noPortsMessage);
|
||||
realHardwarePanel.add(connectPanel, "right, wrap");
|
||||
realHardwarePanel.add(noPortsMessage, "right, wrap");
|
||||
installMessage(noPortsMessage, "Check you cables. Check your drivers. Do you want to start simulator maybe?");
|
||||
|
||||
if (FileLog.isWindows()) {
|
||||
realHardwarePanel.add(new HorizontalLine());
|
||||
realHardwarePanel.add(new DfuFlasher(comboPorts).getAutoButton());
|
||||
realHardwarePanel.add(new DfuFlasher(comboPorts).getManualButton());
|
||||
realHardwarePanel.add(new HorizontalLine(), "right, wrap");
|
||||
|
||||
ProgramSelector selector = new ProgramSelector(comboPorts);
|
||||
realHardwarePanel.add(selector.getControl(), "right, wrap");
|
||||
|
||||
|
||||
// realHardwarePanel.add(new DfuFlasher(comboPorts).getAutoButton());
|
||||
// realHardwarePanel.add(new DfuFlasher(comboPorts).getManualButton());
|
||||
// for F7 builds we just build one file at the moment
|
||||
realHardwarePanel.add(new FirmwareFlasher(FirmwareFlasher.IMAGE_FILE, "ST-LINK Program Firmware", "Default firmware version for most users").getButton());
|
||||
// realHardwarePanel.add(new FirmwareFlasher(FirmwareFlasher.IMAGE_FILE, "ST-LINK Program Firmware", "Default firmware version for most users").getButton());
|
||||
if (new File(FirmwareFlasher.IMAGE_NO_ASSERTS_FILE).exists()) {
|
||||
// 407 build
|
||||
realHardwarePanel.add(new FirmwareFlasher(FirmwareFlasher.IMAGE_NO_ASSERTS_FILE, "ST-LINK Program Firmware/NoAsserts", "Please only use this version if you know that you need this version").getButton());
|
||||
FirmwareFlasher firmwareFlasher = new FirmwareFlasher(FirmwareFlasher.IMAGE_NO_ASSERTS_FILE, "ST-LINK Program Firmware/NoAsserts", "Please only use this version if you know that you need this version");
|
||||
realHardwarePanel.add(firmwareFlasher.getButton(), "right, wrap");
|
||||
}
|
||||
realHardwarePanel.add(new EraseChip().getButton());
|
||||
realHardwarePanel.add(new EraseChip().getButton(), "right, wrap");
|
||||
}
|
||||
|
||||
SerialPortScanner.INSTANCE.listeners.add(new SerialPortScanner.Listener() {
|
||||
|
@ -184,8 +192,8 @@ public class StartupFrame {
|
|||
}
|
||||
});
|
||||
|
||||
miscPanel.add(buttonLogViewer);
|
||||
miscPanel.add(new HorizontalLine());
|
||||
miscPanel.add(buttonLogViewer, "wrap");
|
||||
miscPanel.add(new HorizontalLine(), "wrap");
|
||||
|
||||
miscPanel.add(SimulatorHelper.createSimulatorComponent(this));
|
||||
|
||||
|
|
|
@ -34,35 +34,37 @@ public class DfuFlasher {
|
|||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String port = comboPorts.getSelectedItem().toString();
|
||||
port = PortDetector.autoDetectSerialIfNeeded(port);
|
||||
if (port == null) {
|
||||
JOptionPane.showMessageDialog(Launcher.getFrame(), "rusEfi serial port not detected");
|
||||
return;
|
||||
}
|
||||
IoStream stream = SerialIoStreamJSerialComm.open(port, PortHolder.BAUD_RATE, FileLog.LOGGER);
|
||||
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
|
||||
try {
|
||||
stream.sendPacket(command, FileLog.LOGGER);
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
runDfuProgramming();
|
||||
doAutoDfu(comboPorts);
|
||||
}
|
||||
});
|
||||
|
||||
manualButton.addActionListener(e -> runDfuProgramming());
|
||||
}
|
||||
|
||||
private void runDfuProgramming() {
|
||||
StatusWindow wnd = new StatusWindow();
|
||||
wnd.showFrame("DFU status");
|
||||
ExecHelper.submitAction(() -> executeDFU(wnd), getClass() + " thread");
|
||||
public static void doAutoDfu(JComboBox<String> comboPorts) {
|
||||
String port = comboPorts.getSelectedItem().toString();
|
||||
port = PortDetector.autoDetectSerialIfNeeded(port);
|
||||
if (port == null) {
|
||||
JOptionPane.showMessageDialog(Launcher.getFrame(), "rusEfi serial port not detected");
|
||||
return;
|
||||
}
|
||||
IoStream stream = SerialIoStreamJSerialComm.open(port, PortHolder.BAUD_RATE, FileLog.LOGGER);
|
||||
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
|
||||
try {
|
||||
stream.sendPacket(command, FileLog.LOGGER);
|
||||
stream.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
runDfuProgramming();
|
||||
}
|
||||
|
||||
private void executeDFU(StatusWindow wnd) {
|
||||
public static void runDfuProgramming() {
|
||||
StatusWindow wnd = new StatusWindow();
|
||||
wnd.showFrame("DFU status");
|
||||
ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread");
|
||||
}
|
||||
|
||||
private static void executeDFU(StatusWindow wnd) {
|
||||
wnd.appendMsg("Giving time for USB enumeration...");
|
||||
try {
|
||||
Thread.sleep(3 * Timeouts.SECOND);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.rusefi.ui.StatusWindow;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -15,7 +16,7 @@ public class EraseChip {
|
|||
private static final String FLASH_SIZE = "0x0100000";
|
||||
private static final String ERASE_COMMAND_SUFFIX = " -c init -c targets -c \"halt\" -c \"flash erase_address 0x08000000 " + FLASH_SIZE + "\" -c shutdown";
|
||||
|
||||
private final JButton button = new JButton("ST-LINK Erase Chip");
|
||||
private final JButton button = new JButton("ST-LINK Erase Chip", UiUtils.loadIcon("/com/rusefi/erase.png"));
|
||||
private StatusWindow wnd = new StatusWindow();
|
||||
|
||||
public EraseChip() {
|
||||
|
|
|
@ -36,26 +36,24 @@ public class FirmwareFlasher {
|
|||
|
||||
private final JButton button;
|
||||
private String fileName;
|
||||
private StatusWindow wnd = new StatusWindow();
|
||||
|
||||
public FirmwareFlasher(String fileName, String buttonTest, String tooltip) {
|
||||
this.fileName = fileName;
|
||||
button = new JButton(buttonTest);
|
||||
button.setToolTipText(tooltip);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int dialogResult = JOptionPane.showConfirmDialog(button, "Do you really want to update firmware? Please disconnect vehicle battery before erasing.",
|
||||
"Please disconnect from vehicle", JOptionPane.YES_NO_OPTION);
|
||||
if (dialogResult != JOptionPane.YES_OPTION)
|
||||
return;
|
||||
button.addActionListener(event -> doUpdateFirmware(fileName, button));
|
||||
}
|
||||
|
||||
public static void doUpdateFirmware(String fileName, JComponent component) {
|
||||
StatusWindow wnd = new StatusWindow();
|
||||
int dialogResult = JOptionPane.showConfirmDialog(component, "Do you really want to update firmware? Please disconnect vehicle battery before erasing.",
|
||||
"Please disconnect from vehicle", JOptionPane.YES_NO_OPTION);
|
||||
if (dialogResult != JOptionPane.YES_OPTION)
|
||||
return;
|
||||
|
||||
wnd.showFrame(TITLE);
|
||||
wnd.showFrame(TITLE);
|
||||
|
||||
ExecHelper.submitAction(() -> doFlashFirmware(), getClass() + " extProcessThread");
|
||||
}
|
||||
});
|
||||
ExecHelper.submitAction(() -> doFlashFirmware(wnd, fileName), FirmwareFlasher.class + " extProcessThread");
|
||||
}
|
||||
|
||||
public static String getOpenocdCommand() {
|
||||
|
@ -69,7 +67,7 @@ public class FirmwareFlasher {
|
|||
OPENOCD_EXE, wnd);
|
||||
}
|
||||
|
||||
private void doFlashFirmware() {
|
||||
private static void doFlashFirmware(StatusWindow wnd, String fileName) {
|
||||
if (!new File(fileName).exists()) {
|
||||
wnd.appendMsg(fileName + " not found, cannot proceed !!!");
|
||||
wnd.setStatus("ERROR");
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
public class ProgramSelector {
|
||||
|
||||
private static final String AUTO_DFU = "Auto DFU";
|
||||
private static final String MANUAL_DFU = "Manual DFU";
|
||||
private static final String ST_LINK = "ST-LINK";
|
||||
|
||||
private final JPanel controls = new JPanel(new FlowLayout());
|
||||
private final JComboBox mode = new JComboBox();
|
||||
|
||||
public ProgramSelector(JComboBox<String> comboPorts) {
|
||||
/**
|
||||
* todo: add FULL AUTO mode which would fire up DFU and ST-LINK in parallel hoping that one of those would work?
|
||||
*/
|
||||
mode.addItem(AUTO_DFU);
|
||||
mode.addItem(MANUAL_DFU);
|
||||
mode.addItem(ST_LINK);
|
||||
|
||||
controls.add(mode);
|
||||
|
||||
String persistedMode = getConfig().getRoot().getProperty(getClass().getSimpleName());
|
||||
if (Arrays.asList(AUTO_DFU, MANUAL_DFU, ST_LINK).contains(persistedMode))
|
||||
mode.setSelectedItem(persistedMode);
|
||||
|
||||
JButton updateFirmware = new JButton("Update Firmware",
|
||||
UiUtils.loadIcon("/com/rusefi/upload48.jpg"));
|
||||
controls.add(updateFirmware);
|
||||
|
||||
updateFirmware.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String selectedMode = (String) mode.getSelectedItem();
|
||||
|
||||
getConfig().getRoot().setProperty(getClass().getSimpleName(), selectedMode);
|
||||
|
||||
|
||||
boolean isAutoDfu = selectedMode.equals(AUTO_DFU);
|
||||
boolean isManualDfu = selectedMode.equals(MANUAL_DFU);
|
||||
// todo: add ST-LINK no-assert mode
|
||||
|
||||
if (isAutoDfu) {
|
||||
DfuFlasher.doAutoDfu(comboPorts);
|
||||
} else if (isManualDfu){
|
||||
DfuFlasher.runDfuProgramming();
|
||||
} else {
|
||||
FirmwareFlasher.doUpdateFirmware(FirmwareFlasher.IMAGE_FILE, updateFirmware);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public JPanel getControl() {
|
||||
return controls;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
|
Loading…
Reference in New Issue