auto-sync
This commit is contained in:
parent
0f8d0c47c5
commit
61e77787a7
|
@ -2,6 +2,9 @@ package com.rusefi.config;
|
||||||
|
|
||||||
import com.rusefi.core.Pair;
|
import com.rusefi.core.Pair;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Fields
|
* @see Fields
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +15,8 @@ public class Field {
|
||||||
private static final String FLOAT_VALUE_PREFIX = "float @";
|
private static final String FLOAT_VALUE_PREFIX = "float @";
|
||||||
public static final int NO_BIT_OFFSET = -1;
|
public static final int NO_BIT_OFFSET = -1;
|
||||||
|
|
||||||
|
public final static Map<String, Field> VALUES = new HashMap<>();
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int offset;
|
private final int offset;
|
||||||
private final FieldType type;
|
private final FieldType type;
|
||||||
|
@ -38,6 +43,10 @@ public class Field {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public String setCommand() {
|
public String setCommand() {
|
||||||
if (type == FieldType.BIT)
|
if (type == FieldType.BIT)
|
||||||
return "set_bit " + getOffset() + " " + bitOffset;
|
return "set_bit " + getOffset() + " " + bitOffset;
|
||||||
|
@ -115,7 +124,7 @@ public class Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void register(Field field) {
|
private static void register(Field field) {
|
||||||
|
VALUES.put(field.name, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field create(String name, int offset, FieldType type, int bitOffset) {
|
public static Field create(String name, int offset, FieldType type, int bitOffset) {
|
||||||
|
|
|
@ -1,80 +1,151 @@
|
||||||
package com.rusefi.ui;
|
package com.rusefi.ui;
|
||||||
|
|
||||||
import com.rusefi.config.Fields;
|
import com.rusefi.config.Field;
|
||||||
import com.rusefi.ui.config.BitConfigField;
|
import com.rusefi.config.FieldType;
|
||||||
import com.rusefi.ui.config.ConfigField;
|
import com.rusefi.ui.config.*;
|
||||||
import com.rusefi.ui.config.EnumConfigField;
|
|
||||||
import com.rusefi.ui.util.UiUtils;
|
import com.rusefi.ui.util.UiUtils;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class SettingsTab {
|
public class SettingsTab {
|
||||||
public static final String WRITECONFIG = "writeconfig";
|
public static final String WRITECONFIG = "writeconfig";
|
||||||
private final JPanel panel = new JPanel(new GridLayout(8, 3));
|
|
||||||
private final JPanel content = new JPanel(new BorderLayout());
|
private final JPanel content = new JPanel(new BorderLayout());
|
||||||
|
private final JPanel panel = new JPanel(new GridLayout(1, 3));
|
||||||
|
private final JButton dialog = new JButton();
|
||||||
|
private final JPanel dialogBody = new JPanel();
|
||||||
|
|
||||||
public SettingsTab() {
|
public SettingsTab() {
|
||||||
UiUtils.showLoadingMessage(content);
|
UiUtils.showLoadingMessage(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component createPane() {
|
public Component createPane() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showContent() {
|
public void showContent() {
|
||||||
|
final Map<String, DialogModel> dialogs = IniFileModel.getinstance().getDialogs();
|
||||||
|
if (dialogs.isEmpty()) {
|
||||||
|
// todo: show error label
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
content.removeAll();
|
content.removeAll();
|
||||||
panel.removeAll();
|
panel.removeAll();
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.ALGORITHM, "algorithm").getContent()));
|
String firstDialog = new ArrayList<>(dialogs.keySet()).get(0);
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGER_TYPE, "trigger type").getContent()));
|
dialog.addActionListener(new ActionListener() {
|
||||||
panel.add(new BitConfigField(Fields.USEONLYFRONTFORTRIGGER, "Only Front").getContent());
|
@Override
|
||||||
panel.add(new BitConfigField(Fields.ISPRINTTRIGGERSYNCHDETAILS, "gap info").getContent());
|
public void actionPerformed(ActionEvent e) {
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS1, "trigger #1 input").getContent()));
|
Component c = (Component) e.getSource();
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS2, "trigger #2 input").getContent()));
|
|
||||||
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS3, "trigger #3 input").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.INJECTIONPINS1, "injector #1").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new BitConfigField(Fields.ISSDCARDENABLED, "SD card enabled").getContent()));
|
final JPopupMenu menu = new JPopupMenu();
|
||||||
panel.add(UiUtils.wrap(new BitConfigField(Fields.USELCDSCREEN, "Use LCD").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.HIP9011INTHOLDPIN, "int/hold pin").getContent()));
|
for (final String name : dialogs.keySet()) {
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.HIP9011INTHOLDPINMODE, "int/hold pin mode").getContent()));
|
JMenuItem item = new JMenuItem(name);
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.HIP9011GAIN, "k gain").getContent()));
|
item.addActionListener(new ActionListener() {
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.KNOCKDETECTIONWINDOWSTART, "kw start").getContent()));
|
@Override
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.KNOCKDETECTIONWINDOWEND, "kw end").getContent()));
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
selectDialog(name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(item);
|
||||||
|
}
|
||||||
|
menu.show(c, -1, c.getHeight());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.IGNITIONPINS1, "ign #1").getContent()));
|
selectDialog(firstDialog);
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.IGNITIONPINS3, "ign #3").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.AFR_HWCHANNEL, "AFR channel").getContent()));
|
panel.add(UiUtils.wrap(dialog));
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.MAFADCCHANNEL, "MAF channel").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.MAP_SENSOR_HWCHANNEL, "MAP channel").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.TPSADCCHANNEL, "TPS channel").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.PEDALPOSITIONCHANNEL, "Pedal channel").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new BitConfigField(Fields.ISCANENABLED, "CAN enabled").getContent()));
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.ALGORITHM, "algorithm").getContent()));
|
||||||
panel.add(UiUtils.wrap(new BitConfigField(Fields.CANREADENABLED, "CAN read").getContent()));
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGER_TYPE, "trigger type").getContent()));
|
||||||
panel.add(UiUtils.wrap(new BitConfigField(Fields.CANWRITEENABLED, "CAN write").getContent()));
|
// panel.add(new BitConfigField(Fields.USEONLYFRONTFORTRIGGER, "Only Front").getContent());
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.CANTXPIN, "CAN TX").getContent()));
|
// panel.add(new BitConfigField(Fields.ISPRINTTRIGGERSYNCHDETAILS, "gap info").getContent());
|
||||||
panel.add(UiUtils.wrap(new EnumConfigField(Fields.CANRXPIN, "CAN RX").getContent()));
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS1, "trigger #1 input").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS2, "trigger #2 input").getContent()));
|
||||||
|
//// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TRIGGERINPUTPINS3, "trigger #3 input").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.INJECTIONPINS1, "injector #1").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new BitConfigField(Fields.ISSDCARDENABLED, "SD card enabled").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new BitConfigField(Fields.USELCDSCREEN, "Use LCD").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.HIP9011INTHOLDPIN, "int/hold pin").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.HIP9011INTHOLDPINMODE, "int/hold pin mode").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.HIP9011GAIN, "k gain").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.KNOCKDETECTIONWINDOWSTART, "kw start").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.KNOCKDETECTIONWINDOWEND, "kw end").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.IGNITIONPINS1, "ign #1").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.IGNITIONPINS3, "ign #3").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.AFR_HWCHANNEL, "AFR channel").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.MAFADCCHANNEL, "MAF channel").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.MAP_SENSOR_HWCHANNEL, "MAP channel").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.TPSADCCHANNEL, "TPS channel").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.PEDALPOSITIONCHANNEL, "Pedal channel").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new BitConfigField(Fields.ISCANENABLED, "CAN enabled").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new BitConfigField(Fields.CANREADENABLED, "CAN read").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new BitConfigField(Fields.CANWRITEENABLED, "CAN write").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.CANTXPIN, "CAN TX").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new EnumConfigField(Fields.CANRXPIN, "CAN RX").getContent()));
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.GLOBALFUELCORRECTION, "fuel corr").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.GLOBALTRIGGERANGLEOFFSET, "trig offset").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.CRANKING_BASEFUEL, "Cranking Fuel").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.IGNITIONOFFSET, "Ignition offset").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.CRANKINGTIMINGANGLE, "Cranking timing").getContent()));
|
||||||
|
//
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.ADDEDTOWALLCOEF, "Added to wall").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.SUCKEDOFFCOEF, "Sucked off wall").getContent()));
|
||||||
|
//// panel.add(UiUtils.wrap(new ConfigField(Fields.TPSACCELENRICHMENTTHRESHOLD, "TPS accel threshold").getContent()));
|
||||||
|
// panel.add(UiUtils.wrap(new ConfigField(Fields.TPSACCELENRICHMENTMULTIPLIER, "TPS accel coef").getContent()));
|
||||||
|
|
||||||
|
panel.add(dialogBody);
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.GLOBALFUELCORRECTION, "fuel corr").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.GLOBALTRIGGERANGLEOFFSET, "trig offset").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.CRANKING_BASEFUEL, "Cranking Fuel").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.IGNITIONOFFSET, "Ignition offset").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.CRANKINGTIMINGANGLE, "Cranking timing").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.ADDEDTOWALLCOEF, "Added to wall").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.SUCKEDOFFCOEF, "Sucked off wall").getContent()));
|
|
||||||
// panel.add(UiUtils.wrap(new ConfigField(Fields.TPSACCELENRICHMENTTHRESHOLD, "TPS accel threshold").getContent()));
|
|
||||||
panel.add(UiUtils.wrap(new ConfigField(Fields.TPSACCELENRICHMENTMULTIPLIER, "TPS accel coef").getContent()));
|
|
||||||
|
|
||||||
panel.add(UiUtils.wrap(RecentCommands.createButton(new AtomicBoolean(), WRITECONFIG)));
|
panel.add(UiUtils.wrap(RecentCommands.createButton(new AtomicBoolean(), WRITECONFIG)));
|
||||||
|
|
||||||
content.add(panel);
|
content.add(panel);
|
||||||
UiUtils.trueLayout(content);
|
UiUtils.trueLayout(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void selectDialog(String name) {
|
||||||
|
dialog.setText(name);
|
||||||
|
dialogBody.removeAll();
|
||||||
|
|
||||||
|
DialogModel m = IniFileModel.getinstance().getDialogs().get(name);
|
||||||
|
|
||||||
|
dialogBody.setLayout(new GridLayout(m.getFields().size(), 1));
|
||||||
|
|
||||||
|
for (DialogModel.Field f : m.getFields()) {
|
||||||
|
if (f.getKey() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Field field = Field.VALUES.get(f.getKey().toUpperCase());
|
||||||
|
if (field == null)
|
||||||
|
throw new NullPointerException("No field for " + f.getKey());
|
||||||
|
System.out.println(field);
|
||||||
|
|
||||||
|
JComponent control;
|
||||||
|
if (field.getType() == FieldType.BIT) {
|
||||||
|
control = new BitConfigField(field, f.getUiName()).getContent();
|
||||||
|
} else if (field.getOptions() != null) {
|
||||||
|
control = new EnumConfigField(field, f.getUiName()).getContent();
|
||||||
|
} else {
|
||||||
|
control = new ConfigField(field, f.getUiName()).getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogBody.add(control);
|
||||||
|
}
|
||||||
|
|
||||||
|
UiUtils.trueLayout(dialogBody);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,15 +10,15 @@ import java.util.List;
|
||||||
public class DialogModel {
|
public class DialogModel {
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String uiName;
|
private final String uiName;
|
||||||
private final List<String> fields;
|
private final List<Field> fields;
|
||||||
|
|
||||||
public DialogModel(String key, String uiName, List<String> fields) {
|
public DialogModel(String key, String uiName, List<Field> fields) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.uiName = uiName;
|
this.uiName = uiName;
|
||||||
this.fields = new ArrayList<>(fields);
|
this.fields = new ArrayList<>(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getFields() {
|
public List<Field> getFields() {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,4 +30,30 @@ public class DialogModel {
|
||||||
", fields=" + fields.size() +
|
", fields=" + fields.size() +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Field {
|
||||||
|
private final String key;
|
||||||
|
private final String uiName;
|
||||||
|
|
||||||
|
public Field(String key, String uiName) {
|
||||||
|
this.key = key;
|
||||||
|
this.uiName = uiName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUiName() {
|
||||||
|
return uiName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Field{" +
|
||||||
|
"key='" + key + '\'' +
|
||||||
|
", uiName='" + uiName + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.rusefi.ui.config;
|
package com.rusefi.ui.config;
|
||||||
|
|
||||||
|
import com.rusefi.config.Field;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ public class IniFileModel {
|
||||||
private final static IniFileModel INSTANCE = new IniFileModel();
|
private final static IniFileModel INSTANCE = new IniFileModel();
|
||||||
private String dialogId;
|
private String dialogId;
|
||||||
private String dialogUiName;
|
private String dialogUiName;
|
||||||
private List<String> fields = new ArrayList<>();
|
private List<DialogModel.Field> fields = new ArrayList<>();
|
||||||
private Map<String, DialogModel> dialogs = new TreeMap<>();
|
private Map<String, DialogModel> dialogs = new TreeMap<>();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -85,12 +87,12 @@ public class IniFileModel {
|
||||||
private void handleField(LinkedList<String> list) {
|
private void handleField(LinkedList<String> list) {
|
||||||
list.removeFirst(); // "field"
|
list.removeFirst(); // "field"
|
||||||
|
|
||||||
String label = list.isEmpty() ? "" : list.removeFirst();
|
String uiLabel = list.isEmpty() ? "" : list.removeFirst();
|
||||||
|
|
||||||
String name = list.isEmpty() ? null : list.removeFirst();
|
String key = list.isEmpty() ? null : list.removeFirst();
|
||||||
|
|
||||||
fields.add(label);
|
fields.add(new DialogModel.Field(key, uiLabel));
|
||||||
System.out.println("Field label=[" + label + "] : name=[" + name + "]");
|
System.out.println("Field label=[" + uiLabel + "] : key=[" + key + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDialog(LinkedList<String> list) {
|
private void handleDialog(LinkedList<String> list) {
|
||||||
|
|
Loading…
Reference in New Issue