2 * Copyright © 2013 Keith Packard <keithp@keithp.com>
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.
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.
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.
19 package org.altusmetrum.altosuilib_11;
21 import org.altusmetrum.altoslib_11.*;
23 public class AltosGraphDataPoint implements AltosUIDataPoint {
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;
66 public double x() throws AltosUIDataMissing {
67 double time = state.time_since_boost();
69 throw new AltosUIDataMissing(-1);
73 public double y(int index) throws AltosUIDataMissing {
74 double y = AltosLib.MISSING;
83 y = state.acceleration();
86 y = state.temperature;
88 case data_battery_voltage:
89 y = state.battery_voltage;
91 case data_drogue_voltage:
92 y = state.apogee_voltage;
94 case data_main_voltage:
95 y = state.main_voltage;
100 case data_gps_height:
101 y = state.gps_height;
103 case data_gps_nsat_solution:
104 if (state.gps != null)
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;
115 case data_gps_altitude:
116 y = state.gps_altitude();
118 case data_temperature:
119 y = state.temperature;
125 if (state.from_pad != null)
126 y = state.from_pad.distance;
129 y = state.pressure();
132 case data_accel_along:
133 y = state.accel_along();
135 case data_accel_across:
136 y = state.accel_across();
138 case data_accel_through:
139 y = state.accel_through();
142 y = state.gyro_roll();
144 case data_gyro_pitch:
145 y = state.gyro_pitch();
148 y = state.gyro_yaw();
151 y = state.mag_along();
153 case data_mag_across:
154 y = state.mag_across();
156 case data_mag_through:
157 y = state.mag_through();
162 case data_gps_course:
163 if (state.gps != null)
164 y = state.gps.course;
166 y = AltosLib.MISSING;
168 case data_gps_ground_speed:
169 if (state.gps != null)
170 y = state.gps.ground_speed;
172 y = AltosLib.MISSING;
174 case data_gps_climb_rate:
175 if (state.gps != null)
176 y = state.gps.climb_rate;
178 y = AltosLib.MISSING;
181 if (state.gps != null)
184 y = AltosLib.MISSING;
187 if (state.gps != null)
190 y = AltosLib.MISSING;
193 if (state.gps != null)
196 y = AltosLib.MISSING;
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)
214 if (y == AltosLib.MISSING)
215 throw new AltosUIDataMissing(index);
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)
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)
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);
247 public AltosGraphDataPoint (AltosState state) {