From 3adc4f3599ac1ee3fea986aa23f04822cf5faf46 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 18 Oct 2015 20:01:25 -0400 Subject: [PATCH] auto-sync --- ...ngine_configuration_generated_structures.h | 5 +- firmware/controllers/settings.cpp | 2 + firmware/integration/rusefi_config.txt | 2 +- .../ui/src/com/rusefi/SensorSnifferPane.java | 2 +- .../ui/src/com/rusefi/ui/GaugesPanel.java | 2 +- .../ui/src/com/rusefi/ui/MessagesPane.java | 2 +- .../rusefi/ui/engine/EngineSnifferPanel.java | 2 +- .../src/com/rusefi/ui/widgets/AnyCommand.java | 115 ++++++++++++------ 8 files changed, 88 insertions(+), 44 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index cdd34eba44..34a679a8fe 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated by config_definition.jar on Sun Oct 18 13:04:59 EDT 2015 +// this section was generated by config_definition.jar on Sun Oct 18 19:32:33 EDT 2015 // begin #include "rusefi_types.h" typedef struct { @@ -1044,6 +1044,7 @@ typedef struct { offset 1496 bit 4 */ bool_t useConstantDwellDuringCranking : 1; /** + * This options enables data for 'engine sniffer' tab in console, which comes at some CPU price offset 1496 bit 5 */ bool_t isEngineChartEnabled : 1; /** @@ -1517,4 +1518,4 @@ typedef struct { } persistent_config_s; // end -// this section was generated by config_definition.jar on Sun Oct 18 13:04:59 EDT 2015 +// this section was generated by config_definition.jar on Sun Oct 18 19:32:33 EDT 2015 diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index d9263ad420..df672818da 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -808,6 +808,8 @@ static void setSpiMode(int index, bool mode) { static void enableOrDisable(const char *param, bool isEnabled) { if (strEqualCaseInsensitive(param, "fastadc")) { boardConfiguration->isFastAdcEnabled = isEnabled; + } else if (strEqualCaseInsensitive(param, "engine_sniffer")) { + engineConfiguration->isEngineChartEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "step1limimter")) { boardConfiguration->enabledStep1Limiter = isEnabled; } else if (strEqualCaseInsensitive(param, "serial")) { diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 8e3328ccba..115a979e75 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -488,7 +488,7 @@ bit hasMapSensor;@see isMapAveragingEnabled bit hasBaroSensor bit hasAfrSensor bit useConstantDwellDuringCranking - bit isEngineChartEnabled + bit isEngineChartEnabled;This options enables data for 'engine sniffer' tab in console, which comes at some CPU price bit isCanEnabled bit hasCltSensor bit canReadEnabled diff --git a/java_console/ui/src/com/rusefi/SensorSnifferPane.java b/java_console/ui/src/com/rusefi/SensorSnifferPane.java index beb44ef41e..5fdfe7d2cc 100644 --- a/java_console/ui/src/com/rusefi/SensorSnifferPane.java +++ b/java_console/ui/src/com/rusefi/SensorSnifferPane.java @@ -89,7 +89,7 @@ public class SensorSnifferPane { upperPanel.add(pauseButton); upperPanel.add(new RpmLabel(2).getContent()); - upperPanel.add(new AnyCommand(config, true, false).getContent()); + upperPanel.add(AnyCommand.createField(config, true, false).getContent()); upperPanel.add(new URLLabel(EngineSnifferPanel.HELP_TEXT, HELP_URL)); pauseButton.addActionListener(new diff --git a/java_console/ui/src/com/rusefi/ui/GaugesPanel.java b/java_console/ui/src/com/rusefi/ui/GaugesPanel.java index c834e7f376..d2577462ac 100644 --- a/java_console/ui/src/com/rusefi/ui/GaugesPanel.java +++ b/java_console/ui/src/com/rusefi/ui/GaugesPanel.java @@ -190,7 +190,7 @@ public class GaugesPanel { JPanel leftUpperPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); leftUpperPanel.add(createSaveImageButton()); leftUpperPanel.add(new RpmLabel(2).getContent()); - AnyCommand command = new AnyCommand(config, false, false); + AnyCommand command = AnyCommand.createField(config, false, false); leftUpperPanel.add(command.getContent()); return leftUpperPanel; } diff --git a/java_console/ui/src/com/rusefi/ui/MessagesPane.java b/java_console/ui/src/com/rusefi/ui/MessagesPane.java index d92d3ec0b6..53363677e3 100644 --- a/java_console/ui/src/com/rusefi/ui/MessagesPane.java +++ b/java_console/ui/src/com/rusefi/ui/MessagesPane.java @@ -28,7 +28,7 @@ public class MessagesPane { public MessagesPane(final Node config) { JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); - AnyCommand command = new AnyCommand(config, true, false); + AnyCommand command = AnyCommand.createArea(config, config.getProperty(AnyCommand.KEY), true, false); final MessagesPanel upperPanel = new MessagesPanel(command.getContent()); upperPanel.loadFont(config); diff --git a/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java b/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java index d6eb75cb6c..f30f512486 100644 --- a/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java +++ b/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java @@ -127,7 +127,7 @@ public class EngineSnifferPanel { upperPanel.add(pauseButton); upperPanel.add(new RpmLabel(2).getContent()); - JComponent command = new AnyCommand(config, "chartsize " + EFI_DEFAULT_CHART_SIZE, true, true).getContent(); + JComponent command = AnyCommand.createField(config, "chartsize " + EFI_DEFAULT_CHART_SIZE, true, true).getContent(); upperPanel.add(command); upperPanel.add(zoomControl); diff --git a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java index 26371a04c2..1309e790b8 100644 --- a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java +++ b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java @@ -13,6 +13,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.concurrent.atomic.AtomicInteger; /** * Date: 3/20/13 @@ -20,23 +21,14 @@ import java.awt.event.KeyEvent; */ public class AnyCommand { public static final String KEY = "last_value"; - private final JTextField text = new JTextField() { - @Override - public Dimension getPreferredSize() { - Dimension size = super.getPreferredSize(); - return new Dimension(200, size.height); - } - }; + private final JTextComponent text; private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT)); private boolean reentrant; - private int index; + private Listener listener; - public AnyCommand(final Node config, boolean listenToCommands, boolean withCommandCaption) { - this(config, config.getProperty(KEY), listenToCommands, withCommandCaption); - } - - public AnyCommand(final Node config, String defaultCommand, final boolean listenToCommands, boolean withCommandCaption) { + private AnyCommand(final JTextComponent text, final Node config, String defaultCommand, final boolean listenToCommands, boolean withCommandCaption) { + this.text = text; text.setText(defaultCommand); content.setBorder(BorderFactory.createLineBorder(Color.PINK)); if (withCommandCaption) { @@ -61,25 +53,6 @@ public class AnyCommand { } }); - text.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_UP) { - String command = RecentCommands.getRecent(++index); - text.setText(command); - } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { - String command = RecentCommands.getRecent(--index); - text.setText(command); - } - } - }); - - text.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - send(); - } - }); text.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -93,7 +66,7 @@ public class AnyCommand { @Override public void changedUpdate(DocumentEvent e) { - boolean isOk = isValidInput(text); + boolean isOk = isValidInput(text.getText()); text.setBorder(isOk ? null : BorderFactory.createLineBorder(Color.red)); config.setProperty(KEY, text.getText()); } @@ -111,19 +84,25 @@ public class AnyCommand { } private void send() { - index = 0; String cmd = text.getText(); - if (!isValidInput(text)) + for (String s : cmd.split("\n")) + doSend(s); + } + + private void doSend(String cmd) { + if (!isValidInput(cmd)) return; + if (listener != null) + listener.onSend(); int timeout = CommandQueue.getTimeout(cmd); reentrant = true; CommandQueue.getInstance().write(cmd.toLowerCase(), timeout); reentrant = false; } - private static boolean isValidInput(JTextComponent text) { + private static boolean isValidInput(String text) { boolean isOk = true; - for (char c : text.getText().toCharArray()) { + for (char c : text.toCharArray()) { if (c > 127) { /** * https://sourceforge.net/p/rusefi/tickets/63/ @@ -143,4 +122,66 @@ public class AnyCommand { public void setContent(JPanel content) { this.content = content; } + + interface Listener { + void onSend(); + } + + public static AnyCommand createField(Node config, boolean listenToCommands, boolean withCommandCaption) { + return createField(config, config.getProperty(KEY), listenToCommands, withCommandCaption); + } + + public static AnyCommand createField(Node config, String defaultCommand, boolean listenToCommands, boolean withCommandCaption) { + final JTextField text = new JTextField() { + @Override + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + return new Dimension(200, size.height); + } + }; + + final AnyCommand command = new AnyCommand(text, config, defaultCommand, listenToCommands, withCommandCaption); + text.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + command.send(); + } + }); + + final AtomicInteger index = new AtomicInteger(); + command.listener = new Listener() { + @Override + public void onSend() { + index.set(0); + } + }; + + text.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_UP) { + String command = RecentCommands.getRecent(index.incrementAndGet()); + text.setText(command); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + String command = RecentCommands.getRecent(index.decrementAndGet()); + text.setText(command); + } + } + }); + + return command; + } + + public static AnyCommand createArea(Node config, String defaultCommand, boolean listenToCommands, boolean withCommandCaption) { + final JTextArea text = new JTextArea(3, 20) { + @Override + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + return new Dimension(200, size.height); + } + }; +// text.setMax + + return new AnyCommand(text, config, defaultCommand, listenToCommands, withCommandCaption); + } }