add compass bearing during descent
[fw/altos] / ao-tools / altosui / AltosDisplayThread.java
index 9cc3d5ce9eb273ae49bab05d2fee22b2642d4d62..375965b904d68364e495a3c2081ab0de46dbad64 100644 (file)
@@ -30,13 +30,18 @@ import java.util.concurrent.LinkedBlockingQueue;
 
 public class AltosDisplayThread extends Thread {
 
-       Frame           parent;
-       IdleThread      idle_thread;
-       AltosVoice      voice;
-       String          name;
-       int             crc_errors;
-       AltosStatusTable flightStatus;
-       AltosInfoTable flightInfo;
+       Frame                   parent;
+       IdleThread              idle_thread;
+       AltosVoice              voice;
+       String                  name;
+       AltosFlightReader       reader;
+       int                     crc_errors;
+       AltosFlightDisplay      display;
+
+       synchronized void show(AltosState state, int crc_errors) {
+               if (state != null)
+                       display.show(state, crc_errors);
+       }
 
        class IdleThread extends Thread {
 
@@ -64,8 +69,10 @@ public class AltosDisplayThread extends Thread {
                            state.state < Altos.ao_flight_landed &&
                            state.range >= 0)
                        {
-                               voice.speak("Height %d, bearing %d, elevation %d, range %d.\n",
+                               voice.speak("Height %d, bearing %s %d, elevation %d, range %d.\n",
                                            (int) (state.height + 0.5),
+                        state.from_pad.bearing_words(
+                            AltosGreatCircle.BEARING_VOICE),
                                            (int) (state.from_pad.bearing + 0.5),
                                            (int) (state.elevation + 0.5),
                                            (int) (state.range + 0.5));
@@ -93,6 +100,10 @@ public class AltosDisplayThread extends Thread {
                                                    (int) (state.from_pad.bearing + 0.5),
                                                    (int) (state.from_pad.distance + 0.5));
                                ++reported_landing;
+                               if (state.state != Altos.ao_flight_landed) {
+                                       state.state = Altos.ao_flight_landed;
+                                       show(state, 0);
+                               }
                        }
                }
 
@@ -150,14 +161,6 @@ public class AltosDisplayThread extends Thread {
                }
        }
 
-       void init() { }
-
-       AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
-
-       void close(boolean interrupted) { }
-
-       void update(AltosState state) throws InterruptedException { }
-
        boolean tell(AltosState state, AltosState old_state) {
                boolean ret = false;
                if (old_state == null || old_state.state != state.state) {
@@ -188,13 +191,6 @@ public class AltosDisplayThread extends Thread {
                return ret;
        }
 
-       void show(AltosState state, int crc_errors) {
-               if (state != null) {
-                       flightStatus.set(state);
-                       flightInfo.show(state, crc_errors);
-               }
-       }
-
        public void run() {
                boolean         interrupted = false;
                String          line;
@@ -204,16 +200,16 @@ public class AltosDisplayThread extends Thread {
 
                idle_thread = new IdleThread();
 
-               flightInfo.clear();
+               display.reset();
                try {
                        for (;;) {
                                try {
-                                       AltosRecord record = read();
+                                       AltosRecord record = reader.read();
                                        if (record == null)
                                                break;
                                        old_state = state;
                                        state = new AltosState(record, state);
-                                       update(state);
+                                       reader.update(state);
                                        show(state, crc_errors);
                                        told = tell(state, old_state);
                                        idle_thread.notice(state, told);
@@ -232,7 +228,9 @@ public class AltosDisplayThread extends Thread {
                                                      "Telemetry Read Error",
                                                      JOptionPane.ERROR_MESSAGE);
                } finally {
-                       close(interrupted);
+                       if (!interrupted)
+                               idle_thread.report(true);
+                       reader.close(interrupted);
                        idle_thread.interrupt();
                        try {
                                idle_thread.join();
@@ -240,16 +238,10 @@ public class AltosDisplayThread extends Thread {
                }
        }
 
-       public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info) {
+       public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) {
                parent = in_parent;
                voice = in_voice;
-               flightStatus = in_status;
-               flightInfo = in_info;
+               display = in_display;
+               reader = in_reader;
        }
-
-       public void report() {
-               if (idle_thread != null)
-                       idle_thread.report(true);
-       }
-
 }