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_10;
21 import java.util.ArrayList;
25 import org.altusmetrum.altoslib_10.*;
27 import org.jfree.ui.*;
28 import org.jfree.chart.*;
29 import org.jfree.chart.plot.*;
30 import org.jfree.chart.axis.*;
31 import org.jfree.chart.renderer.*;
32 import org.jfree.chart.renderer.xy.*;
33 import org.jfree.chart.labels.*;
34 import org.jfree.data.xy.*;
35 import org.jfree.data.*;
37 class AltosVoltage extends AltosUnits {
39 public double value(double v, boolean imperial_units) {
43 public double inverse(double v, boolean imperial_units) {
47 public String show_units(boolean imperial_units) {
51 public String say_units(boolean imperial_units) {
55 public int show_fraction(int width, boolean imperial_units) {
60 class AltosNsat extends AltosUnits {
62 public double value(double v, boolean imperial_units) {
66 public double inverse(double v, boolean imperial_units) {
70 public String show_units(boolean imperial_units) {
74 public String say_units(boolean imperial_units) {
78 public int show_fraction(int width, boolean imperial_units) {
83 class AltosPressure extends AltosUnits {
85 public double value(double p, boolean imperial_units) {
89 public double inverse(double p, boolean imperial_units) {
93 public String show_units(boolean imperial_units) {
97 public String say_units(boolean imperial_units) {
101 public int show_fraction(int width, boolean imperial_units) {
106 class AltosDbm extends AltosUnits {
108 public double value(double d, boolean imperial_units) {
112 public double inverse(double d, boolean imperial_units) {
116 public String show_units(boolean imperial_units) {
120 public String say_units(boolean imperial_units) {
124 public int show_fraction(int width, boolean imperial_units) {
129 class AltosGyroUnits extends AltosUnits {
131 public double value(double p, boolean imperial_units) {
135 public double inverse(double p, boolean imperial_units) {
139 public String show_units(boolean imperial_units) {
143 public String say_units(boolean imperial_units) {
144 return "degrees per second";
147 public int show_fraction(int width, boolean imperial_units) {
152 class AltosMagUnits extends AltosUnits {
154 public double value(double p, boolean imperial_units) {
158 public double inverse(double p, boolean imperial_units) {
162 public String show_units(boolean imperial_units) {
166 public String say_units(boolean imperial_units) {
170 public int show_fraction(int width, boolean imperial_units) {
175 class AltosDopUnits extends AltosUnits {
177 public double value(double p, boolean imperial_units) {
181 public double inverse(double p, boolean imperial_units) {
185 public String show_units(boolean imperial_units) {
189 public String say_units(boolean imperial_units) {
193 public int show_fraction(int width, boolean imperial_units) {
198 public class AltosGraph extends AltosUIGraph {
200 static final private Color height_color = new Color(194,31,31);
201 static final private Color gps_height_color = new Color(150,31,31);
202 static final private Color pressure_color = new Color (225,31,31);
203 static final private Color range_color = new Color(100, 31, 31);
204 static final private Color distance_color = new Color(100, 31, 194);
205 static final private Color speed_color = new Color(31,194,31);
206 static final private Color accel_color = new Color(31,31,194);
207 static final private Color voltage_color = new Color(194, 194, 31);
208 static final private Color battery_voltage_color = new Color(194, 194, 31);
209 static final private Color drogue_voltage_color = new Color(150, 150, 31);
210 static final private Color main_voltage_color = new Color(100, 100, 31);
211 static final private Color gps_nsat_color = new Color (194, 31, 194);
212 static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
213 static final private Color gps_nsat_view_color = new Color (150, 31, 150);
214 static final private Color gps_course_color = new Color (100, 31, 112);
215 static final private Color gps_ground_speed_color = new Color (31, 112, 100);
216 static final private Color gps_climb_rate_color = new Color (31, 31, 112);
217 static final private Color gps_pdop_color = new Color(50, 194, 0);
218 static final private Color gps_hdop_color = new Color(50, 0, 194);
219 static final private Color gps_vdop_color = new Color(194, 0, 50);
220 static final private Color temperature_color = new Color (31, 194, 194);
221 static final private Color dbm_color = new Color(31, 100, 100);
222 static final private Color state_color = new Color(0,0,0);
223 static final private Color accel_x_color = new Color(255, 0, 0);
224 static final private Color accel_y_color = new Color(0, 255, 0);
225 static final private Color accel_z_color = new Color(0, 0, 255);
226 static final private Color gyro_x_color = new Color(192, 0, 0);
227 static final private Color gyro_y_color = new Color(0, 192, 0);
228 static final private Color gyro_z_color = new Color(0, 0, 192);
229 static final private Color mag_x_color = new Color(128, 0, 0);
230 static final private Color mag_y_color = new Color(0, 128, 0);
231 static final private Color mag_z_color = new Color(0, 0, 128);
232 static final private Color orient_color = new Color(31, 31, 31);
234 static AltosVoltage voltage_units = new AltosVoltage();
235 static AltosPressure pressure_units = new AltosPressure();
236 static AltosNsat nsat_units = new AltosNsat();
237 static AltosDbm dbm_units = new AltosDbm();
238 static AltosGyroUnits gyro_units = new AltosGyroUnits();
239 static AltosOrient orient_units = new AltosOrient();
240 static AltosMagUnits mag_units = new AltosMagUnits();
241 static AltosDopUnits dop_units = new AltosDopUnits();
243 AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
244 AltosUIAxis distance_axis, pressure_axis;
245 AltosUIAxis gyro_axis, orient_axis, mag_axis;
246 AltosUIAxis course_axis, dop_axis;
248 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
251 height_axis = newAxis("Height", AltosConvert.height, height_color);
252 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
253 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
254 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
255 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
256 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
257 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
258 AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
259 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
260 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
262 gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0);
263 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
264 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
265 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
266 dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0);
268 addMarker("State", AltosGraphDataPoint.data_state, state_color);
270 if (stats.has_flight_data) {
272 AltosGraphDataPoint.data_height,
277 addSeries("Pressure",
278 AltosGraphDataPoint.data_pressure,
284 AltosGraphDataPoint.data_speed,
289 addSeries("Acceleration",
290 AltosGraphDataPoint.data_accel,
297 boolean enable_gps = false;
299 if (!stats.has_flight_data)
303 AltosGraphDataPoint.data_range,
304 AltosConvert.distance,
308 addSeries("Distance",
309 AltosGraphDataPoint.data_distance,
310 AltosConvert.distance,
314 addSeries("GPS Height",
315 AltosGraphDataPoint.data_gps_height,
320 addSeries("GPS Altitude",
321 AltosGraphDataPoint.data_gps_altitude,
326 addSeries("GPS Satellites in Solution",
327 AltosGraphDataPoint.data_gps_nsat_solution,
329 gps_nsat_solution_color,
332 if (stats.has_gps_sats) {
333 addSeries("GPS Satellites in View",
334 AltosGraphDataPoint.data_gps_nsat_view,
340 if (stats.has_gps_detail) {
341 addSeries("GPS Course",
342 AltosGraphDataPoint.data_gps_course,
347 addSeries("GPS Ground Speed",
348 AltosGraphDataPoint.data_gps_ground_speed,
350 gps_ground_speed_color,
353 addSeries("GPS Climb Rate",
354 AltosGraphDataPoint.data_gps_climb_rate,
356 gps_climb_rate_color,
360 addSeries("GPS Position DOP",
361 AltosGraphDataPoint.data_gps_pdop,
366 if (stats.has_gps_detail) {
367 addSeries("GPS Horizontal DOP",
368 AltosGraphDataPoint.data_gps_hdop,
373 addSeries("GPS Vertical DOP",
374 AltosGraphDataPoint.data_gps_vdop,
382 addSeries("Received Signal Strength",
383 AltosGraphDataPoint.data_rssi,
389 if (stats.has_battery)
390 addSeries("Battery Voltage",
391 AltosGraphDataPoint.data_battery_voltage,
393 battery_voltage_color,
397 if (stats.has_flight_adc) {
398 addSeries("Temperature",
399 AltosGraphDataPoint.data_temperature,
400 AltosConvert.temperature,
404 addSeries("Drogue Voltage",
405 AltosGraphDataPoint.data_drogue_voltage,
407 drogue_voltage_color,
410 addSeries("Main Voltage",
411 AltosGraphDataPoint.data_main_voltage,
419 addSeries("Acceleration Along",
420 AltosGraphDataPoint.data_accel_along,
425 addSeries("Acceleration Across",
426 AltosGraphDataPoint.data_accel_across,
431 addSeries("Acceleration Through",
432 AltosGraphDataPoint.data_accel_through,
437 addSeries("Roll Rate",
438 AltosGraphDataPoint.data_gyro_roll,
443 addSeries("Pitch Rate",
444 AltosGraphDataPoint.data_gyro_pitch,
449 addSeries("Yaw Rate",
450 AltosGraphDataPoint.data_gyro_yaw,
457 addSeries("Magnetometer Along",
458 AltosGraphDataPoint.data_mag_along,
463 addSeries("Magnetometer Across",
464 AltosGraphDataPoint.data_mag_across,
469 addSeries("Magnetometer Through",
470 AltosGraphDataPoint.data_mag_through,
476 if (stats.has_orient)
477 addSeries("Tilt Angle",
478 AltosGraphDataPoint.data_orient,
483 if (stats.num_ignitor > 0) {
484 for (int i = 0; i < stats.num_ignitor; i++)
485 addSeries(AltosLib.ignitor_name(i),
486 AltosGraphDataPoint.data_ignitor_0 + i,
491 for (int i = 0; i < stats.num_ignitor; i++)
492 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);