java: Bump java library versions for next release
[fw/altos] / micropeak / MicroStats.java
index 056fac7..3fc05bd 100644 (file)
@@ -18,8 +18,8 @@
 package org.altusmetrum.micropeak;
 
 import java.io.*;
-import org.altusmetrum.AltosLib.*;
-import org.altusmetrum.altosuilib.*;
+import org.altusmetrum.altoslib_5.*;
+import org.altusmetrum.altosuilib_3.*;
 
 public class MicroStats {
        double          coast_height;
@@ -58,12 +58,17 @@ public class MicroStats {
        }
 
        void find_apogee() {
-               apogee_height = 0;
+               apogee_height = data.apogee_height();
+               double searched_apogee = 0;
                apogee_time = 0;
                
+               /* This just finds the apogee time -- we've recorded the
+                * peak altitude separately in eeprom, and that could
+                * have occurred after the eeprom was full.
+                */
                for (MicroDataPoint point : data.points()) {
-                       if (point.height > apogee_height) {
-                               apogee_height = point.height;
+                       if (point.height > searched_apogee) {
+                               searched_apogee = point.height;
                                apogee_time = point.time;
                        }
                }
@@ -145,6 +150,43 @@ public class MicroStats {
                return descent_height() / descent_duration();
        }
 
+       public static final int state_startup = -1;
+       public static final int state_pad = 0;
+       public static final int state_boost = 1;
+       public static final int state_coast = 2;
+       public static final int state_descent = 3;
+       public static final int state_landed = 4;
+
+       static final String state_names[] = {
+               "pad",
+               "boost",
+               "coast",
+               "descent",
+               "landed"
+       };
+
+       public int state(double t) {
+               if (t >= landed_time)
+                       return state_landed;
+               if (t >= apogee_time)
+                       return state_descent;
+               if (t >= coast_time)
+                       return state_coast;
+               if (t >= 0)
+                       return state_boost;
+               return state_pad;
+       }
+
+       public static String state_name(int state) {
+               if (state < 0 || state > state_landed)
+                       return "unknown";
+               return state_names[state];
+       }
+
+       public String state_name(double t) {
+               return state_name(state(t));
+       }
+
        public MicroStats(MicroData data) {
 
                this.data = data;