Merge branch 'master' into new-state
[fw/altos] / altosui / AltosGraphDataPoint.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import org.altusmetrum.altosuilib_1.*;
21 import org.altusmetrum.altoslib_1.*;
22
23 public class AltosGraphDataPoint implements AltosUIDataPoint {
24
25         AltosState      state;
26
27         public static final int data_height = 0;
28         public static final int data_speed = 1;
29         public static final int data_accel = 2;
30         public static final int data_temp = 3;
31         public static final int data_battery_voltage = 4;
32         public static final int data_drogue_voltage = 5;
33         public static final int data_main_voltage = 6;
34         public static final int data_rssi = 7;
35         public static final int data_state = 8;
36         public static final int data_gps_height = 9;
37         public static final int data_gps_nsat_solution = 10;
38         public static final int data_gps_nsat_view = 11;
39         public static final int data_temperature = 12;
40         public static final int data_range = 13;
41         public static final int data_distance = 14;
42         public static final int data_pressure = 15;
43
44         public double x() throws AltosUIDataMissing {
45                 double  time = state.time_since_boost();
46                 if (time < -2)
47                         throw new AltosUIDataMissing(-1);
48                 return time;
49         }
50
51         public double y(int index) throws AltosUIDataMissing {
52                 double y = AltosRecord.MISSING;
53                 switch (index) {
54                 case data_height:
55                         y = state.height;
56                         break;
57                 case data_speed:
58                         y = state.speed();
59                         break;
60                 case data_accel:
61                         y = state.acceleration;
62                         break;
63                 case data_temp:
64                         y = state.temperature;
65                         break;
66                 case data_battery_voltage:
67                         y = state.battery_voltage;
68                         break;
69                 case data_drogue_voltage:
70                         y = state.apogee_voltage;
71                         break;
72                 case data_main_voltage:
73                         y = state.main_voltage;
74                         break;
75                 case data_rssi:
76                         y = state.rssi;
77                         break;
78                 case data_gps_height:
79                         y = state.gps_height;
80                         break;  
81                 case data_gps_nsat_solution:
82                         if (state.gps != null)
83                                 y = state.gps.nsat;
84                         break;
85                 case data_gps_nsat_view:
86                         if (state.gps != null && state.gps.cc_gps_sat != null)
87                                 y = state.gps.cc_gps_sat.length;
88                         break;
89                 case data_temperature:
90                         y = state.temperature;
91                         break;
92                 case data_range:
93                         y = state.range;
94                         break;
95                 case data_distance:
96                         if (state.from_pad != null)
97                                 y = state.from_pad.distance;
98                         break;
99                 case data_pressure:
100                         y = state.pressure;
101                         break;
102                 }
103                 if (y == AltosRecord.MISSING)
104                         throw new AltosUIDataMissing(index);
105                 return y;
106         }
107
108         public int id(int index) {
109                 if (index == data_state) {
110                         int s = state.state;
111                         if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed)
112                                 return -1;
113                         return s;
114                 }
115                 return 0;
116         }
117
118         public String id_name(int index) {
119                 if (index == data_state)
120                         return state.state_name();
121                 return "";
122         }
123
124         public AltosGraphDataPoint (AltosState state) {
125                 this.state = state;
126         }
127 }