altoslib: Preserve old GPS data during operation
authorKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 01:46:00 +0000 (18:46 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 May 2017 01:46:00 +0000 (18:46 -0700)
This avoids having the lat/lon values blank out when the GPS receiver
looses lock.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosCalData.java

index fff6ba67a1eee973dbbcccd30542b861b7b5f6e6..ae0a9294800348cc396445cf7ffc1a1e749820f6 100644 (file)
@@ -220,6 +220,7 @@ public class AltosCalData {
         * object and then deliver the result atomically to the listener
         */
        AltosGPS                temp_gps = null;
+       AltosGPS                prev_gps = null;
        int                     temp_gps_sat_tick = AltosLib.MISSING;
 
        public AltosGPS temp_gps() {
@@ -230,6 +231,7 @@ public class AltosCalData {
                if (temp_gps != null) {
                        if (temp_gps.locked && temp_gps.nsat >= 4)
                                set_gps(temp_gps);
+                       prev_gps = temp_gps;
                        temp_gps = null;
                }
        }
@@ -239,8 +241,12 @@ public class AltosCalData {
        }
 
        public AltosGPS make_temp_gps(int tick, boolean sats) {
-               if (temp_gps == null)
-                       temp_gps = new AltosGPS();
+               if (temp_gps == null) {
+                       if (prev_gps != null)
+                               temp_gps = prev_gps.clone();
+                       else
+                               temp_gps = new AltosGPS();
+               }
                if (sats) {
                        if (tick != temp_gps_sat_tick)
                                temp_gps.cc_gps_sat = null;