altosui: Start idle thread after the rocket leaves the pad
[fw/altos] / ao-tools / altosui / AltosUI.java
index 6a1814ff87034fad92f922779f925b2f10aa81e1..fbce5e14f749ccbf8de2485590344d9d71ffc801 100644 (file)
@@ -277,6 +277,7 @@ public class AltosUI extends JFrame {
 
        class IdleThread extends Thread {
 
+               boolean started;
                private AltosState state;
                int     reported_landing;
 
@@ -346,6 +347,10 @@ public class AltosUI extends JFrame {
                public void notice(AltosState new_state) {
                        AltosState old_state = state;
                        state = new_state;
+                       if (!started && state.state > Altos.ao_flight_pad) {
+                               started = true;
+                               start();
+                       }
                        if (old_state != null && old_state.state != state.state)
                                report(false);
                }
@@ -384,11 +389,12 @@ public class AltosUI extends JFrame {
 
                AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
 
-               void close() { }
+               void close(boolean interrupted) { }
 
                void update(AltosState state) throws InterruptedException { }
 
                public void run() {
+                       boolean         interrupted = false;
                        String          line;
                        AltosState      state = null;
                        AltosState      old_state = null;
@@ -397,7 +403,6 @@ public class AltosUI extends JFrame {
 
                        info_reset();
                        info_finish();
-                       idle_thread.start();
                        try {
                                for (;;) {
                                        try {
@@ -418,14 +423,18 @@ public class AltosUI extends JFrame {
                                        }
                                }
                        } catch (InterruptedException ee) {
+                               interrupted = true;
                        } catch (IOException ie) {
                                JOptionPane.showMessageDialog(AltosUI.this,
                                                              String.format("Error reading from \"%s\"", name),
                                                              "Telemetry Read Error",
                                                              JOptionPane.ERROR_MESSAGE);
                        } finally {
-                               close();
+                               close(interrupted);
                                idle_thread.interrupt();
+                               try {
+                                       idle_thread.join();
+                               } catch (InterruptedException ie) {}
                        }
                }
 
@@ -446,7 +455,7 @@ public class AltosUI extends JFrame {
                        return new AltosTelemetry(l.line);
                }
 
-               void close() {
+               void close(boolean interrupted) {
                        serial.close();
                        serial.remove_monitor(telem);
                }
@@ -530,8 +539,9 @@ public class AltosUI extends JFrame {
                        return null;
                }
 
-               public void close () {
-                       report();
+               public void close (boolean interrupted) {
+                       if (!interrupted)
+                               report();
                }
 
                public ReplayThread(AltosReader in_reader, String in_name) {