altosui: Add raw pressure to the AltosUI graph
[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                 if (state.data.time < -2)
46                         throw new AltosUIDataMissing(-1);
47                 return state.data.time;
48         }
49
50         public double y(int index) throws AltosUIDataMissing {
51                 double y = AltosRecord.MISSING;
52                 switch (index) {
53                 case data_height:
54                         y = state.height;
55                         break;
56                 case data_speed:
57                         y = state.speed();
58                         break;
59                 case data_accel:
60                         y = state.acceleration;
61                         break;
62                 case data_temp:
63                         y = state.temperature;
64                         break;
65                 case data_battery_voltage:
66                         y = state.battery;
67                         break;
68                 case data_drogue_voltage:
69                         y = state.drogue_sense;
70                         break;
71                 case data_main_voltage:
72                         y = state.main_sense;
73                         break;
74                 case data_rssi:
75                         y = state.data.rssi;
76                         break;
77                 case data_gps_height:
78                         y = state.gps_height;
79                         break;  
80                 case data_gps_nsat_solution:
81                         if (state.gps != null)
82                                 y = state.gps.nsat;
83                         break;
84                 case data_gps_nsat_view:
85                         if (state.gps != null && state.gps.cc_gps_sat != null)
86                                 y = state.gps.cc_gps_sat.length;
87                         break;
88                 case data_temperature:
89                         y = state.temperature;
90                         break;
91                 case data_range:
92                         y = state.range;
93                         break;
94                 case data_distance:
95                         if (state.from_pad != null)
96                                 y = state.from_pad.distance;
97                         break;
98                 case data_pressure:
99                         y = state.pressure;
100                         break;
101                 }
102                 if (y == AltosRecord.MISSING)
103                         throw new AltosUIDataMissing(index);
104                 return y;
105         }
106
107         public int id(int index) {
108                 if (index == data_state) {
109                         int s = state.data.state;
110                         if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed)
111                                 return -1;
112                         return s;
113                 }
114                 return 0;
115         }
116
117         public String id_name(int index) {
118                 if (index == data_state)
119                         return state.data.state();
120                 return "";
121         }
122
123         public AltosGraphDataPoint (AltosState state) {
124                 this.state = state;
125         }
126 }