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;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_11.*;
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
38 class AltosVoltage extends AltosUnits {
40 public double value(double v, boolean imperial_units) {
44 public double inverse(double v, boolean imperial_units) {
48 public String show_units(boolean imperial_units) {
52 public String say_units(boolean imperial_units) {
56 public int show_fraction(int width, boolean imperial_units) {
61 class AltosNsat extends AltosUnits {
63 public double value(double v, boolean imperial_units) {
67 public double inverse(double v, boolean imperial_units) {
71 public String show_units(boolean imperial_units) {
75 public String say_units(boolean imperial_units) {
79 public int show_fraction(int width, boolean imperial_units) {
84 class AltosPressure extends AltosUnits {
86 public double value(double p, boolean imperial_units) {
90 public double inverse(double p, boolean imperial_units) {
94 public String show_units(boolean imperial_units) {
98 public String say_units(boolean imperial_units) {
102 public int show_fraction(int width, boolean imperial_units) {
107 class AltosDbm extends AltosUnits {
109 public double value(double d, boolean imperial_units) {
113 public double inverse(double d, boolean imperial_units) {
117 public String show_units(boolean imperial_units) {
121 public String say_units(boolean imperial_units) {
125 public int show_fraction(int width, boolean imperial_units) {
130 class AltosGyroUnits extends AltosUnits {
132 public double value(double p, boolean imperial_units) {
136 public double inverse(double p, boolean imperial_units) {
140 public String show_units(boolean imperial_units) {
144 public String say_units(boolean imperial_units) {
145 return "degrees per second";
148 public int show_fraction(int width, boolean imperial_units) {
153 class AltosMagUnits extends AltosUnits {
155 public double value(double p, boolean imperial_units) {
159 public double inverse(double p, boolean imperial_units) {
163 public String show_units(boolean imperial_units) {
167 public String say_units(boolean imperial_units) {
171 public int show_fraction(int width, boolean imperial_units) {
176 class AltosDopUnits extends AltosUnits {
178 public double value(double p, boolean imperial_units) {
182 public double inverse(double p, boolean imperial_units) {
186 public String show_units(boolean imperial_units) {
190 public String say_units(boolean imperial_units) {
194 public int show_fraction(int width, boolean imperial_units) {
199 public class AltosGraph extends AltosUIGraph {
201 static final private Color height_color = new Color(194,31,31);
202 static final private Color gps_height_color = new Color(150,31,31);
203 static final private Color pressure_color = new Color (225,31,31);
204 static final private Color range_color = new Color(100, 31, 31);
205 static final private Color distance_color = new Color(100, 31, 194);
206 static final private Color speed_color = new Color(31,194,31);
207 static final private Color accel_color = new Color(31,31,194);
208 static final private Color voltage_color = new Color(194, 194, 31);
209 static final private Color battery_voltage_color = new Color(194, 194, 31);
210 static final private Color drogue_voltage_color = new Color(150, 150, 31);
211 static final private Color main_voltage_color = new Color(100, 100, 31);
212 static final private Color gps_nsat_color = new Color (194, 31, 194);
213 static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
214 static final private Color gps_nsat_view_color = new Color (150, 31, 150);
215 static final private Color gps_course_color = new Color (100, 31, 112);
216 static final private Color gps_ground_speed_color = new Color (31, 112, 100);
217 static final private Color gps_climb_rate_color = new Color (31, 31, 112);
218 static final private Color gps_pdop_color = new Color(50, 194, 0);
219 static final private Color gps_hdop_color = new Color(50, 0, 194);
220 static final private Color gps_vdop_color = new Color(194, 0, 50);
221 static final private Color temperature_color = new Color (31, 194, 194);
222 static final private Color dbm_color = new Color(31, 100, 100);
223 static final private Color state_color = new Color(0,0,0);
224 static final private Color accel_x_color = new Color(255, 0, 0);
225 static final private Color accel_y_color = new Color(0, 255, 0);
226 static final private Color accel_z_color = new Color(0, 0, 255);
227 static final private Color gyro_x_color = new Color(192, 0, 0);
228 static final private Color gyro_y_color = new Color(0, 192, 0);
229 static final private Color gyro_z_color = new Color(0, 0, 192);
230 static final private Color mag_x_color = new Color(128, 0, 0);
231 static final private Color mag_y_color = new Color(0, 128, 0);
232 static final private Color mag_z_color = new Color(0, 0, 128);
233 static final private Color orient_color = new Color(31, 31, 31);
235 static AltosVoltage voltage_units = new AltosVoltage();
236 static AltosPressure pressure_units = new AltosPressure();
237 static AltosNsat nsat_units = new AltosNsat();
238 static AltosDbm dbm_units = new AltosDbm();
239 static AltosGyroUnits gyro_units = new AltosGyroUnits();
240 static AltosOrient orient_units = new AltosOrient();
241 static AltosMagUnits mag_units = new AltosMagUnits();
242 static AltosDopUnits dop_units = new AltosDopUnits();
244 AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
245 AltosUIAxis distance_axis, pressure_axis;
246 AltosUIAxis gyro_axis, orient_axis, mag_axis;
247 AltosUIAxis course_axis, dop_axis;
249 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
252 height_axis = newAxis("Height", AltosConvert.height, height_color);
253 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
254 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
255 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
256 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
257 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
258 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
259 AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
260 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
261 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
263 gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0);
264 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
265 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
266 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
267 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
269 addMarker("State", AltosGraphDataPoint.data_state, state_color);
271 if (stats.has_flight_data) {
273 AltosGraphDataPoint.data_height,
278 addSeries("Pressure",
279 AltosGraphDataPoint.data_pressure,
285 AltosGraphDataPoint.data_speed,
290 addSeries("Acceleration",
291 AltosGraphDataPoint.data_accel,
298 boolean enable_gps = false;
300 if (!stats.has_flight_data)
304 AltosGraphDataPoint.data_range,
305 AltosConvert.distance,
309 addSeries("Distance",
310 AltosGraphDataPoint.data_distance,
311 AltosConvert.distance,
315 addSeries("GPS Height",
316 AltosGraphDataPoint.data_gps_height,
321 addSeries("GPS Altitude",
322 AltosGraphDataPoint.data_gps_altitude,
327 addSeries("GPS Satellites in Solution",
328 AltosGraphDataPoint.data_gps_nsat_solution,
330 gps_nsat_solution_color,
333 if (stats.has_gps_sats) {
334 addSeries("GPS Satellites in View",
335 AltosGraphDataPoint.data_gps_nsat_view,
341 if (stats.has_gps_detail) {
342 addSeries("GPS Course",
343 AltosGraphDataPoint.data_gps_course,
348 addSeries("GPS Ground Speed",
349 AltosGraphDataPoint.data_gps_ground_speed,
351 gps_ground_speed_color,
354 addSeries("GPS Climb Rate",
355 AltosGraphDataPoint.data_gps_climb_rate,
357 gps_climb_rate_color,
361 addSeries("GPS Position DOP",
362 AltosGraphDataPoint.data_gps_pdop,
367 if (stats.has_gps_detail) {
368 addSeries("GPS Horizontal DOP",
369 AltosGraphDataPoint.data_gps_hdop,
374 addSeries("GPS Vertical DOP",
375 AltosGraphDataPoint.data_gps_vdop,
383 addSeries("Received Signal Strength",
384 AltosGraphDataPoint.data_rssi,
390 if (stats.has_battery)
391 addSeries("Battery Voltage",
392 AltosGraphDataPoint.data_battery_voltage,
394 battery_voltage_color,
398 if (stats.has_flight_adc) {
399 addSeries("Temperature",
400 AltosGraphDataPoint.data_temperature,
401 AltosConvert.temperature,
405 addSeries("Drogue Voltage",
406 AltosGraphDataPoint.data_drogue_voltage,
408 drogue_voltage_color,
411 addSeries("Main Voltage",
412 AltosGraphDataPoint.data_main_voltage,
420 addSeries("Acceleration Along",
421 AltosGraphDataPoint.data_accel_along,
426 addSeries("Acceleration Across",
427 AltosGraphDataPoint.data_accel_across,
432 addSeries("Acceleration Through",
433 AltosGraphDataPoint.data_accel_through,
438 addSeries("Roll Rate",
439 AltosGraphDataPoint.data_gyro_roll,
444 addSeries("Pitch Rate",
445 AltosGraphDataPoint.data_gyro_pitch,
450 addSeries("Yaw Rate",
451 AltosGraphDataPoint.data_gyro_yaw,
458 addSeries("Magnetometer Along",
459 AltosGraphDataPoint.data_mag_along,
464 addSeries("Magnetometer Across",
465 AltosGraphDataPoint.data_mag_across,
470 addSeries("Magnetometer Through",
471 AltosGraphDataPoint.data_mag_through,
477 if (stats.has_orient)
478 addSeries("Tilt Angle",
479 AltosGraphDataPoint.data_orient,
484 if (stats.num_ignitor > 0) {
485 for (int i = 0; i < stats.num_ignitor; i++)
486 addSeries(AltosLib.ignitor_name(i),
487 AltosGraphDataPoint.data_ignitor_0 + i,
492 for (int i = 0; i < stats.num_ignitor; i++)
493 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);