altoslib: Create data file open helper in AltosLib
[fw/altos] / altosui / AltosPad.java
index 2f87b6818db55e5c86a7efd8ebb65508bd5d2dde..73da9933501a0707d470f62c7acd1c261ce1c9a9 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +19,8 @@
 package altosui;
 
 import java.util.*;
-import org.altusmetrum.altoslib_8.*;
-import org.altusmetrum.altosuilib_8.*;
+import org.altusmetrum.altoslib_11.*;
+import org.altusmetrum.altosuilib_11.*;
 
 public class AltosPad extends AltosUIFlightTab {
 
@@ -45,20 +46,20 @@ public class AltosPad extends AltosUIFlightTab {
 
        class LoggingReady extends AltosUIIndicator {
                public void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.flight == AltosLib.MISSING) {
+                       if (state == null || state.cal_data.flight == AltosLib.MISSING) {
                                hide();
                        } else {
-                               if (state.flight != 0) {
-                                       if (state.state <= Altos.ao_flight_pad)
+                               if (state.cal_data.flight != 0) {
+                                       if (state.state() <= Altos.ao_flight_pad)
                                                show("Ready to record");
-                                       else if (state.state < Altos.ao_flight_landed ||
-                                                state.state == AltosLib.ao_flight_stateless)
+                                       else if (state.state() < Altos.ao_flight_landed ||
+                                                state.state() == AltosLib.ao_flight_stateless)
                                                show("Recording data");
                                        else
                                                show("Recorded data");
                                } else
                                        show("Storage full");
-                               set_lights(state.flight != 0);
+                               set_lights(state.cal_data.flight != 0);
                        }
                }
                public LoggingReady (AltosUIFlightTab container, int y) {
@@ -101,7 +102,11 @@ public class AltosPad extends AltosUIFlightTab {
 
        class ReceiverBattery extends AltosUIVoltageIndicator {
 
-               public double voltage(AltosState state) { return AltosLib.MISSING; }
+               double  last_voltage = AltosLib.MISSING;
+
+               public double voltage(AltosState state) {
+                       return last_voltage;
+               }
 
                public double good() { return AltosLib.ao_battery_good; }
 
@@ -111,8 +116,10 @@ public class AltosPad extends AltosUIFlightTab {
 
                public double value(AltosState state, AltosListenerState listener_state, int i) {
                        if (listener_state == null)
-                               return AltosLib.MISSING;
-                       return listener_state.battery;
+                               last_voltage = AltosLib.MISSING;
+                       else
+                               last_voltage = listener_state.battery;
+                       return last_voltage;
                }
 
                public ReceiverBattery (AltosUIFlightTab container, int y) {
@@ -121,8 +128,8 @@ public class AltosPad extends AltosUIFlightTab {
        }
 
        boolean report_pad(AltosState state) {
-               if ((state.state == AltosLib.ao_flight_stateless ||
-                    state.state < AltosLib.ao_flight_pad) &&
+               if ((state.state() == AltosLib.ao_flight_stateless ||
+                    state.state() < AltosLib.ao_flight_pad) &&
                    state.gps != null &&
                    state.gps.lat != AltosLib.MISSING)
                {
@@ -205,40 +212,26 @@ public class AltosPad extends AltosUIFlightTab {
                }
        }
 
-       class PadAlt extends AltosUIIndicator {
+       class PadAlt extends AltosUIUnitsIndicator {
 
-               double  last_alt = AltosLib.MISSING - 1;
+               public double value(AltosState state, int i) {
+                       if (report_pad(state))
+                               return state.pad_alt;
+                       else
+                               return state.gps.alt;
+               }
 
                public void show (AltosState state, AltosListenerState listener_state) {
-                       double alt = AltosLib.MISSING;
-                       String label = null;
+                       String label = "Altitude";
 
-                       if (state != null) {
-                               if (report_pad(state)) {
-                                       alt = state.pad_alt;
-                                       label = "Pad Altitude";
-                               } else {
-                                       alt = state.gps.alt;
-                                       label = "Altitude";
-                               }
-                       }
-                       if (alt != last_alt) {
-                               if (alt != AltosLib.MISSING) {
-                                       show(AltosConvert.height.show(5, alt));
-                                       set_label(label);
-                               } else
-                                       hide();
-                               last_alt = alt;
-                       }
-               }
-
-               public void reset() {
-                       super.reset();
-                       last_alt =  AltosLib.MISSING - 1;
+                       if (state != null && report_pad(state))
+                               label = "Pad Altitude";
+                       set_label(label);
+                       super.show(state, listener_state);
                }
 
                public PadAlt (AltosUIFlightTab container, int y) {
-                       super (container, y, "Pad Altitude", 1, false, 2);
+                       super (container, y, AltosConvert.height, "Pad Altitude", 1, false, 2);
                }
        }
        public String getName() { return "Pad"; }