altoslib: Handle eeprom tick wrapping
[fw/altos] / altoslib / AltosCalData.java
index fff6ba67a1eee973dbbcccd30542b861b7b5f6e6..54b75817bb7196b2fc8b82cd88c5ca4d5ea0bcd1 100644 (file)
@@ -172,6 +172,7 @@ public class AltosCalData {
                                        tick += 65536;
                                }
                        }
+                       prev_tick = tick;
                        this.tick = tick;
                }
        }
@@ -182,18 +183,24 @@ public class AltosCalData {
                boost_tick = tick;
        }
 
+       public double           ticks_per_sec = 100.0;
+
+       public void set_ticks_per_sec(double ticks_per_sec) {
+               this.ticks_per_sec = ticks_per_sec;
+       }
+
        public double time() {
                if (tick == AltosLib.MISSING)
                        return AltosLib.MISSING;
                if (boost_tick == AltosLib.MISSING)
                        return AltosLib.MISSING;
-               return (tick - boost_tick) / 100.0;
+               return (tick - boost_tick) / ticks_per_sec;
        }
 
        public double boost_time() {
                if (boost_tick == AltosLib.MISSING)
                        return AltosLib.MISSING;
-               return boost_tick / 100.0;
+               return boost_tick / ticks_per_sec;
        }
 
        public int              state = AltosLib.MISSING;
@@ -220,6 +227,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 +238,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 +248,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;
@@ -337,9 +350,16 @@ public class AltosCalData {
 
        public AltosCalData(AltosConfigData config_data) {
                set_serial(config_data.serial);
+               set_ticks_per_sec(100.0);
                set_flight(config_data.flight);
                set_callsign(config_data.callsign);
+               set_config(config_data.config_major, config_data.config_minor, config_data.flight_log_max);
+               set_firmware_version(config_data.version);
+               set_flight_params(config_data.apogee_delay / ticks_per_sec, config_data.apogee_lockout / ticks_per_sec);
+               set_pad_orientation(config_data.pad_orientation);
+               set_product(config_data.product);
                set_accel_plus_minus(config_data.accel_cal_plus, config_data.accel_cal_minus);
+               set_accel_zero(config_data.accel_zero_along, config_data.accel_zero_across, config_data.accel_zero_through);
                set_ms5607(config_data.ms5607);
                try {
                        set_mma655x_inverted(config_data.mma655x_inverted());