altosui: Remove graph series which aren't available
authorKeith Packard <keithp@keithp.com>
Mon, 11 Feb 2013 18:34:47 +0000 (10:34 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 11 Feb 2013 18:40:19 +0000 (10:40 -0800)
Make sure all graph series have actual data underlying them by
checking the available data before creating the series objects.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosFlightStats.java
altosui/AltosFlightStatsTable.java
altosui/AltosGraph.java
altosui/AltosGraphUI.java

index 7f0c9adba49e0c4f6b44dde0a2741b7280925d36..da06bb3d3ea1f4de9d5de38fb0fa690503c3c357 100644 (file)
@@ -36,6 +36,9 @@ public class AltosFlightStats {
        int             hour, minute, second;
        double          lat, lon;
        double          pad_lat, pad_lon;
+       boolean         has_gps;
+       boolean         has_other_adc;
+       boolean         has_rssi;
 
        double landed_time(AltosRecordIterable iterable) {
                AltosState      state = null;
@@ -101,11 +104,18 @@ public class AltosFlightStats {
                hour = minute = second = -1;
                serial = flight = -1;
                lat = lon = -1;
+               has_gps = false;
+               has_other_adc = false;
+               has_rssi = false;
                for (AltosRecord record : iterable) {
                        if (serial < 0)
                                serial = record.serial;
                        if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
                                flight = record.flight;
+                       if ((record.seen & AltosRecord.seen_temp_volt) != 0)
+                               has_other_adc = true;
+                       if (record.rssi != 0)
+                               has_rssi = true;
                        new_state = new AltosState(record, state);
                        end_time = new_state.time;
                        state = new_state;
@@ -147,6 +157,7 @@ public class AltosFlightStats {
                                }
                                lat = state.gps.lat;
                                lon = state.gps.lon;
+                               has_gps = true;
                        }
                }
                for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
index 5ed53c1a8a716786fba14abbe6ab7b407f3d1054..a35b5f637e71e1daf269d824d2a4bd5673ef1867 100644 (file)
@@ -126,7 +126,7 @@ public class AltosFlightStatsTable extends JComponent {
                new FlightStat(layout, y++, "Flight time",
                               String.format("%6.1f s", stats.state_end[Altos.ao_flight_main] -
                                             stats.state_start[Altos.ao_flight_boost]));
-               if (stats.lat != -1 && stats.lon != -1) {
+               if (stats.has_gps) {
                        new FlightStat(layout, y++, "Pad location",
                                       pos(stats.pad_lat,"N","S"),
                                       pos(stats.pad_lon,"E","W"));
index 5bd756ecc1c4c0f1db3bc99b592ccbb3b4360ba1..defe69a0082cdca7a061331cd5086bf3404e772a 100644 (file)
@@ -118,7 +118,7 @@ public class AltosGraph extends AltosUIGraph {
        AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
        AltosUIAxis     distance_axis;
 
-       public AltosGraph(AltosUIEnable enable) {
+       public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
                super(enable);
 
                height_axis = newAxis("Height", AltosConvert.height, height_color);
@@ -150,65 +150,72 @@ public class AltosGraph extends AltosUIGraph {
                          accel_color,
                          true,
                          accel_axis);
-               addSeries("Range",
-                         AltosGraphDataPoint.data_range,
-                         AltosConvert.distance,
-                         range_color,
-                         false,
-                         distance_axis);
-               addSeries("Distance",
-                         AltosGraphDataPoint.data_distance,
-                         AltosConvert.distance,
-                         distance_color,
-                         false,
-                         distance_axis);
-               addSeries("GPS Height",
-                         AltosGraphDataPoint.data_gps_height,
-                         AltosConvert.height,
-                         gps_height_color,
-                         false,
-                         height_axis);
-               addSeries("GPS Satellites in Solution",
-                         AltosGraphDataPoint.data_gps_nsat_solution,
-                         nsat_units,
-                         gps_nsat_solution_color,
-                         false,
-                         nsat_axis);
-               addSeries("GPS Satellites in View",
-                         AltosGraphDataPoint.data_gps_nsat_view,
-                         nsat_units,
-                         gps_nsat_view_color,
-                         false,
+               if (stats.has_gps) {
+                       addSeries("Range",
+                                 AltosGraphDataPoint.data_range,
+                                 AltosConvert.distance,
+                                 range_color,
+                                 false,
+                                 distance_axis);
+                       addSeries("Distance",
+                                 AltosGraphDataPoint.data_distance,
+                                 AltosConvert.distance,
+                                 distance_color,
+                                 false,
+                                 distance_axis);
+                       addSeries("GPS Height",
+                                 AltosGraphDataPoint.data_gps_height,
+                                 AltosConvert.height,
+                                 gps_height_color,
+                                 false,
+                                 height_axis);
+                       addSeries("GPS Satellites in Solution",
+                                 AltosGraphDataPoint.data_gps_nsat_solution,
+                                 nsat_units,
+                                 gps_nsat_solution_color,
+                                 false,
+                                 nsat_axis);
+                       addSeries("GPS Satellites in View",
+                                 AltosGraphDataPoint.data_gps_nsat_view,
+                                 nsat_units,
+                                 gps_nsat_view_color,
+                                 false,
                          nsat_axis);
-               addSeries("Received Signal Strength",
-                         AltosGraphDataPoint.data_rssi,
-                         dbm_units,
-                         dbm_color,
-                         false,
-                         dbm_axis);
-               addSeries("Temperature",
-                         AltosGraphDataPoint.data_temperature,
-                         AltosConvert.temperature,
-                         temperature_color,
-                         false,
-                         temperature_axis);
-               addSeries("Battery Voltage",
-                         AltosGraphDataPoint.data_battery_voltage,
-                         voltage_units,
-                         battery_voltage_color,
-                         false,
-                         voltage_axis);
-               addSeries("Drogue Voltage",
-                         AltosGraphDataPoint.data_drogue_voltage,
-                         voltage_units,
-                         drogue_voltage_color,
-                         false,
-                         voltage_axis);
-               addSeries("Main Voltage",
-                         AltosGraphDataPoint.data_main_voltage,
-                         voltage_units,
-                         main_voltage_color,
-                         false,
-                         voltage_axis);
+               }
+               if (stats.has_rssi)
+                       addSeries("Received Signal Strength",
+                                 AltosGraphDataPoint.data_rssi,
+                                 dbm_units,
+                                 dbm_color,
+                                 false,
+                                 dbm_axis);
+               if (stats.has_other_adc) {
+                       addSeries("Temperature",
+                                 AltosGraphDataPoint.data_temperature,
+                                 AltosConvert.temperature,
+                                 temperature_color,
+                                 false,
+                                 temperature_axis);
+                       addSeries("Battery Voltage",
+                                 AltosGraphDataPoint.data_battery_voltage,
+                                 voltage_units,
+                                 battery_voltage_color,
+                                 false,
+                                 voltage_axis);
+                       addSeries("Drogue Voltage",
+                                 AltosGraphDataPoint.data_drogue_voltage,
+                                 voltage_units,
+                                 drogue_voltage_color,
+                                 false,
+                                 voltage_axis);
+                       addSeries("Main Voltage",
+                                 AltosGraphDataPoint.data_main_voltage,
+                                 voltage_units,
+                                 main_voltage_color,
+                                 false,
+                                 voltage_axis);
+               }
+
+               setDataSet(dataSet);
        }
 }
\ No newline at end of file
index 2dded9a2cfe5486c9f5fcbf837d2a35e707d51ac..2f3575a4387bbbd9e39f0e58a4a8394ce53a1f27 100644 (file)
@@ -23,12 +23,15 @@ public class AltosGraphUI extends AltosUIFrame
        AltosUIEnable           enable;
        AltosSiteMap            map;
        AltosState              state;
+       AltosGraphDataSet       graphDataSet;
+       AltosFlightStats        stats;
+       AltosFlightStatsTable   statsTable;
 
        boolean fill_map(AltosRecordIterable records) {
                boolean         any_gps = false;
                for (AltosRecord record : records) {
                        state = new AltosState(record, state);
-                       if (state.data.gps != null) {
+                       if (state.gps.locked && state.gps.nsat >= 4) {
                                map.show(state, 0);
                                any_gps = true;
                        }
@@ -44,17 +47,18 @@ public class AltosGraphUI extends AltosUIFrame
 
                enable = new AltosUIEnable();
 
-               AltosGraph graph = new AltosGraph(enable);
+               stats = new AltosFlightStats(records);
+               graphDataSet = new AltosGraphDataSet(records);
 
-               graph.setDataSet(new AltosGraphDataSet(records));
+               graph = new AltosGraph(enable, stats, graphDataSet);
+
+               statsTable = new AltosFlightStatsTable(stats);
 
                map = new AltosSiteMap();
 
                pane.add("Flight Graph", graph.panel);
                pane.add("Configure Graph", enable);
-
-               AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
-               pane.add("Flight Statistics", stats);
+               pane.add("Flight Statistics", statsTable);
 
                if (fill_map(records))
                        pane.add("Map", map);