simpler basic console Console buttons to read write tune #5577
only:mild refactoring
This commit is contained in:
parent
6706f97512
commit
71ec798191
|
@ -0,0 +1,22 @@
|
|||
package com.rusefi;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static com.rusefi.ui.util.UiUtils.setToolTip;
|
||||
|
||||
public class PortsComboBox {
|
||||
private final JComboBox<SerialPortScanner.PortResult> comboPorts = new JComboBox<>();
|
||||
|
||||
public PortsComboBox() {
|
||||
if (FileLog.isWindows()) {
|
||||
setToolTip(comboPorts, "Use 'Device Manager' icon above to launch Device Manager",
|
||||
"In 'Ports' section look for ",
|
||||
"'STMicroelectronics Virtual COM Port' for USB port",
|
||||
"'USB Serial Port' for TTL port");
|
||||
}
|
||||
}
|
||||
|
||||
public JComboBox<SerialPortScanner.PortResult> getComboPorts() {
|
||||
return comboPorts;
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ public class StartupFrame {
|
|||
private final JFrame frame;
|
||||
private final JPanel connectPanel = new JPanel(new FlowLayout());
|
||||
// todo: move this line to the connectPanel
|
||||
private final JComboBox<SerialPortScanner.PortResult> comboPorts = new JComboBox<>();
|
||||
private final PortsComboBox portsComboBox = new PortsComboBox();
|
||||
private final JPanel leftPanel = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
private final JPanel realHardwarePanel = new JPanel(new MigLayout());
|
||||
|
@ -89,14 +89,7 @@ public class StartupFrame {
|
|||
realHardwarePanel.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.darkGray), "Real stm32"));
|
||||
miscPanel.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.darkGray), "Miscellaneous"));
|
||||
|
||||
if (FileLog.isWindows()) {
|
||||
setToolTip(comboPorts, "Use 'Device Manager' icon above to launch Device Manager",
|
||||
"In 'Ports' section look for ",
|
||||
"'STMicroelectronics Virtual COM Port' for USB port",
|
||||
"'USB Serial Port' for TTL port");
|
||||
}
|
||||
|
||||
connectPanel.add(comboPorts);
|
||||
connectPanel.add(portsComboBox.getComboPorts());
|
||||
final JComboBox<String> comboSpeeds = createSpeedCombo();
|
||||
comboSpeeds.setToolTipText("For 'STMicroelectronics Virtual COM Port' device any speed setting would work the same");
|
||||
connectPanel.add(comboSpeeds);
|
||||
|
@ -148,7 +141,7 @@ public class StartupFrame {
|
|||
realHardwarePanel.add(noPortsMessage, "right, wrap");
|
||||
noPortsMessage.setToolTipText("Check you cables. Check your drivers. Do you want to start simulator maybe?");
|
||||
|
||||
ProgramSelector selector = new ProgramSelector(comboPorts);
|
||||
ProgramSelector selector = new ProgramSelector(portsComboBox.getComboPorts());
|
||||
|
||||
if (FileLog.isWindows()) {
|
||||
realHardwarePanel.add(new HorizontalLine(), "right, wrap");
|
||||
|
@ -249,7 +242,7 @@ public class StartupFrame {
|
|||
connectPanel.setVisible(!ports.isEmpty());
|
||||
|
||||
|
||||
boolean hasEcuOrBootloader = applyPortSelectionToUIcontrol(ports);
|
||||
boolean hasEcuOrBootloader = applyPortSelectionToUIcontrol(portsComboBox.getComboPorts(), ports);
|
||||
if (ports.isEmpty()) {
|
||||
noPortsMessage.setText(NO_PORTS_FOUND);
|
||||
} else {
|
||||
|
@ -270,7 +263,7 @@ public class StartupFrame {
|
|||
|
||||
private void connectButtonAction(JComboBox<String> comboSpeeds) {
|
||||
BaudRateHolder.INSTANCE.baudRate = Integer.parseInt((String) comboSpeeds.getSelectedItem());
|
||||
SerialPortScanner.PortResult selectedPort = ((SerialPortScanner.PortResult)comboPorts.getSelectedItem());
|
||||
SerialPortScanner.PortResult selectedPort = ((SerialPortScanner.PortResult)portsComboBox.getComboPorts().getSelectedItem());
|
||||
disposeFrameAndProceed();
|
||||
new ConsoleUI(selectedPort.port);
|
||||
}
|
||||
|
@ -311,7 +304,7 @@ public class StartupFrame {
|
|||
SerialPortScanner.INSTANCE.stopTimer();
|
||||
}
|
||||
|
||||
private boolean applyPortSelectionToUIcontrol(List<SerialPortScanner.PortResult> ports) {
|
||||
private static boolean applyPortSelectionToUIcontrol(JComboBox<SerialPortScanner.PortResult> comboPorts, List<SerialPortScanner.PortResult> ports) {
|
||||
comboPorts.removeAllItems();
|
||||
boolean hasEcuOrBootloader = false;
|
||||
for (final SerialPortScanner.PortResult port : ports) {
|
||||
|
|
|
@ -43,26 +43,27 @@ public class ProgramSelector {
|
|||
|
||||
private final JPanel content = new JPanel(new BorderLayout());
|
||||
private final JLabel noHardware = new JLabel("Nothing detected");
|
||||
private final JPanel controls = new JPanel(new FlowLayout());
|
||||
private final JComboBox<String> mode = new JComboBox<>();
|
||||
private final JPanel updateModeAndButton = new JPanel(new FlowLayout());
|
||||
private final JComboBox<String> updateModeComboBox = new JComboBox<>();
|
||||
|
||||
public ProgramSelector(JComboBox<SerialPortScanner.PortResult> comboPorts) {
|
||||
content.add(controls, BorderLayout.NORTH);
|
||||
content.add(updateModeAndButton, BorderLayout.NORTH);
|
||||
content.add(noHardware, BorderLayout.SOUTH);
|
||||
controls.setVisible(false);
|
||||
controls.add(mode);
|
||||
|
||||
String persistedMode = getConfig().getRoot().getProperty(getClass().getSimpleName());
|
||||
if (Arrays.asList(AUTO_DFU, MANUAL_DFU, OPENBLT_CAN, OPENBLT_SWITCH, OPENBLT_MANUAL, OPENBLT_AUTO, DFU_ERASE, DFU_SWITCH).contains(persistedMode))
|
||||
mode.setSelectedItem(persistedMode);
|
||||
updateModeComboBox.setSelectedItem(persistedMode);
|
||||
|
||||
JButton updateFirmware = createUpdateFirmwareButton();
|
||||
controls.add(updateFirmware);
|
||||
JButton updateFirmwareButton = createUpdateFirmwareButton();
|
||||
|
||||
updateFirmware.addActionListener(new ActionListener() {
|
||||
updateModeAndButton.setVisible(false);
|
||||
updateModeAndButton.add(updateModeComboBox);
|
||||
updateModeAndButton.add(updateFirmwareButton);
|
||||
|
||||
updateFirmwareButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String selectedMode = (String) mode.getSelectedItem();
|
||||
final String selectedMode = (String) updateModeComboBox.getSelectedItem();
|
||||
final SerialPortScanner.PortResult selectedPort = ((SerialPortScanner.PortResult) comboPorts.getSelectedItem());
|
||||
|
||||
getConfig().getRoot().setProperty(getClass().getSimpleName(), selectedMode);
|
||||
|
@ -87,7 +88,7 @@ public class ProgramSelector {
|
|||
case ST_LINK:
|
||||
job = updateOperationCallbacks -> {
|
||||
// todo: add ST-LINK no-assert mode? or not?
|
||||
StLinkFlasher.doUpdateFirmware(MaintenanceUtil.FIRMWARE_BIN_FILE, updateFirmware);
|
||||
StLinkFlasher.doUpdateFirmware(MaintenanceUtil.FIRMWARE_BIN_FILE, updateFirmwareButton);
|
||||
};
|
||||
break;
|
||||
case DFU_SWITCH:
|
||||
|
@ -263,42 +264,42 @@ public class ProgramSelector {
|
|||
|
||||
public void apply(SerialPortScanner.AvailableHardware currentHardware) {
|
||||
noHardware.setVisible(currentHardware.isEmpty());
|
||||
controls.setVisible(!currentHardware.isEmpty());
|
||||
updateModeAndButton.setVisible(!currentHardware.isEmpty());
|
||||
|
||||
boolean hasSerialPorts = !currentHardware.getKnownPorts().isEmpty();
|
||||
boolean hasDfuDevice = currentHardware.isDfuFound();
|
||||
|
||||
mode.removeAllItems();
|
||||
updateModeComboBox.removeAllItems();
|
||||
if (FileLog.isWindows()) {
|
||||
boolean requireBlt = FindFileHelper.isObfuscated();
|
||||
if (hasSerialPorts && !requireBlt) {
|
||||
mode.addItem(AUTO_DFU);
|
||||
updateModeComboBox.addItem(AUTO_DFU);
|
||||
}
|
||||
|
||||
if (hasDfuDevice) {
|
||||
mode.addItem(MANUAL_DFU);
|
||||
mode.addItem(DFU_ERASE);
|
||||
updateModeComboBox.addItem(MANUAL_DFU);
|
||||
updateModeComboBox.addItem(DFU_ERASE);
|
||||
if (DfuFlasher.haveBootloaderBinFile()) {
|
||||
mode.addItem(INSTALL_OPENBLT);
|
||||
updateModeComboBox.addItem(INSTALL_OPENBLT);
|
||||
}
|
||||
}
|
||||
if (!requireBlt) {
|
||||
mode.addItem(DFU_SWITCH);
|
||||
updateModeComboBox.addItem(DFU_SWITCH);
|
||||
}
|
||||
if (currentHardware.isStLinkConnected())
|
||||
mode.addItem(ST_LINK);
|
||||
updateModeComboBox.addItem(ST_LINK);
|
||||
if (currentHardware.isPCANConnected())
|
||||
mode.addItem(OPENBLT_CAN);
|
||||
updateModeComboBox.addItem(OPENBLT_CAN);
|
||||
// todo: detect PCAN mode.addItem(OPENBLT_CAN);
|
||||
}
|
||||
|
||||
if (hasSerialPorts) {
|
||||
mode.addItem(OPENBLT_AUTO);
|
||||
mode.addItem(OPENBLT_SWITCH);
|
||||
mode.addItem(OPENBLT_MANUAL);
|
||||
updateModeComboBox.addItem(OPENBLT_AUTO);
|
||||
updateModeComboBox.addItem(OPENBLT_SWITCH);
|
||||
updateModeComboBox.addItem(OPENBLT_MANUAL);
|
||||
}
|
||||
|
||||
trueLayout(mode);
|
||||
trueLayout(updateModeComboBox);
|
||||
trueLayout(content);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue