From 973af9efe2e086b72bedd274805895bfde65a8e4 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 9 Sep 2014 22:02:45 -0500 Subject: [PATCH] auto-sync --- .../src/com/irnems/core/EngineState.java | 1 + .../models/src/com/irnems/core/Sensor.java | 5 +++ .../src/com/irnems/core/SensorStats.java | 20 ++++++++--- .../com/rusefi/ui/widgets/UpDownImage.java | 33 ++++++++++++++----- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/java_console/models/src/com/irnems/core/EngineState.java b/java_console/models/src/com/irnems/core/EngineState.java index 61eafc79c4..f72c658b03 100644 --- a/java_console/models/src/com/irnems/core/EngineState.java +++ b/java_console/models/src/com/irnems/core/EngineState.java @@ -74,6 +74,7 @@ public class EngineState { SensorStats.start(Sensor.VREF, Sensor.VREF_WIDTH); SensorStats.startStandardDeviation(Sensor.DWELL0, Sensor.DWELL0_SD); + SensorStats.startDelta(Sensor.INJECTOR_1_DWELL, Sensor.INJECTOR_2_DWELL, Sensor.INJ_1_2_DELTA); registerStringValueAction("adcfast_co", NOTHING); registerStringValueAction("adcfast_max", NOTHING); diff --git a/java_console/models/src/com/irnems/core/Sensor.java b/java_console/models/src/com/irnems/core/Sensor.java index ee4233db70..f91a4a051a 100644 --- a/java_console/models/src/com/irnems/core/Sensor.java +++ b/java_console/models/src/com/irnems/core/Sensor.java @@ -67,6 +67,11 @@ public enum Sensor { ADC_FAST("ADC_FAST", "b", 4000), ADC_FAST_AVG("ADC_FAST_AVG", "b", 4000), + INJECTOR_1_DWELL("inj #1"), + INJECTOR_2_DWELL("inj #2"), + + + INJ_1_2_DELTA("inj 1-2 delta"), ; private final String name; diff --git a/java_console/models/src/com/irnems/core/SensorStats.java b/java_console/models/src/com/irnems/core/SensorStats.java index de0be0651b..a75546ef86 100644 --- a/java_console/models/src/com/irnems/core/SensorStats.java +++ b/java_console/models/src/com/irnems/core/SensorStats.java @@ -1,6 +1,7 @@ package com.irnems.core; import com.rusefi.CyclicBuffer; +import com.rusefi.waves.WaveReport; /** * 7/26/13 @@ -41,15 +42,14 @@ public class SensorStats { * http://en.wikipedia.org/wiki/Standard_deviation */ public static void startStandardDeviation(Sensor source, final Sensor destination) { - final CyclicBuffer sb = new CyclicBuffer(30); + final CyclicBuffer cb = new CyclicBuffer(30); SensorCentral.getInstance().addListener(source, new SensorCentral.SensorListener() { @Override public void onSensorUpdate(double value) { - sb.add(value); - - if (sb.getSize() == sb.getMaxSize()) { - double stdDev = sb.getStandardDeviation(); + cb.add(value); + if (cb.getSize() == cb.getMaxSize()) { + double stdDev = cb.getStandardDeviation(); SensorCentral.getInstance().setValue(stdDev, destination); } } @@ -57,4 +57,14 @@ public class SensorStats { ); } + public static void startDelta(Sensor input1, final Sensor input2, final Sensor destination) { + final CyclicBuffer cb = new CyclicBuffer(30); + SensorCentral.getInstance().addListener(input1, new SensorCentral.SensorListener() { + @Override + public void onSensorUpdate(double value) { + double valueMs = 1.0 * (value - SensorCentral.getInstance().getValue(input2)) / WaveReport.SYS_TICKS_PER_MS; + SensorCentral.getInstance().setValue(valueMs, destination); + } + }); + } } diff --git a/java_console/ui/src/com/rusefi/ui/widgets/UpDownImage.java b/java_console/ui/src/com/rusefi/ui/widgets/UpDownImage.java index 1a077ab45b..416df7bc06 100644 --- a/java_console/ui/src/com/rusefi/ui/widgets/UpDownImage.java +++ b/java_console/ui/src/com/rusefi/ui/widgets/UpDownImage.java @@ -1,5 +1,7 @@ package com.rusefi.ui.widgets; +import com.irnems.core.Sensor; +import com.irnems.core.SensorCentral; import com.irnems.waves.TimeAxisTranslator; import com.rusefi.ui.WavePanel; import com.rusefi.waves.WaveReport; @@ -10,6 +12,8 @@ import javax.swing.*; import java.awt.*; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Map; +import java.util.TreeMap; /** * This is a renderer of an individual {@link WaveReport} - this makes a simple Logical Analyzer @@ -17,6 +21,7 @@ import java.util.Date; *

* Date: 6/23/13 * (c) Andrey Belomutskiy + * * @see WavePanel */ public class UpDownImage extends JPanel { @@ -32,6 +37,13 @@ public class UpDownImage extends JPanel { private RevolutionLog time2rpm = RevolutionLog.parseRevolutions(null); private String pin = ""; + private static final Map name2sensor = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + static { + name2sensor.put("inj1", Sensor.INJECTOR_1_DWELL); + name2sensor.put("inj2", Sensor.INJECTOR_2_DWELL); + } + public UpDownImage(final String name) { this(WaveReport.MOCK, name); setToolTip(); @@ -49,10 +61,6 @@ public class UpDownImage extends JPanel { this.zoomProvider = zoomProvider; } - public void onUpdate() { - trueRepaint(this); - } - /** * This does not make any sense :( That's an attempt * to hack http://rusefi.com/forum/viewtopic.php?f=2&t=631&p=10083#p10081 @@ -117,9 +125,21 @@ public class UpDownImage extends JPanel { public void setWaveReport(WaveReport wr, StringBuilder revolutions) { this.wr = wr; + propagateDwellIntoSensor(wr); this.revolutions = revolutions; lastUpdateTime = System.currentTimeMillis(); - onUpdate(); + trueRepaint(this); + } + + private void propagateDwellIntoSensor(WaveReport wr) { + Sensor sensor = name2sensor.get(name); + if (sensor == null) + return; + + if (!wr.getList().isEmpty()) { + WaveReport.UpDown last = wr.getList().get(wr.getList().size() - 1); + SensorCentral.getInstance().setValue(last.getDuration(), sensor); + } } @Override @@ -224,9 +244,6 @@ public class UpDownImage extends JPanel { g.setColor(Color.green); g.drawString(toAngle, x1 + offset, (int) (1.0 * d.height)); - - - } public void setRevolutions(StringBuilder revolutions) {