altosdroid: Improve voice for TeleGPS
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabPad.java
index 6906324dd594fd5de27a9e346b5f4011ce1b5cae..2d88974d3d787f516c15ea352b6e3936a5cfae84 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_4.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -27,6 +27,7 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.location.Location;
 
 public class TabPad extends Fragment implements AltosDroidTab {
        AltosDroid mAltosDroid;
@@ -100,40 +101,51 @@ public class TabPad extends Fragment implements AltosDroidTab {
                mAltosDroid = null;
        }
 
-       public void update_ui(AltosState state, AltosGreatCircle from_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");
+       public void update_ui(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);
                }
-               mDataLoggingLights.set(state.data.flight != 0);
 
-               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);
-
-               mPadLatitudeView.setText(AltosDroid.pos(state.pad_lat, "N", "S"));
-               mPadLongitudeView.setText(AltosDroid.pos(state.pad_lon, "W", "E"));
-               mPadAltitudeView.setText(String.format("%4.0f m", state.pad_alt));
+               if (receiver != null) {
+                       double altitude = 0;
+                       if (receiver.hasAltitude())
+                               altitude = receiver.getAltitude();
+                       mPadLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
+                       mPadLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
+                       mPadAltitudeView.setText(AltosDroid.number("%4.0f m", altitude));
+               }
        }
 
 }