From 104ad305ac428d3e63d8d711d66e268be79e405f Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 22 Apr 2015 22:10:51 -0400 Subject: [PATCH] auto-sync --- firmware/svnversion.h | 4 +- .../models/src/com/rusefi/config/Field.java | 8 +++ java_console/ui/src/com/rusefi/Launcher.java | 2 +- .../com/rusefi/ui/config/BaseConfigField.java | 66 +++++++++++++++++++ .../com/rusefi/ui/config/BitConfigField.java | 46 +++++++++++++ .../src/com/rusefi/ui/config/ConfigField.java | 53 ++------------- .../rusefi/ui/engine/EngineSnifferPanel.java | 2 + 7 files changed, 130 insertions(+), 51 deletions(-) create mode 100644 java_console/ui/src/com/rusefi/ui/config/BaseConfigField.java create mode 100644 java_console/ui/src/com/rusefi/ui/config/BitConfigField.java diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 9294bf2df3..6f143d778c 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Sun Mar 22 11:16:21 EDT 2015 +// Wed Apr 22 21:56:21 EDT 2015 #ifndef VCS_VERSION -#define VCS_VERSION "7501" +#define VCS_VERSION "7887" #endif diff --git a/java_console/models/src/com/rusefi/config/Field.java b/java_console/models/src/com/rusefi/config/Field.java index 6fa1c0a5d9..92f49d48b2 100644 --- a/java_console/models/src/com/rusefi/config/Field.java +++ b/java_console/models/src/com/rusefi/config/Field.java @@ -7,6 +7,7 @@ import com.rusefi.core.Pair; */ public class Field { + private static final String BIT_VALUE_PREFIX = "bit @"; private static final String INT_VALUE_PREFIX = "int @"; private static final String FLOAT_VALUE_PREFIX = "float @"; @@ -40,6 +41,10 @@ public class Field { return offset; } + public int getBitOffset() { + return bitOffset; + } + public FieldType getType() { return type; } @@ -48,6 +53,9 @@ public class Field { return message.startsWith(INT_VALUE_PREFIX); } + public static boolean isBitValueMessage(String message) { + return message.startsWith(BIT_VALUE_PREFIX); + } public static boolean isFloatValueMessage(String message) { return message.startsWith(FLOAT_VALUE_PREFIX); diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index c291d8d1d6..917de9763b 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see com.rusefi.StartupFrame */ public class Launcher { - public static final int CONSOLE_VERSION = 20150421; + public static final int CONSOLE_VERSION = 20150422; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; diff --git a/java_console/ui/src/com/rusefi/ui/config/BaseConfigField.java b/java_console/ui/src/com/rusefi/ui/config/BaseConfigField.java new file mode 100644 index 0000000000..0990a51889 --- /dev/null +++ b/java_console/ui/src/com/rusefi/ui/config/BaseConfigField.java @@ -0,0 +1,66 @@ +package com.rusefi.ui.config; + +import com.rusefi.FileLog; +import com.rusefi.config.Field; +import com.rusefi.io.CommandQueue; +import com.rusefi.io.InvocationConfirmationListener; +import com.rusefi.ui.ConnectionStatus; + +import javax.swing.*; +import java.awt.*; + +class BaseConfigField { + protected final JLabel status = new JLabel("P"); + protected final JPanel panel = new JPanel(new BorderLayout()); + + public BaseConfigField(final Field field) { + /** + * This would request initial value + */ + ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() { + @Override + public void onConnectionStatus(boolean isConnected) { + CommandQueue.getInstance().write(field.getCommand(), + CommandQueue.DEFAULT_TIMEOUT, + InvocationConfirmationListener.VOID, + false); + } + }); + + status.setToolTipText("Pending..."); + + } + + protected void onValueArrived() { + status.setText(""); + status.setToolTipText(null); + } + + protected void sendValue(Field field, String newValue) { + String msg = field.setCommand() + " " + newValue; + FileLog.MAIN.logLine("Sending " + msg); + CommandQueue.getInstance().write(msg); + status.setText("S"); + status.setToolTipText("Storing..."); + } + + protected void createUi(String topLabel, Component control) { + JPanel center = new JPanel(new FlowLayout()); + + /** + * I guess a nice status enum is coming soon + */ + center.add(status); + + center.add(control); + + panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), + BorderFactory.createEmptyBorder(2, 2, 2, 2))); + panel.add(new JLabel(topLabel), BorderLayout.NORTH); + panel.add(center, BorderLayout.CENTER); + } + + public JPanel getContent() { + return panel; + } +} \ No newline at end of file diff --git a/java_console/ui/src/com/rusefi/ui/config/BitConfigField.java b/java_console/ui/src/com/rusefi/ui/config/BitConfigField.java new file mode 100644 index 0000000000..1302361f21 --- /dev/null +++ b/java_console/ui/src/com/rusefi/ui/config/BitConfigField.java @@ -0,0 +1,46 @@ +package com.rusefi.ui.config; + +import com.rusefi.config.Field; +import com.rusefi.core.MessagesCentral; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class BitConfigField extends BaseConfigField { + private final JCheckBox view = new JCheckBox(); + private boolean ec; + + public BitConfigField(final Field field, String caption) { + super(field); + + createUi(caption, view); + + MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() { + @Override + public void onMessage(Class clazz, String message) { + if (Field.isBitValueMessage(message)) { + String expectedPrefix = "bit @" + field.getOffset() + "/" + field.getBitOffset() + " is "; + if (message.startsWith(expectedPrefix) && message.length() == expectedPrefix.length() + 1) { + message = message.substring(expectedPrefix.length()); + System.out.println("Bit arrived " + message); + Boolean value = message.equals("1"); + ec = true; + view.setSelected(value); + onValueArrived(); + ec = false; + } + } + } + }); + + view.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (ec) + return; + sendValue(field, view.isSelected() ? "1" : "0"); + } + }); + } +} \ No newline at end of file diff --git a/java_console/ui/src/com/rusefi/ui/config/ConfigField.java b/java_console/ui/src/com/rusefi/ui/config/ConfigField.java index dc43be2a0a..f1c294da27 100644 --- a/java_console/ui/src/com/rusefi/ui/config/ConfigField.java +++ b/java_console/ui/src/com/rusefi/ui/config/ConfigField.java @@ -1,12 +1,8 @@ package com.rusefi.ui.config; -import com.rusefi.FileLog; import com.rusefi.config.Field; import com.rusefi.core.MessagesCentral; import com.rusefi.core.Pair; -import com.rusefi.io.CommandQueue; -import com.rusefi.io.InvocationConfirmationListener; -import com.rusefi.ui.ConnectionStatus; import com.rusefi.ui.util.JTextFieldWithWidth; import javax.swing.*; @@ -14,43 +10,12 @@ import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -public class ConfigField { - private final Field field; - - private final JPanel panel = new JPanel(new BorderLayout()); - private final JLabel status = new JLabel("P"); +public class ConfigField extends BaseConfigField { private final JTextField view = new JTextFieldWithWidth(200); public ConfigField(final Field field, String topLabel) { - this.field = field; - - /** - * This would request initial value - */ - ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() { - @Override - public void onConnectionStatus(boolean isConnected) { - CommandQueue.getInstance().write(field.getCommand(), - CommandQueue.DEFAULT_TIMEOUT, - InvocationConfirmationListener.VOID, - false); - } - }); - - JPanel center = new JPanel(new FlowLayout()); - - /** - * I guess a nice status enum is coming soon - */ - center.add(status); - status.setToolTipText("Pending..."); - - center.add(view); - - panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black), - BorderFactory.createEmptyBorder(2, 2, 2, 2))); - panel.add(new JLabel(topLabel), BorderLayout.NORTH); - panel.add(center, BorderLayout.CENTER); + super(field); + createUi(topLabel, view); MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() { @Override @@ -59,8 +24,7 @@ public class ConfigField { Pair p = Field.parseResponse(message); if (p != null && p.first == field.getOffset()) { view.setText("" + p.second); - status.setText(""); - status.setToolTipText(null); + onValueArrived(); } } } @@ -70,17 +34,10 @@ public class ConfigField { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { - String msg = field.setCommand() + " " + view.getText(); - FileLog.MAIN.logLine("Sending " + msg); - CommandQueue.getInstance().write(msg); - status.setText("S"); - status.setToolTipText("Storing..."); + sendValue(field, ConfigField.this.view.getText()); } } }); } - public JPanel getContent() { - return panel; - } } \ No newline at end of file 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 14a7a3064d..a27ed889f2 100644 --- a/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java +++ b/java_console/ui/src/com/rusefi/ui/engine/EngineSnifferPanel.java @@ -7,6 +7,7 @@ import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.io.LinkManager; import com.rusefi.ui.*; +import com.rusefi.ui.config.BitConfigField; import com.rusefi.ui.config.ConfigField; import com.rusefi.ui.storage.Node; import com.rusefi.ui.util.UiUtils; @@ -141,6 +142,7 @@ public class EngineSnifferPanel { topButtons.add(new URLLabel(HELP_TEXT, HELP_URL)); JPanel lowerButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0)); + lowerButtons.add(new BitConfigField(Fields.isDigitalChartEnabled, "Collect Engine Data").getContent()); lowerButtons.add(new ConfigField(Fields.ENGINE_SNIFFER_SIZE, "Engine Sniffer size").getContent()); JPanel bottomPanel = new JPanel(new BorderLayout());