auto-sync

This commit is contained in:
rusefi 2014-08-29 10:55:20 -04:00
parent 4ee83f0fee
commit 8ad5f0de7c
9 changed files with 86 additions and 27 deletions

View File

@ -96,6 +96,8 @@ public class EngineState {
addDoubleSensor("duty0", Sensor.DUTY0);
addDoubleSensor("duty1", Sensor.DUTY1);
addDoubleSensor("timing", Sensor.TIMING);
addDoubleSensor(Sensor.TRG_0_DUTY);
addDoubleSensor(Sensor.TRG_1_DUTY);
addDoubleSensor("idl", Sensor.IDLE_SWITCH);
@ -164,6 +166,13 @@ public class EngineState {
});
}
/**
* Sensor enum name matches the protocol key
*/
private void addDoubleSensor(Sensor sensor) {
addDoubleSensor(sensor.name(), sensor);
}
private void addDoubleSensor(String key, final Sensor sensor) {
addDoubleSensor(key, sensor, false);
}

View File

@ -22,6 +22,9 @@ public enum Sensor {
MAF("MAF", "Volts", 4),
TPS("throttle", "%", 100),
TRG_0_DUTY("trg0 duty", "%", 100),
TRG_1_DUTY("trg1 duty", "%", 100),
// COOLANT_WIDTH("c w", "", 30),
// INTAKE_AIR_WIDTH("air w", "", 30),

View File

@ -19,7 +19,7 @@ import javax.swing.*;
* @see WavePanel
*/
public class Launcher extends FrameHelper {
public static final int CONSOLE_VERSION = 20140820;
public static final int CONSOLE_VERSION = 20140828;
public static final boolean SHOW_STIMULATOR = true;
public Launcher(String port) {

View File

@ -13,7 +13,7 @@ import java.awt.event.WindowEvent;
public class FrameHelper {
protected final JFrame frame = new JFrame();
protected void showFrame(JComponent container) {
protected void showFrame(JComponent component) {
frame.setSize(800, 500);
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@ -28,7 +28,7 @@ public class FrameHelper {
onWindowClosed();
}
});
frame.add(container);
frame.add(component);
frame.setVisible(true);
}

View File

@ -19,6 +19,11 @@ public class GaugesPanel {
private final JPanel content = new JPanel(new BorderLayout());
public static void main(String[] args) {
FrameHelper fh = new FrameHelper();
fh.showFrame(new GaugesPanel().getContent());
}
public GaugesPanel() {
// Radial radial2 = createRadial("title");

View File

@ -36,6 +36,7 @@ public class RecentCommands {
}
});
add("help");
add("showconfig");
add("writeconfig");
add("enable_injection");
@ -52,7 +53,7 @@ public class RecentCommands {
content.add(createButton(entry));
}
UpDownImage.trueRepaint(content.getParent());
// UpDownImage.trueLayout(content);
UpDownImage.trueLayout(content.getParent());
}
private JComponent createButton(final Entry entry) {

View File

@ -53,7 +53,7 @@ public class RpmPanel {
gauges.add(SensorGauge.createGauge(Sensor.FUEL));
//gauges.add(GaugesPanel.createGauge(Sensor.ADVANCE0));
gauges.add(SensorGauge.createGauge(Sensor.VREF, PotCommand.VOLTAGE_CORRECTION));
gauges.add(SensorGauge.createGauge(Sensor.VREF));
gauges.add(SensorGauge.createGauge(Sensor.MAF));
gauges.add(SensorGauge.createGauge(Sensor.DWELL1));
// gauges.add(GaugesPanel.createGauge(Sensor.ADVANCE1));

View File

@ -10,6 +10,8 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
@ -32,17 +34,22 @@ public class SensorGauge {
private static final int _5_VOLTS_WITH_DECIMAL = 50;
public static Component createGauge(final Sensor sensor) {
return createGauge(sensor, 1);
JPanel wrapper = new JPanel(new BorderLayout());
createGaugeBody(sensor, wrapper);
return wrapper;
}
public static Component createGauge(final Sensor sensor, final double correction) {
private static void createGaugeBody(final Sensor sensor, final JPanel wrapper) {
final Radial gauge = createRadial(sensor.getName(), sensor.getUnits(), sensor.getMaxValue(), sensor.getMinValue());
gauge.setBackgroundColor(sensor.getColor());
SensorCentral.getInstance().addListener(sensor, new SensorCentral.AdcListener() {
public void onAdcUpdate(SensorCentral model, double value) {
gauge.setValue(value * correction);
gauge.setValue(value);
}
});
gauge.setLcdDecimals(2);
@ -50,29 +57,58 @@ public class SensorGauge {
gauge.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int size = gauge.getSize().width;
JFrame n = new JFrame(sensor.getName());
boolean isMockable = MOCKABLE.contains(sensor);
int h = isMockable ? (int) (size * 1.5) : size;
JPanel content = new JPanel(new BorderLayout());
content.add(createGauge(sensor, correction), BorderLayout.CENTER);
if (isMockable)
content.add(createMockVoltageSlider(sensor), BorderLayout.SOUTH);
n.setSize(size, h);
n.setAlwaysOnTop(true);
n.add(content);
n.setVisible(true);
n.setLocation(e.getXOnScreen(), e.getYOnScreen());
if (SwingUtilities.isRightMouseButton(e)) {
showPopupMenu(e, wrapper);
} else if (e.getClickCount() == 2) {
handleDoubleClick(e, gauge, sensor);
}
}
});
wrapper.removeAll();
wrapper.add(gauge, BorderLayout.CENTER);
UpDownImage.trueRepaint(wrapper.getParent());
UpDownImage.trueLayout(wrapper.getParent());
}
return gauge;
private static void showPopupMenu(MouseEvent e, JPanel wrapper) {
JPopupMenu pm = new JPopupMenu();
JMenu gauges = new JMenu("Gauges...");
fillGaugeItems(gauges, wrapper);
pm.add(gauges);
pm.show(e.getComponent(), e.getX(), e.getY());
}
private static void fillGaugeItems(JMenu gauges, final JPanel wrapper) {
for (final Sensor s : Sensor.values()) {
JMenuItem mi = new JMenuItem(s.getName());
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createGaugeBody(s, wrapper);
}
});
gauges.add(mi);
}
}
private static void handleDoubleClick(MouseEvent e, Radial gauge, Sensor sensor) {
int size = gauge.getSize().width;
JFrame n = new JFrame(sensor.getName());
boolean isMockable = MOCKABLE.contains(sensor);
int h = isMockable ? (int) (size * 1.5) : size;
JPanel content = new JPanel(new BorderLayout());
content.add(createGauge(sensor), BorderLayout.CENTER);
if (isMockable)
content.add(createMockVoltageSlider(sensor), BorderLayout.SOUTH);
n.setSize(size, h);
n.setAlwaysOnTop(true);
n.add(content);
n.setVisible(true);
n.setLocation(e.getXOnScreen(), e.getYOnScreen());
}
private final static Hashtable<Integer, JComponent> SLIDER_LABELS = new Hashtable<Integer, JComponent>();

View File

@ -65,7 +65,12 @@ public class UpDownImage extends JPanel {
control.repaint();
}
/**
* todo: one 'trueXXX' method should be enough, which one?
*/
public static void trueLayout(Component component) {
if (component == null)
return;
component.invalidate();
component.validate();
}