diff --git a/java_console/ui/src/main/java/com/rusefi/BenchTestPane.java b/java_console/ui/src/main/java/com/rusefi/BenchTestPane.java index ca93c37dbb..9c65479430 100644 --- a/java_console/ui/src/main/java/com/rusefi/BenchTestPane.java +++ b/java_console/ui/src/main/java/com/rusefi/BenchTestPane.java @@ -2,7 +2,6 @@ package com.rusefi; import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.config.generated.Fields; -import com.rusefi.io.LinkManager; import com.rusefi.tracing.Entry; import com.rusefi.tracing.JsonOutput; import com.rusefi.ui.MessagesView; @@ -40,13 +39,13 @@ public class BenchTestPane { content.add(createMILTest()); content.add(createIdleTest()); content.add(createDizzyTest()); - content.add(new CommandControl("Reboot", "", "Reboot") { + content.add(new CommandControl(uiContext, "Reboot", "", "Reboot") { @Override protected String getCommand() { return Fields.CMD_REBOOT; } }.getContent()); - content.add(new CommandControl("Reboot to DFU", "", "Reboot to DFU") { + content.add(new CommandControl(uiContext,"Reboot to DFU", "", "Reboot to DFU") { @Override protected String getCommand() { return Fields.CMD_REBOOT_DFU; @@ -86,7 +85,7 @@ public class BenchTestPane { } private Component createMILTest() { - CommandControl panel = new CommandControl("MIL", "check_engine.jpg", TEST) { + CommandControl panel = new CommandControl(uiContext,"MIL", "check_engine.jpg", TEST) { @NotNull protected String getCommand() { return "milbench"; @@ -96,7 +95,7 @@ public class BenchTestPane { } private Component createIdleTest() { - CommandControl panel = new CommandControl("Idle Valve", "idle_valve.png", TEST) { + CommandControl panel = new CommandControl(uiContext,"Idle Valve", "idle_valve.png", TEST) { @NotNull protected String getCommand() { return "idlebench"; @@ -127,7 +126,7 @@ public class BenchTestPane { private Component createSparkTest() { final JComboBox indexes = createIndexCombo(); - CommandControl panel = new CommandControl("Spark #", "spark.jpg", TEST, indexes) { + CommandControl panel = new CommandControl(uiContext,"Spark #", "spark.jpg", TEST, indexes) { @Override protected String getCommand() { return "sparkbench2 1000 " + indexes.getSelectedItem() + " 5 333 3"; @@ -138,7 +137,7 @@ public class BenchTestPane { private Component createInjectorTest() { final JComboBox indexes = createIndexCombo(); - CommandControl panel = new CommandControl("Injector #", "injector.png", TEST, indexes) { + CommandControl panel = new CommandControl(uiContext,"Injector #", "injector.png", TEST, indexes) { @Override protected String getCommand() { return "fuelbench2 1000 " + indexes.getSelectedItem() + " 5 333 3"; diff --git a/java_console/ui/src/main/java/com/rusefi/CmdLine.java b/java_console/ui/src/main/java/com/rusefi/CmdLine.java deleted file mode 100644 index a0523a66b7..0000000000 --- a/java_console/ui/src/main/java/com/rusefi/CmdLine.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.rusefi; - -import com.rusefi.io.CommandQueue; -import com.rusefi.io.LinkManager; - -/** - * Andrey Belomutskiy, (c) 2013-2020 - * 2/22/2015 - */ -public class CmdLine { - public static void main(String[] args) { - if (args.length == 0 || args.length > 2) { - System.out.println("CmdLine COMMAND [PORT]"); - return; - } - String command = args[0]; - if (args.length == 1) { - String port = LinkManager.getDefaultPort(); - if (port == null) - return; - executeCommand(command, port); - } else { - executeCommand(command, args[1]); - } - } - - private static void executeCommand(String command, String port) { - System.out.println("Sending " + command); - System.out.println("Sending to " + port); - LinkManager linkManager = new LinkManager(); - IoUtil.realHardwareConnect(linkManager, port); - - IoUtil.sendCommand(command, CommandQueue.getInstance()); - System.out.println("Done!"); - System.exit(-1); - } - -} diff --git a/java_console/ui/src/main/java/com/rusefi/CommandControl.java b/java_console/ui/src/main/java/com/rusefi/CommandControl.java index 5ea082eb80..9f630050d8 100644 --- a/java_console/ui/src/main/java/com/rusefi/CommandControl.java +++ b/java_console/ui/src/main/java/com/rusefi/CommandControl.java @@ -2,6 +2,7 @@ package com.rusefi; import com.rusefi.autoupdate.AutoupdateUtil; import com.rusefi.io.CommandQueue; +import com.rusefi.ui.UIContext; import com.rusefi.ui.util.UiUtils; import org.jetbrains.annotations.NotNull; import org.putgemin.VerticalFlowLayout; @@ -18,8 +19,10 @@ abstract class CommandControl { public static final String SET = "Set"; protected final JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0)); final JButton test; + private final UIContext uiContext; - public CommandControl(String labelText, String iconFileName, String buttonText, JComponent... components) { + public CommandControl(UIContext uiContext, String labelText, String iconFileName, String buttonText, JComponent... components) { + this.uiContext = uiContext; ImageIcon icon = AutoupdateUtil.loadIcon(iconFileName); JPanel rightVerticalPanel = new JPanel(new VerticalFlowLayout()); rightVerticalPanel.add(new JLabel(labelText)); @@ -40,7 +43,7 @@ abstract class CommandControl { @NotNull protected ActionListener createButtonListener() { - return e -> CommandQueue.getInstance().write(getCommand()); + return e -> uiContext.getCommandQueue().write(getCommand()); } protected abstract String getCommand(); diff --git a/java_console/ui/src/main/java/com/rusefi/EcuStimulator.java b/java_console/ui/src/main/java/com/rusefi/EcuStimulator.java index 65af50b250..bf866a3dee 100644 --- a/java_console/ui/src/main/java/com/rusefi/EcuStimulator.java +++ b/java_console/ui/src/main/java/com/rusefi/EcuStimulator.java @@ -4,6 +4,7 @@ import com.rusefi.core.MessagesCentral; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.file.TableGenerator; +import com.rusefi.io.CommandQueue; import com.rusefi.models.Point3D; import com.rusefi.models.Range; import com.rusefi.models.XYData; @@ -189,7 +190,7 @@ public class EcuStimulator { int actual; int attempt = 0; do { - RpmCommand.requestRpmChange(rpm); + RpmCommand.requestRpmChange(rpm, null); sleepRuntime(50); actual = RpmModel.getInstance().getValue(); } while (attempt++ < 10 && Math.abs(rpm - actual) >= 100); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/MessagesPane.java b/java_console/ui/src/main/java/com/rusefi/ui/MessagesPane.java index d3a17d4791..30e22b30e6 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/MessagesPane.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/MessagesPane.java @@ -29,7 +29,7 @@ public class MessagesPane { public MessagesPane(UIContext uiContext, final Node config) { JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); - command = AnyCommand.createArea(config, config.getProperty(AnyCommand.KEY), true, false); + command = AnyCommand.createArea(uiContext, config, config.getProperty(AnyCommand.KEY), true, false); final MessagesPanel upperPanel = new MessagesPanel(command.getContent()); upperPanel.loadFont(config); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/Wizard.java b/java_console/ui/src/main/java/com/rusefi/ui/Wizard.java index af4013f7b8..151884f52f 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/Wizard.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/Wizard.java @@ -48,7 +48,8 @@ public class Wizard { @Override public Component getContent() { - CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() { + CommandQueue instance = null; + instance.write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() { @Override public void onCommandConfirmation() { SwingUtilities.invokeLater(new Runnable() { diff --git a/java_console/ui/src/main/java/com/rusefi/ui/etb/EtbCommandsPanel.java b/java_console/ui/src/main/java/com/rusefi/ui/etb/EtbCommandsPanel.java index 6207d274d7..b8d5a0b7ee 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/etb/EtbCommandsPanel.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/etb/EtbCommandsPanel.java @@ -51,11 +51,11 @@ public class EtbCommandsPanel { content.add(testParameters); - content.add(AnyCommand.createArea(new Node(), CMD_ETB_DUTY + " " + "10", false, false).getContent()); + content.add(AnyCommand.createArea(uiContext, new Node(), CMD_ETB_DUTY + " " + "10", false, false).getContent()); JPanel mockPpsPanel = new JPanel(new VerticalFlowLayout()); mockPpsPanel.setBorder(BorderFactory.createTitledBorder("Mock PPS")); - mockPpsPanel.add(DetachedSensor.createMockVoltageSlider(Sensor.PPS)); + mockPpsPanel.add(DetachedSensor.createMockVoltageSlider(uiContext.getCommandQueue(), Sensor.PPS)); content.add(mockPpsPanel); diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/AnyCommand.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/AnyCommand.java index d70027c8ca..7766b01196 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/AnyCommand.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/widgets/AnyCommand.java @@ -31,12 +31,14 @@ public class AnyCommand { public static final String KEY = "last_value"; private static final String DECODE_RPN = "decode_rpn"; + private final UIContext uiContext; private final JTextComponent text; private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT)); private boolean reentrant; private Listener listener; - private AnyCommand(final JTextComponent text, final Node config, String defaultCommand, final boolean listenToCommands, boolean withCommandCaption) { + private AnyCommand(UIContext uiContext, final JTextComponent text, final Node config, String defaultCommand, final boolean listenToCommands, boolean withCommandCaption) { + this.uiContext = uiContext; this.text = text; installCtrlEnterAction(); text.setText(defaultCommand); @@ -55,7 +57,7 @@ public class AnyCommand { }); content.add(go); - CommandQueue.getInstance().addListener(command -> { + uiContext.getCommandQueue().addListener(command -> { if (listenToCommands && !reentrant) text.setText(command); }); @@ -123,7 +125,7 @@ public class AnyCommand { listener.onSend(); int timeout = CommandQueue.getTimeout(cmd); reentrant = true; - CommandQueue.getInstance().write(cmd.toLowerCase(), timeout); + uiContext.getCommandQueue().write(cmd.toLowerCase(), timeout); reentrant = false; } @@ -260,7 +262,7 @@ public class AnyCommand { public static AnyCommand createField(UIContext uiContext, Node config, String defaultCommand, boolean listenToCommands, boolean withCommandCaption) { final JTextField text = new JTextFieldWithWidth(200); - final AnyCommand command = new AnyCommand(text, config, defaultCommand, listenToCommands, withCommandCaption); + final AnyCommand command = new AnyCommand(uiContext, text, config, defaultCommand, listenToCommands, withCommandCaption); text.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -292,7 +294,7 @@ public class AnyCommand { return command; } - public static AnyCommand createArea(Node config, String defaultCommand, boolean listenToCommands, boolean withCommandCaption) { + public static AnyCommand createArea(UIContext uiContext, Node config, String defaultCommand, boolean listenToCommands, boolean withCommandCaption) { final JTextArea text = new JTextArea(3, 20) { @Override public Dimension getPreferredSize() { @@ -302,6 +304,6 @@ public class AnyCommand { }; // text.setMax - return new AnyCommand(text, config, defaultCommand, listenToCommands, withCommandCaption); + return new AnyCommand(uiContext, text, config, defaultCommand, listenToCommands, withCommandCaption); } } diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/BooleanFlagControlPanel.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/BooleanFlagControlPanel.java deleted file mode 100644 index e774ecbd99..0000000000 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/BooleanFlagControlPanel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.rusefi.ui.widgets; - -import com.rusefi.core.Sensor; -import com.rusefi.core.SensorCentral; -import com.rusefi.io.CommandQueue; -import net.miginfocom.swing.MigLayout; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * This panel turns ON/OFF some rusefi configuration property - *

- * 7/11/13 - * Andrey Belomutskiy, (c) 2013-2020 - */ -public class BooleanFlagControlPanel { - private final JPanel content = new JPanel(new MigLayout()); - protected final JCheckBox checkBox; - - public BooleanFlagControlPanel(String labelCaption, String checkboxCaption) { - content.add(new JLabel(labelCaption)); - checkBox = new JCheckBox(checkboxCaption); - content.add(checkBox); - } - - public JComponent getControl() { - return content; - } - - protected void installCommand(final String command) { - checkBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - int mode = checkBox.isSelected() ? 1 : 0; - CommandQueue.getInstance().write(command + mode); - } - }); - } - - protected void installStatusReader(final Sensor statusSensor) { - SensorCentral.getInstance().addListener(statusSensor, new SensorCentral.SensorListener() { - @Override - public void onSensorUpdate(double value) { - checkBox.setSelected(value > 0); - } - }); - } -} diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/DetachedSensor.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/DetachedSensor.java index e62961bac8..4a719bf80e 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/DetachedSensor.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/widgets/DetachedSensor.java @@ -6,7 +6,6 @@ import com.rusefi.io.CommandQueue; import com.rusefi.io.IMethodInvocation; import com.rusefi.io.InvocationConfirmationListener; import com.rusefi.io.LinkManager; -import com.rusefi.ui.GaugesPanel; import com.rusefi.ui.UIContext; import com.rusefi.ui.storage.Node; import com.rusefi.ui.util.UiUtils; @@ -109,7 +108,7 @@ public class DetachedSensor { mockControlPanel.removeAll(); boolean isMockable = isMockable(); if (isMockable) { - Component mockComponent = createMockVoltageSlider(sensor); + Component mockComponent = createMockVoltageSlider(uiContext.getCommandQueue(), sensor); mockControlPanel.add(mockComponent); } UiUtils.trueLayout(content); @@ -122,7 +121,7 @@ public class DetachedSensor { return MOCKABLE.contains(sensor) && LinkManager.isSimulationMode; } - public static Component createMockVoltageSlider(final Sensor sensor) { + public static Component createMockVoltageSlider(CommandQueue commandQueue, final Sensor sensor) { final JSlider slider = new JSlider(0, _5_VOLTS_WITH_DECIMAL); slider.setLabelTable(SLIDER_LABELS); slider.setPaintLabels(true); @@ -157,7 +156,6 @@ public class DetachedSensor { slider.addChangeListener(e -> { double value = slider.getValue() / 10.0; - CommandQueue commandQueue = CommandQueue.getInstance(); pendingValue.set(value); /* diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/PotCommand.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/PotCommand.java index 0233237ad5..509fcd81c5 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/PotCommand.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/widgets/PotCommand.java @@ -84,7 +84,8 @@ public class PotCommand { public static void requestPotChange(int channel, int resistance) { if (resistance < 0 || resistance > 10000) throw new IllegalArgumentException("resistance: " + resistance); - CommandQueue.getInstance().write("pot " + channel + " " + resistance); + CommandQueue commandQueue = null; + commandQueue.write("pot " + channel + " " + resistance); } public static int getPotResistance(double vout, double vRef) { diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/RpmCommand.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/RpmCommand.java index 393bdd59d0..773f481fc9 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/RpmCommand.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/widgets/RpmCommand.java @@ -3,15 +3,13 @@ package com.rusefi.ui.widgets; import com.rusefi.io.CommandQueue; import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; /** * Date: 3/17/13 * Andrey Belomutskiy, (c) 2013-2020 */ public class RpmCommand extends JPanel { +/* public RpmCommand() { setBorder(BorderFactory.createLineBorder(Color.ORANGE)); setLayout(new FlowLayout(FlowLayout.LEFT)); @@ -36,11 +34,11 @@ public class RpmCommand extends JPanel { }); add(spinner); } - - public static void requestRpmChange(int rpm) { +*/ + public static void requestRpmChange(int rpm, CommandQueue commandQueue) { /** * @see */ - CommandQueue.getInstance().write("rpm " + rpm); + commandQueue.write("rpm " + rpm); } } diff --git a/java_console/ui/src/main/java/com/rusefi/ui/widgets/WaveInfoPanel.java b/java_console/ui/src/main/java/com/rusefi/ui/widgets/WaveInfoPanel.java deleted file mode 100644 index bf5e68c985..0000000000 --- a/java_console/ui/src/main/java/com/rusefi/ui/widgets/WaveInfoPanel.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.rusefi.ui.widgets; - -/** - * Date: 1/14/13 - * Andrey Belomutskiy, (c) 2013-2020 - */ -public class WaveInfoPanel extends BooleanFlagControlPanel { - public WaveInfoPanel(final int index) { - super("wave" + index, "active on low"); - installCommand("set_logic_input_mode " + index + " "); - } -}