Reset GPS ready status when GPS comes unlocked on the pad
[fw/altos] / ao-tools / altosui / AltosState.java
index 192011d02955f6c637fa42aabe7f9c917f2cd54b..9aa10a0887502ee80417b5adb44084c07c8c1a7b 100644 (file)
@@ -29,7 +29,7 @@ public class AltosState {
 
        /* derived data */
 
-       double  report_time;
+       long    report_time;
 
        double  time_change;
        int     tick;
@@ -56,8 +56,12 @@ public class AltosState {
        double  pad_lat;
        double  pad_lon;
        double  pad_alt;
+
+       static final int MIN_PAD_SAMPLES = 10;
+
        int     npad;
-       int     prev_npad;
+       int     gps_waiting;
+       boolean gps_ready;
 
        AltosGreatCircle from_pad;
 
@@ -66,11 +70,6 @@ public class AltosState {
        int     speak_tick;
        double  speak_altitude;
 
-       static double
-       aoview_time()
-       {
-               return System.currentTimeMillis() / 1000.0;
-       }
 
        void init (AltosTelemetry cur, AltosState prev_state) {
                int             i;
@@ -82,7 +81,7 @@ public class AltosState {
                ground_altitude = AltosConvert.cc_barometer_to_altitude(data.ground_pres);
                height = AltosConvert.cc_barometer_to_altitude(data.flight_pres) - ground_altitude;
 
-               report_time = aoview_time();
+               report_time = System.currentTimeMillis();
 
                accel_counts_per_mss = ((data.accel_minus_g - data.accel_plus_g) / 2.0) / 9.80665;
                acceleration = (data.ground_accel - data.flight_accel) / accel_counts_per_mss;
@@ -139,8 +138,17 @@ public class AltosState {
                                        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);