altosdroid: Check for missing values
authorKeith Packard <keithp@keithp.com>
Tue, 16 Apr 2013 21:22:23 +0000 (14:22 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 16 Apr 2013 21:22:23 +0000 (14:22 -0700)
When displaying numbers, check for MISSING values and display nothing

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/res/layout/tab_ascent.xml
altosdroid/res/layout/tab_descent.xml
altosdroid/res/layout/tab_pad.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/GoNoGoLights.java
altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java

index d2d721e197c8323cbadeda4634979edc675dddb7..b21ec426a73ccc71184b25e5cedf3018fa2832e0 100644 (file)
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/apogee_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/apogee_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/main_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/main_greenled"
index 56e8a00a64a55b3924b1ae4d35a5585fc62c5b1f..9e1fc820f5150fd90c9740e4222b5c6243c8f86b 100644 (file)
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/apogee_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/apogee_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/main_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/main_greenled"
index a21f9bbbb05b271631c8d5c115ab725165937e79..00d5ea12ddadec61b2fdde2a719d1176672effeb 100644 (file)
@@ -30,7 +30,7 @@
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/battery_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/battery_greenled"
@@ -68,7 +68,7 @@
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/apogee_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/apogee_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/main_voltage_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/main_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/logging_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/logging_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/gps_locked_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/gps_locked_greenled"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/gps_ready_label"
-                       android:src="@drawable/redled" />
+                       android:src="@drawable/grayled" />
 
                <ImageView
                        android:id="@+id/gps_ready_greenled"
index 5ce6f81069eae5bb7222f9d4c447ce211d8b28e1..917d64d603a6663816f2cc6894b80a53fe76df9b 100644 (file)
@@ -265,6 +265,8 @@ public class AltosDroid extends FragmentActivity {
 
        static String pos(double p, String pos, String neg) {
                String  h = pos;
+               if (p == AltosRecord.MISSING)
+                       return "";
                if (p < 0) {
                        h = neg;
                        p = -p;
@@ -274,6 +276,12 @@ public class AltosDroid extends FragmentActivity {
                return String.format("%d°%9.4f\" %s", deg, min, h);
        }
 
+       static String number(String format, double value) {
+               if (value == AltosRecord.MISSING)
+                       return "";
+               return String.format(format, value);
+       }
+
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
index 0f95bc220a78dcf51a62ed870bec1dfd88acd5f1..8e8d9c03a32c9105f0d6553b461a107d773a785e 100644 (file)
@@ -23,6 +23,8 @@ import android.widget.ImageView;
 
 public class GoNoGoLights {
        private Boolean state;
+       private Boolean missing;
+       private Boolean set;
 
        private ImageView red;
        private ImageView green;
@@ -35,16 +37,23 @@ public class GoNoGoLights {
                red = in_red;
                green = in_green;
                state = false;
+               missing = true;
+               set = false;
 
                dRed   = r.getDrawable(R.drawable.redled);
                dGreen = r.getDrawable(R.drawable.greenled);
                dGray  = r.getDrawable(R.drawable.grayled);
        }
 
-       public void set(Boolean s) {
-               if (s == state) return;
+       public void set(Boolean s, Boolean m) {
+               if (set && s == state && m == missing) return;
                state = s;
-               if (state) {
+               missing = m;
+               set = true;
+               if (missing) {
+                       red.setImageDrawable(dGray);
+                       green.setImageDrawable(dGray);
+               } else if (state) {
                        red.setImageDrawable(dGray);
                        green.setImageDrawable(dGreen);
                } else {
index 23d2e97cead2eb9d48e8000316183999a0d7f8b4..0e141ae47e942e2983333a1ef526c79b67b13c2d 100644 (file)
@@ -87,23 +87,26 @@ public class TabAscent extends Fragment implements AltosDroidTab {
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mHeightView.setText(String.format("%6.0f m", state.height));
-                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
-                       mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-                       mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
-                       mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
-                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
+                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height));
+                       mMaxHeightView.setText(AltosDroid.number("%6.0f m", state.max_height));
+                       mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
+                       mMaxSpeedView.setText(AltosDroid.number("%6.0f m/s", state.max_speed()));
+                       mAccelView.setText(AltosDroid.number("%6.0f m/s²", state.acceleration));
+                       mMaxAccelView.setText(AltosDroid.number("%6.0f m/s²", state.max_acceleration));
 
                        if (state.gps != null) {
                                mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
                                mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+                       } else {
+                               mLatitudeView.setText("");
+                               mLongitudeView.setText("");
                        }
 
-                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
 
-                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
                }
        }
 }
index 49774a3030b87eb810970f908388662a25e862a1..09e7169b229ff1c126405ac9f8fe8a3fdbedabc6 100644 (file)
@@ -91,14 +91,14 @@ public class TabDescent extends Fragment implements AltosDroidTab {
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-                       mHeightView.setText(String.format("%6.0f m", state.height));
+                       mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
+                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height));
                        if (from_receiver != null) {
-                               mElevationView.setText(String.format("%3.0f°", from_receiver.elevation));
-                               mRangeView.setText(String.format("%6.0f m", from_receiver.range));
-                               mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+                               mElevationView.setText(AltosDroid.number("%3.0f°", from_receiver.elevation));
+                               mRangeView.setText(AltosDroid.number("%6.0f m", from_receiver.range));
+                               mBearingView.setText(AltosDroid.number("%3.0f°", from_receiver.bearing));
                                mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
-                               mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
+                               mDistanceView.setText(AltosDroid.number("%6.0f m", from_receiver.distance));
                        } else { 
                                mElevationView.setText("<unknown>");
                                mRangeView.setText("<unknown>");
@@ -111,11 +111,11 @@ public class TabDescent extends Fragment implements AltosDroidTab {
                                mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
                        }
 
-                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
 
-                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
                }
        }
 
index 3c168e37d4f69a4740f4a9567b37f6304d478fc7..8b3c401290055006cd7332652265b3d7e09d470e 100644 (file)
@@ -103,14 +103,14 @@ public class TabPad extends Fragment implements AltosDroidTab {
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
-                       mBatteryLights.set(state.battery > 3.7);
+                       mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery));
+                       mBatteryLights.set(state.battery > 3.7, state.battery == AltosRecord.MISSING);
 
-                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
 
-                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
 
                        if (state.data.flight != 0) {
                                if (state.data.state <= AltosLib.ao_flight_pad)
@@ -122,17 +122,18 @@ public class TabPad extends Fragment implements AltosDroidTab {
                        } else {
                                mDataLoggingView.setText("Storage full");
                        }
-                       mDataLoggingLights.set(state.data.flight != 0);
+                       mDataLoggingLights.set(state.data.flight != 0, state.data.flight != AltosRecord.MISSING);
 
                        if (state.gps != null) {
-                               mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat));
-                               mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4);
+                               mGPSLockedView.setText(AltosDroid.number("%4d sats", state.gps.nsat));
+                               mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4, false);
                                if (state.gps_ready)
                                        mGPSReadyView.setText("Ready");
                                else
-                                       mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting));
-                               mGPSReadyLights.set(state.gps_ready);
-                       }
+                                       mGPSReadyView.setText(AltosDroid.number("Waiting %d", state.gps_waiting));
+                       } else
+                               mGPSLockedLights.set(false, true);
+                       mGPSReadyLights.set(state.gps_ready, state.gps == null);
                }
 
                if (receiver != null) {
@@ -141,7 +142,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));
                }
        }