altosui: Ship telemini v3.0 firmware
[fw/altos] / altosui / AltosFlightStatus.java
index 46c0b38736d5c9d4c53bf1c1519634ebee9765b4..4288fc9feea97c9d647285b82a4e687356f7b7d9 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,8 +20,8 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_4.*;
-import org.altusmetrum.altosuilib_2.*;
+import org.altusmetrum.altoslib_11.*;
+import org.altusmetrum.altosuilib_11.*;
 
 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
@@ -173,14 +174,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                int     last_state = -1;
 
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.state != last_state) {
-                               if (state.state == AltosLib.ao_flight_stateless)
+                       if (state.state() != last_state) {
+                               if (state.state() == AltosLib.ao_flight_stateless)
                                        hide();
                                else {
                                        show();
                                        value.setText(state.state_name());
                                }
-                               last_state = state.state;
+                               last_state = state.state();
                        }
                }
 
@@ -229,10 +230,14 @@ public class AltosFlightStatus 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");
                        }
                }
 
@@ -276,6 +281,8 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                flight_state.show(state, listener_state);
                rssi.show(state, listener_state);
                last_packet.show(state, listener_state);
+               if (!listener_state.running)
+                       stop();
        }
 
        public int height() {
@@ -285,6 +292,22 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        public String getName() { return "Flight Status"; }
 
+       AltosFlightStatusUpdate status_update;
+       javax.swing.Timer       timer;
+
+       public void start(AltosFlightStatusUpdate 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 AltosFlightStatus() {
                layout = new GridBagLayout();