altoslib: Mark listener as 'not running' on EOF.
[fw/altos] / telegps / TeleGPSStatus.java
index 1d4415d6064d400444891ea769c3a0643a3ac0ea..1eeb7ed5de718e72a50aee8696c411c44e03a568 100644 (file)
@@ -179,11 +179,15 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                long    last_secs = -1;
 
                void show(AltosState state, AltosListenerState listener_state) {
-                       long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
-
-                       if (secs != last_secs) {
-                               value.setText(String.format("%d", secs));
-                               last_secs = secs;
+                       if (listener_state.running) {
+                               long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
+
+                               if (secs != last_secs) {
+                                       value.setText(String.format("%d", secs));
+                                       last_secs = secs;
+                               }
+                       } else {
+                               value.setText("done");
                        }
                }
 
@@ -232,6 +236,8 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                flight.show(state, listener_state);
                rssi.show(state, listener_state);
                last_packet.show(state, listener_state);
+               if (!listener_state.running)
+                       stop();
        }
 
        public int height() {
@@ -239,6 +245,22 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                return d.height;
        }
 
+       TeleGPSStatusUpdate     status_update;
+       javax.swing.Timer       timer;
+
+       public void start(TeleGPSStatusUpdate status_update) {
+               this.status_update = status_update;
+               timer = new javax.swing.Timer(100, status_update);
+               timer.start();
+       }
+
+       public void stop() {
+               if (timer != null) {
+                       timer.stop();
+                       timer = null;
+               }
+       }
+
        public TeleGPSStatus() {
                layout = new GridBagLayout();