auto-sync
This commit is contained in:
parent
51e4b484d9
commit
0db26f16a2
|
@ -1,13 +1,65 @@
|
|||
package com.rusefi.config;
|
||||
|
||||
public class Field {
|
||||
private final int offset;
|
||||
import com.rusefi.core.Pair;
|
||||
|
||||
public Field(int offset) {
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @see com.rusefi.config.Fields
|
||||
*/
|
||||
|
||||
public class Field {
|
||||
private static final String INT_VALUE_PREFIX = "int @";
|
||||
private static final String FLOAT_VALUE_PREFIX = "float @";
|
||||
|
||||
private final int offset;
|
||||
private final FieldType type;
|
||||
|
||||
public Field(int offset, FieldType type) {
|
||||
this.offset = offset;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public FieldType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static boolean isIntValueMessage(String message) {
|
||||
return message.startsWith(INT_VALUE_PREFIX);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isFloatValueMessage(String message) {
|
||||
return message.startsWith(FLOAT_VALUE_PREFIX);
|
||||
}
|
||||
|
||||
public static Pair<Integer, ?> parseResponse(String message) {
|
||||
try {
|
||||
if (isIntValueMessage(message)) {
|
||||
message = message.substring(INT_VALUE_PREFIX.length());
|
||||
String[] a = message.split(" is ");
|
||||
if (a.length != 2)
|
||||
return null;
|
||||
int index = Integer.parseInt(a[0]);
|
||||
int value = Integer.parseInt(a[1]);
|
||||
return new Pair<>(index, value);
|
||||
}
|
||||
if (isFloatValueMessage(message)) {
|
||||
message = message.substring(FLOAT_VALUE_PREFIX.length());
|
||||
String[] a = message.split(" is ");
|
||||
if (a.length != 2)
|
||||
return null;
|
||||
int index = Integer.parseInt(a[0]);
|
||||
double value = Double.parseDouble(a[1]);
|
||||
return new Pair<>(index, value);
|
||||
}
|
||||
return null;
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.rusefi.config;
|
||||
|
||||
public enum FieldType {
|
||||
INT, FLOAT, ANALOG_CHART_E;
|
||||
|
||||
public String getCommand() {
|
||||
switch (this) {
|
||||
case FLOAT:
|
||||
return "get_float";
|
||||
case INT:
|
||||
case ANALOG_CHART_E:
|
||||
default:
|
||||
return "get_int";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package com.rusefi.config;
|
||||
|
||||
public class Fields {
|
||||
public static final Field ANALOGCHARTFREQUENCY = new Field(768);
|
||||
public static final Field ANALOGCHARTFREQUENCY = new Field(768, FieldType.INT);
|
||||
public static final Field ANALOGCHARTMODE = new Field(1648, FieldType.ANALOG_CHART_E);
|
||||
public static final Field globalFuelCorrection = new Field(808, FieldType.FLOAT);
|
||||
public static final Field digitalChartSize = new Field(4892, FieldType.INT);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.rusefi.config.test;
|
||||
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.core.Pair;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class FieldTest {
|
||||
@Test
|
||||
public void testParse() {
|
||||
{
|
||||
assertNull(Field.parseResponse("notint @768 is 21"));
|
||||
}
|
||||
{
|
||||
Pair<Integer, ?> p = Field.parseResponse("int @768 is 21");
|
||||
assertNotNull(p);
|
||||
assertEquals(new Integer(768), p.first);
|
||||
assertEquals(21, p.second);
|
||||
}
|
||||
{
|
||||
Pair<Integer, ?> p = Field.parseResponse("float @808 is 1.00");
|
||||
assertNotNull(p);
|
||||
assertEquals(new Integer(808), p.first);
|
||||
assertEquals(1.0, p.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +89,10 @@ public class AnalogChartPanel {
|
|||
lowerPanel.setBorder(BorderFactory.createLineBorder(Color.white));
|
||||
content.add(lowerPanel, BorderLayout.SOUTH);
|
||||
|
||||
lowerPanel.add(new ConfigField(Fields.ANALOGCHARTFREQUENCY).getContent());
|
||||
lowerPanel.add(new ConfigField(Fields.ANALOGCHARTMODE, "Sensor chart mode").getContent());
|
||||
lowerPanel.add(new ConfigField(Fields.ANALOGCHARTFREQUENCY, "Every XXX engine cycles").getContent());
|
||||
lowerPanel.add(new ConfigField(Fields.globalFuelCorrection, "Global Fuel Correction").getContent());
|
||||
lowerPanel.add(new ConfigField(Fields.digitalChartSize, "Engine Sniffer size").getContent());
|
||||
}
|
||||
|
||||
private void processValues() {
|
||||
|
|
|
@ -53,7 +53,7 @@ public class Launcher extends FrameHelper {
|
|||
tabbedPane.addTab("Main", mainGauges.createRpmPanel());
|
||||
tabbedPane.addTab("Gauges", new GaugesPanel().getContent());
|
||||
tabbedPane.addTab("Engine Sniffer", engineSnifferPanel.getPanel());
|
||||
tabbedPane.addTab("Analog Sniffer", new AnalogChartPanel().getPanel());
|
||||
tabbedPane.addTab("Sensor Sniffer", new AnalogChartPanel().getPanel());
|
||||
|
||||
tabbedPane.addTab("LE controls", new FlexibleControls().getPanel());
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ public class GaugesPanel {
|
|||
private Component createControls() {
|
||||
JPanel controls = new JPanel(new GridLayout(2, 1));
|
||||
controls.add(new RpmCommand());
|
||||
controls.add(new MafCommand());
|
||||
return controls;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,8 +97,6 @@ public class RpmPanel {
|
|||
// controls.add(new PotCommand(0).panel, "grow, wrap");
|
||||
// controls.add(new PotCommand(1).panel, "grow, wrap");
|
||||
|
||||
controls.add(new MafCommand(), "grow, wrap");
|
||||
|
||||
controls.add(wave0.getControl(), "grow, wrap");
|
||||
controls.add(wave1.getControl(), "grow, wrap");
|
||||
controls.add(wave2.getControl(), "grow, wrap");
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package com.rusefi.ui.config;
|
||||
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.config.FieldType;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.ui.ConnectionStatus;
|
||||
import com.rusefi.ui.util.JTextFieldWithWidth;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -8,20 +14,48 @@ import java.awt.*;
|
|||
public class ConfigField {
|
||||
private final Field field;
|
||||
|
||||
private final JPanel content = new JPanel(new FlowLayout());
|
||||
private final JPanel panel = new JPanel(new BorderLayout());
|
||||
private final JLabel status = new JLabel("P");
|
||||
private final JTextField view = new JTextField();
|
||||
private final JTextField view = new JTextFieldWithWidth(200);
|
||||
|
||||
public ConfigField(Field field) {
|
||||
public ConfigField(final Field field, String topLabel) {
|
||||
this.field = field;
|
||||
|
||||
content.add(status);
|
||||
ConnectionStatus.INSTANCE.addListener(new ConnectionStatus.Listener() {
|
||||
@Override
|
||||
public void onConnectionStatus(boolean isConnected) {
|
||||
CommandQueue.getInstance().write(field.getType().getCommand() + " " + field.getOffset());
|
||||
}
|
||||
});
|
||||
|
||||
JPanel center = new JPanel(new FlowLayout());
|
||||
|
||||
center.add(status);
|
||||
status.setToolTipText("Pending...");
|
||||
|
||||
content.add(view);
|
||||
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);
|
||||
|
||||
MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Class clazz, String message) {
|
||||
if (Field.isIntValueMessage(message) || Field.isFloatValueMessage(message) ) {
|
||||
Pair<Integer, ?> p = Field.parseResponse(message);
|
||||
if (p != null && p.first == field.getOffset()) {
|
||||
view.setText("" + p.second);
|
||||
status.setText("");
|
||||
status.setToolTipText(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JPanel getContent() {
|
||||
return content;
|
||||
return panel;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,10 @@ import java.awt.*;
|
|||
public class JTextFieldWithWidth extends JTextField {
|
||||
private int width;
|
||||
|
||||
public JTextFieldWithWidth(int width) {
|
||||
this("", width);
|
||||
}
|
||||
|
||||
public JTextFieldWithWidth() {
|
||||
this("", 200);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue