From 4899fa4e0b8d2b4ab76126bb5d2062aeecc81374 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 4 Mar 2015 22:04:20 -0600 Subject: [PATCH] auto-sync --- .../src/com/rusefi/ui/ConnectionWatchdog.java | 38 +++++++++++++++++++ .../ui/src/com/rusefi/ui/RpmPanel.java | 30 +-------------- 2 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 java_console/ui/src/com/rusefi/ui/ConnectionWatchdog.java diff --git a/java_console/ui/src/com/rusefi/ui/ConnectionWatchdog.java b/java_console/ui/src/com/rusefi/ui/ConnectionWatchdog.java new file mode 100644 index 0000000000..227d77fb48 --- /dev/null +++ b/java_console/ui/src/com/rusefi/ui/ConnectionWatchdog.java @@ -0,0 +1,38 @@ +package com.rusefi.ui; + +import com.rusefi.core.EngineTimeListener; +import com.rusefi.io.LinkManager; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ConnectionWatchdog { + /** + * 10 seconds + */ + private static final int RESTART_DELAY = 10000; + + private ConnectionWatchdog() { + } + + public static void start() { + final Timer reconnectTimer = new Timer(RESTART_DELAY, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + LinkManager.restart(); + } + }); + reconnectTimer.restart(); + + LinkManager.engineState.timeListeners.add(new EngineTimeListener() { + @Override + public void onTime(double time) { + /** + * this timer will reconnect + */ + reconnectTimer.restart(); + } + }); + } +} \ No newline at end of file diff --git a/java_console/ui/src/com/rusefi/ui/RpmPanel.java b/java_console/ui/src/com/rusefi/ui/RpmPanel.java index 1414d0fc8f..d6e15811ed 100644 --- a/java_console/ui/src/com/rusefi/ui/RpmPanel.java +++ b/java_console/ui/src/com/rusefi/ui/RpmPanel.java @@ -1,17 +1,13 @@ package com.rusefi.ui; -import com.rusefi.core.EngineTimeListener; import com.rusefi.core.Sensor; import com.rusefi.ui.storage.Node; import com.rusefi.ui.widgets.*; -import com.rusefi.io.LinkManager; import com.rusefi.ui.widgets.SensorGauge; import net.miginfocom.swing.MigLayout; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; /** * Date: 1/7/13 @@ -43,7 +39,7 @@ public class RpmPanel { gauges.add(SensorGauge.createGauge(Sensor.MAF)); gauges.add(SensorGauge.createGauge(Sensor.TPS)); - startConnectionWatchDog(); + ConnectionWatchdog.start(); JPanel smallMessagePanel = new JPanel(new BorderLayout()); MessagesPanel mp = new MessagesPanel(config); @@ -66,30 +62,6 @@ public class RpmPanel { return rpmPanel; } - private void startConnectionWatchDog() { - final Timer reconnectTimer = new Timer(10000, new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - LinkManager.restart(); - } - }); - reconnectTimer.restart(); - - LinkManager.engineState.timeListeners.add(new EngineTimeListener() { - @Override - public void onTime(double time) { - /** - * this timer will reconnect - */ - postponeReconnecting(reconnectTimer); - } - }); - } - - private void postponeReconnecting(Timer timer2) { - timer2.restart(); - } - private JPanel createControls() { JPanel controls = new JPanel(new MigLayout()); controls.setBorder(BorderFactory.createLineBorder(Color.red));