Reset GPS ready status when GPS comes unlocked on the pad
authorKeith Packard <keithp@keithp.com>
Thu, 29 Jul 2010 04:49:23 +0000 (21:49 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 29 Jul 2010 04:49:23 +0000 (21:49 -0700)
If GPS becomes unlocked, then report that in the UI and via
voice.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosState.java
ao-tools/altosui/AltosUI.java

index 59a1999e693d20b59514ebb79e04f9f1e151e850..9aa10a0887502ee80417b5adb44084c07c8c1a7b 100644 (file)
@@ -56,8 +56,12 @@ public class AltosState {
        double  pad_lat;
        double  pad_lon;
        double  pad_alt;
        double  pad_lat;
        double  pad_lon;
        double  pad_alt;
+
+       static final int MIN_PAD_SAMPLES = 10;
+
        int     npad;
        int     npad;
-       int     prev_npad;
+       int     gps_waiting;
+       boolean gps_ready;
 
        AltosGreatCircle from_pad;
 
 
        AltosGreatCircle from_pad;
 
@@ -134,8 +138,17 @@ public class AltosState {
                                        pad_lon = data.gps.lon;
                                        pad_alt = data.gps.alt;
                                }
                                        pad_lon = data.gps.lon;
                                        pad_alt = data.gps.alt;
                                }
+                       } else {
+                               npad = 0;
                        }
                }
                        }
                }
+
+               gps_waiting = MIN_PAD_SAMPLES - npad;
+               if (gps_waiting < 0)
+                       gps_waiting = 0;
+
+               gps_ready = gps_waiting == 0;
+
                ascent = (AltosTelemetry.ao_flight_boost <= state &&
                          state <= AltosTelemetry.ao_flight_coast);
 
                ascent = (AltosTelemetry.ao_flight_boost <= state &&
                          state <= AltosTelemetry.ao_flight_coast);
 
index 5c771df20816993e6d700f9e481b0eb1a11f0d9f..4994f093dcbfed6eb80e7c9534a2715fea65843a 100644 (file)
@@ -243,17 +243,15 @@ public class AltosUI extends JFrame {
                        flightInfoModel[i].finish();
        }
 
                        flightInfoModel[i].finish();
        }
 
-       static final int MIN_PAD_SAMPLES = 10;
-
        public void show(AltosState state) {
                flightStatusModel.set(state);
 
                info_reset();
        public void show(AltosState state) {
                flightStatusModel.set(state);
 
                info_reset();
-               if (state.npad >= MIN_PAD_SAMPLES)
+               if (state.gps_ready)
                        info_add_row(0, "Ground state", "%s", "ready");
                else
                        info_add_row(0, "Ground state", "wait (%d)",
                        info_add_row(0, "Ground state", "%s", "ready");
                else
                        info_add_row(0, "Ground state", "wait (%d)",
-                                    MIN_PAD_SAMPLES - state.npad);
+                                    state.gps_waiting);
                info_add_row(0, "Rocket state", "%s", state.data.state);
                info_add_row(0, "Callsign", "%s", state.data.callsign);
                info_add_row(0, "Rocket serial", "%6d", state.data.serial);
                info_add_row(0, "Rocket state", "%s", state.data.state);
                info_add_row(0, "Callsign", "%s", state.data.callsign);
                info_add_row(0, "Rocket serial", "%6d", state.data.serial);
@@ -413,6 +411,12 @@ public class AltosUI extends JFrame {
                                            (int) (state.max_height + 0.5));
                        }
                }
                                            (int) (state.max_height + 0.5));
                        }
                }
+               if (old_state == null || old_state.gps_ready != state.gps_ready) {
+                       if (state.gps_ready)
+                               voice.speak("GPS ready");
+                       else if (old_state != null)
+                               voice.speak("GPS lost");
+               }
                old_state = state;
        }
 
                old_state = state;
        }