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; version 2 of the License.
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.
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.
18 package org.altusmetrum.altosuilib_8;
20 import org.altusmetrum.altoslib_8.*;
22 public class AltosGraphDataPoint implements AltosUIDataPoint {
26 public static final int data_height = 0;
27 public static final int data_speed = 1;
28 public static final int data_accel = 2;
29 public static final int data_temp = 3;
30 public static final int data_battery_voltage = 4;
31 public static final int data_drogue_voltage = 5;
32 public static final int data_main_voltage = 6;
33 public static final int data_rssi = 7;
34 public static final int data_state = 8;
35 public static final int data_gps_height = 9;
36 public static final int data_gps_nsat_solution = 10;
37 public static final int data_gps_nsat_view = 11;
38 public static final int data_gps_altitude = 12;
39 public static final int data_temperature = 13;
40 public static final int data_range = 14;
41 public static final int data_distance = 15;
42 public static final int data_pressure = 16;
43 public static final int data_accel_along = 17;
44 public static final int data_accel_across = 18;
45 public static final int data_accel_through = 19;
46 public static final int data_gyro_roll = 20;
47 public static final int data_gyro_pitch = 21;
48 public static final int data_gyro_yaw = 22;
49 public static final int data_mag_along = 23;
50 public static final int data_mag_across = 24;
51 public static final int data_mag_through = 25;
52 public static final int data_orient = 26;
53 public static final int data_gps_course = 27;
54 public static final int data_gps_ground_speed = 28;
55 public static final int data_gps_climb_rate = 29;
56 public static final int data_gps_pdop = 30;
57 public static final int data_gps_hdop = 31;
58 public static final int data_gps_vdop = 32;
59 public static final int data_ignitor_0 = 33;
60 public static final int data_ignitor_num = 32;
61 public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1;
62 public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num;
63 public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1;
65 public double x() throws AltosUIDataMissing {
66 double time = state.time_since_boost();
68 throw new AltosUIDataMissing(-1);
72 public double y(int index) throws AltosUIDataMissing {
73 double y = AltosLib.MISSING;
82 y = state.acceleration();
85 y = state.temperature;
87 case data_battery_voltage:
88 y = state.battery_voltage;
90 case data_drogue_voltage:
91 y = state.apogee_voltage;
93 case data_main_voltage:
94 y = state.main_voltage;
100 y = state.gps_height;
102 case data_gps_nsat_solution:
103 if (state.gps != null)
106 case data_gps_nsat_view:
107 if (state.gps != null) {
108 if (state.gps.cc_gps_sat != null)
109 y = state.gps.cc_gps_sat.length;
114 case data_gps_altitude:
115 y = state.gps_altitude();
117 case data_temperature:
118 y = state.temperature;
124 if (state.from_pad != null)
125 y = state.from_pad.distance;
128 y = state.pressure();
131 case data_accel_along:
132 y = state.accel_along();
134 case data_accel_across:
135 y = state.accel_across();
137 case data_accel_through:
138 y = state.accel_through();
141 y = state.gyro_roll();
143 case data_gyro_pitch:
144 y = state.gyro_pitch();
147 y = state.gyro_yaw();
150 y = state.mag_along();
152 case data_mag_across:
153 y = state.mag_across();
155 case data_mag_through:
156 y = state.mag_through();
161 case data_gps_course:
162 if (state.gps != null)
163 y = state.gps.course;
165 y = AltosLib.MISSING;
167 case data_gps_ground_speed:
168 if (state.gps != null)
169 y = state.gps.ground_speed;
171 y = AltosLib.MISSING;
173 case data_gps_climb_rate:
174 if (state.gps != null)
175 y = state.gps.climb_rate;
177 y = AltosLib.MISSING;
180 if (state.gps != null)
183 y = AltosLib.MISSING;
186 if (state.gps != null)
189 y = AltosLib.MISSING;
192 if (state.gps != null)
195 y = AltosLib.MISSING;
198 if (data_ignitor_0 <= index && index <= data_ignitor_max) {
199 int ignitor = index - data_ignitor_0;
200 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
201 y = state.ignitor_voltage[ignitor];
202 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
203 int ignitor = index - data_ignitor_fired_0;
204 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
205 if ((state.pyro_fired & (1 << ignitor)) != 0)
213 if (y == AltosLib.MISSING)
214 throw new AltosUIDataMissing(index);
218 public int id(int index) {
219 if (index == data_state) {
220 int s = state.state();
221 if (AltosLib.ao_flight_boost <= s && s <= AltosLib.ao_flight_landed)
223 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
224 int ignitor = index - data_ignitor_fired_0;
225 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
226 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
227 if ((state.pyro_fired & (1 << ignitor)) != 0)
235 public String id_name(int index) {
236 if (index == data_state) {
237 return state.state_name();
238 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
239 int ignitor = index - data_ignitor_fired_0;
240 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
241 return AltosLib.ignitor_name(ignitor);
246 public AltosGraphDataPoint (AltosState state) {