altosdroid: Skip updating hidden UI elements
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabPad.java
index 5070ec0bb0a33d765a33bc067a2f9f285bf2a105..03b78b75dbf29a0cfa9e24b766358bee9d388853 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_5.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -29,7 +29,7 @@ import android.widget.ImageView;
 import android.widget.TextView;
 import android.location.Location;
 
-public class TabPad extends Fragment implements AltosDroidTab {
+public class TabPad extends AltosDroidTab {
        AltosDroid mAltosDroid;
 
        private TextView mBatteryVoltageView;
@@ -101,36 +101,43 @@ public class TabPad extends Fragment implements AltosDroidTab {
                mAltosDroid = null;
        }
 
-       public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
-               mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
-               mBatteryLights.set(state.battery > 3.7);
-
-               mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-               mApogeeLights.set(state.drogue_sense > 3.2);
-
-               mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-               mMainLights.set(state.main_sense > 3.2);
-
-               if (state.data.flight != 0) {
-                       if (state.data.state <= AltosLib.ao_flight_pad)
-                               mDataLoggingView.setText("Ready to record");
-                       else if (state.data.state < AltosLib.ao_flight_landed)
-                               mDataLoggingView.setText("Recording data");
-                       else
-                               mDataLoggingView.setText("Recorded data");
-               } else {
-                       mDataLoggingView.setText("Storage full");
-               }
-               mDataLoggingLights.set(state.data.flight != 0);
-
-               if (state.gps != null) {
-                       mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat));
-                       mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4);
-                       if (state.gps_ready)
-                               mGPSReadyView.setText("Ready");
-                       else
-                               mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting));
-                       mGPSReadyLights.set(state.gps_ready);
+       public String tab_name() { return "pad"; }
+
+       public void show(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
+               if (state != null) {
+                       mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery_voltage));
+                       mBatteryLights.set(state.battery_voltage >= AltosLib.ao_battery_good, state.battery_voltage == AltosLib.MISSING);
+
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage >= AltosLib.ao_igniter_good, state.apogee_voltage == AltosLib.MISSING);
+
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING);
+
+                       if (state.flight != 0) {
+                               if (state.state <= AltosLib.ao_flight_pad)
+                                       mDataLoggingView.setText("Ready to record");
+                               else if (state.state < AltosLib.ao_flight_landed)
+                                       mDataLoggingView.setText("Recording data");
+                               else
+                                       mDataLoggingView.setText("Recorded data");
+                       } else {
+                               mDataLoggingView.setText("Storage full");
+                       }
+                       mDataLoggingLights.set(state.flight != 0, state.flight == AltosLib.MISSING);
+
+                       if (state.gps != null) {
+                               int soln = state.gps.nsat;
+                               int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
+                               mGPSLockedView.setText(String.format("%4d in soln, %4d in view", soln, nsat));
+                               mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4, false);
+                               if (state.gps_ready)
+                                       mGPSReadyView.setText("Ready");
+                               else
+                                       mGPSReadyView.setText(AltosDroid.integer("Waiting %d", state.gps_waiting));
+                       } else
+                               mGPSLockedLights.set(false, true);
+                       mGPSReadyLights.set(state.gps_ready, state.gps == null);
                }
 
                if (receiver != null) {
@@ -139,7 +146,7 @@ public class TabPad extends Fragment implements AltosDroidTab {
                                altitude = receiver.getAltitude();
                        mPadLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
                        mPadLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
-                       mPadAltitudeView.setText(String.format("%4.0f m", altitude));
+                       mPadAltitudeView.setText(AltosDroid.number("%4.0f m", altitude));
                }
        }