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