0012d96a145598bc6128d0e85d7328e7809d5ef8
[fw/altos] / altosuilib / 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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altosuilib_11;
20
21 import org.altusmetrum.altoslib_11.*;
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_gps_altitude = 12;
40         public static final int data_temperature = 13;
41         public static final int data_range = 14;
42         public static final int data_distance = 15;
43         public static final int data_pressure = 16;
44         public static final int data_accel_along = 17;
45         public static final int data_accel_across = 18;
46         public static final int data_accel_through = 19;
47         public static final int data_gyro_roll = 20;
48         public static final int data_gyro_pitch = 21;
49         public static final int data_gyro_yaw = 22;
50         public static final int data_mag_along = 23;
51         public static final int data_mag_across = 24;
52         public static final int data_mag_through = 25;
53         public static final int data_orient = 26;
54         public static final int data_gps_course = 27;
55         public static final int data_gps_ground_speed = 28;
56         public static final int data_gps_climb_rate = 29;
57         public static final int data_gps_pdop = 30;
58         public static final int data_gps_hdop = 31;
59         public static final int data_gps_vdop = 32;
60         public static final int data_ignitor_0 = 33;
61         public static final int data_ignitor_num = 32;
62         public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1;
63         public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num;
64         public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1;
65
66         public double x() throws AltosUIDataMissing {
67                 double  time = state.time_since_boost();
68                 if (time < -2)
69                         throw new AltosUIDataMissing(-1);
70                 return time;
71         }
72
73         public double y(int index) throws AltosUIDataMissing {
74                 double y = AltosLib.MISSING;
75                 switch (index) {
76                 case data_height:
77                         y = state.height();
78                         break;
79                 case data_speed:
80                         y = state.speed();
81                         break;
82                 case data_accel:
83                         y = state.acceleration();
84                         break;
85                 case data_temp:
86                         y = state.temperature;
87                         break;
88                 case data_battery_voltage:
89                         y = state.battery_voltage;
90                         break;
91                 case data_drogue_voltage:
92                         y = state.apogee_voltage;
93                         break;
94                 case data_main_voltage:
95                         y = state.main_voltage;
96                         break;
97                 case data_rssi:
98                         y = state.rssi;
99                         break;
100                 case data_gps_height:
101                         y = state.gps_height;
102                         break;
103                 case data_gps_nsat_solution:
104                         if (state.gps != null)
105                                 y = state.gps.nsat;
106                         break;
107                 case data_gps_nsat_view:
108                         if (state.gps != null) {
109                                 if (state.gps.cc_gps_sat != null)
110                                         y = state.gps.cc_gps_sat.length;
111                                 else
112                                         y = 0;
113                         }
114                         break;
115                 case data_gps_altitude:
116                         y = state.gps_altitude();
117                         break;
118                 case data_temperature:
119                         y = state.temperature;
120                         break;
121                 case data_range:
122                         y = state.range;
123                         break;
124                 case data_distance:
125                         if (state.from_pad != null)
126                                 y = state.from_pad.distance;
127                         break;
128                 case data_pressure:
129                         y = state.pressure();
130                         break;
131
132                 case data_accel_along:
133                         y = state.accel_along();
134                         break;
135                 case data_accel_across:
136                         y = state.accel_across();
137                         break;
138                 case data_accel_through:
139                         y = state.accel_through();
140                         break;
141                 case data_gyro_roll:
142                         y = state.gyro_roll();
143                         break;
144                 case data_gyro_pitch:
145                         y = state.gyro_pitch();
146                         break;
147                 case data_gyro_yaw:
148                         y = state.gyro_yaw();
149                         break;
150                 case data_mag_along:
151                         y = state.mag_along();
152                         break;
153                 case data_mag_across:
154                         y = state.mag_across();
155                         break;
156                 case data_mag_through:
157                         y = state.mag_through();
158                         break;
159                 case data_orient:
160                         y = state.orient();
161                         break;
162                 case data_gps_course:
163                         if (state.gps != null)
164                                 y = state.gps.course;
165                         else
166                                 y = AltosLib.MISSING;
167                         break;
168                 case data_gps_ground_speed:
169                         if (state.gps != null)
170                                 y = state.gps.ground_speed;
171                         else
172                                 y = AltosLib.MISSING;
173                         break;
174                 case data_gps_climb_rate:
175                         if (state.gps != null)
176                                 y = state.gps.climb_rate;
177                         else
178                                 y = AltosLib.MISSING;
179                         break;
180                 case data_gps_pdop:
181                         if (state.gps != null)
182                                 y = state.gps.pdop;
183                         else
184                                 y = AltosLib.MISSING;
185                         break;
186                 case data_gps_hdop:
187                         if (state.gps != null)
188                                 y = state.gps.hdop;
189                         else
190                                 y = AltosLib.MISSING;
191                         break;
192                 case data_gps_vdop:
193                         if (state.gps != null)
194                                 y = state.gps.vdop;
195                         else
196                                 y = AltosLib.MISSING;
197                         break;
198                 default:
199                         if (data_ignitor_0 <= index && index <= data_ignitor_max) {
200                                 int ignitor = index - data_ignitor_0;
201                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
202                                         y = state.ignitor_voltage[ignitor];
203                         } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
204                                 int ignitor = index - data_ignitor_fired_0;
205                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
206                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
207                                                 y = 1;
208                                         else
209                                                 y = 0;
210                                 }
211                         }
212                         break;
213                 }
214                 if (y == AltosLib.MISSING)
215                         throw new AltosUIDataMissing(index);
216                 return y;
217         }
218
219         public int id(int index) {
220                 if (index == data_state) {
221                         int s = state.state();
222                         if (AltosLib.ao_flight_boost <= s && s <= AltosLib.ao_flight_landed)
223                                 return s;
224                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
225                         int ignitor = index - data_ignitor_fired_0;
226                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
227                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
228                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
229                                                 return 1;
230                                 }
231                         }
232                 }
233                 return -1;
234         }
235
236         public String id_name(int index) {
237                 if (index == data_state) {
238                         return state.state_name();
239                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
240                         int ignitor = index - data_ignitor_fired_0;
241                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
242                                 return AltosLib.ignitor_name(ignitor);
243                 }
244                 return "";
245         }
246
247         public AltosGraphDataPoint (AltosState state) {
248                 this.state = state;
249         }
250 }