diff --git a/java_console/models/src/com/rusefi/core/ISensorCentral.java b/java_console/models/src/com/rusefi/core/ISensorCentral.java new file mode 100644 index 0000000000..3ec2f89939 --- /dev/null +++ b/java_console/models/src/com/rusefi/core/ISensorCentral.java @@ -0,0 +1,19 @@ +package com.rusefi.core; + +/** + * 11/16/2017 + * (c) Andrey Belomutskiy + */ +public interface ISensorCentral { + double getValue(Sensor sensor); + + void setValue(double value, Sensor sensor); + + void setAnySensorListener(SensorCentral.SensorListener2 anySensorListener); + + void addListener(Sensor sensor, SensorCentral.SensorListener listener); + + void removeListener(Sensor sensor, SensorCentral.SensorListener listener); + + void initialize(EngineState es); +} diff --git a/java_console/models/src/com/rusefi/core/SensorCentral.java b/java_console/models/src/com/rusefi/core/SensorCentral.java index 755df87f1a..609af58783 100644 --- a/java_console/models/src/com/rusefi/core/SensorCentral.java +++ b/java_console/models/src/com/rusefi/core/SensorCentral.java @@ -12,22 +12,23 @@ import java.util.concurrent.CopyOnWriteArrayList; * Date: 1/6/13 * (c) Andrey Belomutskiy */ -public class SensorCentral { +public class SensorCentral implements ISensorCentral { public static final String RPM_KEY = "rpm"; private static final SensorCentral INSTANCE = new SensorCentral(); private final Map values = new EnumMap<>(Sensor.class); private final Map> allListeners = new EnumMap<>(Sensor.class); - public SensorListener2 anySensorListener; + private SensorListener2 anySensorListener; - public static SensorCentral getInstance() { + public static ISensorCentral getInstance() { return INSTANCE; } private SensorCentral() { } + @Override public double getValue(Sensor sensor) { Double value = values.get(sensor); if (value == null) @@ -35,6 +36,7 @@ public class SensorCentral { return value; } + @Override public void setValue(double value, final Sensor sensor) { Double oldValue = values.get(sensor); boolean isUpdated = oldValue == null || !oldValue.equals(value); @@ -58,6 +60,12 @@ public class SensorCentral { anySensorListener.onSensorUpdate(sensor, value); } + @Override + public void setAnySensorListener(SensorListener2 anySensorListener) { + this.anySensorListener = anySensorListener; + } + + @Override public void addListener(Sensor sensor, SensorListener listener) { List listeners; synchronized (allListeners) { @@ -69,6 +77,7 @@ public class SensorCentral { listeners.add(listener); } + @Override public void removeListener(Sensor sensor, SensorListener listener) { List listeners; synchronized (allListeners) { @@ -78,6 +87,7 @@ public class SensorCentral { listeners.remove(listener); } + @Override public void initialize(EngineState es) { addDoubleSensor(RPM_KEY, Sensor.RPM, es); addDoubleSensor("mat", Sensor.IAT, es); diff --git a/java_console/romraider/src/com/romraider/logger/ecu/ui/handler/table/TableUpdateHandler.java b/java_console/romraider/src/com/romraider/logger/ecu/ui/handler/table/TableUpdateHandler.java index 5b28fab035..48c28bcbb4 100644 --- a/java_console/romraider/src/com/romraider/logger/ecu/ui/handler/table/TableUpdateHandler.java +++ b/java_console/romraider/src/com/romraider/logger/ecu/ui/handler/table/TableUpdateHandler.java @@ -75,7 +75,7 @@ public final class TableUpdateHandler { }; - SensorCentral.getInstance().anySensorListener = new SensorCentral.SensorListener2() { + SensorCentral.getInstance().setAnySensorListener(new SensorCentral.SensorListener2() { @Override public void onSensorUpdate(final Sensor sensor, double value) { ResponseImpl r = new ResponseImpl(); @@ -131,7 +131,7 @@ public final class TableUpdateHandler { TableUpdateHandler.getInstance().handleDataUpdate(r); } - }; + }); } private TableUpdateHandler() { diff --git a/java_console/ui/src/com/rusefi/ui/FuelTunePane.java b/java_console/ui/src/com/rusefi/ui/FuelTunePane.java index 7b1852627f..c1ce6faec6 100644 --- a/java_console/ui/src/com/rusefi/ui/FuelTunePane.java +++ b/java_console/ui/src/com/rusefi/ui/FuelTunePane.java @@ -15,6 +15,7 @@ import com.rusefi.autotune.stDataOnline; import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.BinaryProtocolHolder; import com.rusefi.config.Fields; +import com.rusefi.core.ISensorCentral; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.ui.config.BaseConfigField; @@ -282,7 +283,7 @@ public class FuelTunePane { } public void showContent() { - final SensorCentral sc = SensorCentral.getInstance(); + final ISensorCentral sc = SensorCentral.getInstance(); sc.addListener(Sensor.RPM, new SensorCentral.SensorListener() { @Override public void onSensorUpdate(double value) {