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_2;
21 import java.util.ArrayList;
25 import org.altusmetrum.altoslib_4.*;
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 public class AltosGraph extends AltosUIGraph {
177 static final private Color height_color = new Color(194,31,31);
178 static final private Color gps_height_color = new Color(150,31,31);
179 static final private Color pressure_color = new Color (225,31,31);
180 static final private Color range_color = new Color(100, 31, 31);
181 static final private Color distance_color = new Color(100, 31, 194);
182 static final private Color speed_color = new Color(31,194,31);
183 static final private Color accel_color = new Color(31,31,194);
184 static final private Color voltage_color = new Color(194, 194, 31);
185 static final private Color battery_voltage_color = new Color(194, 194, 31);
186 static final private Color drogue_voltage_color = new Color(150, 150, 31);
187 static final private Color main_voltage_color = new Color(100, 100, 31);
188 static final private Color gps_nsat_color = new Color (194, 31, 194);
189 static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
190 static final private Color gps_nsat_view_color = new Color (150, 31, 150);
191 static final private Color gps_course_color = new Color (100, 31, 112);
192 static final private Color gps_ground_speed_color = new Color (31, 112, 100);
193 static final private Color gps_climb_rate_color = new Color (31, 31, 112);
194 static final private Color temperature_color = new Color (31, 194, 194);
195 static final private Color dbm_color = new Color(31, 100, 100);
196 static final private Color state_color = new Color(0,0,0);
197 static final private Color accel_x_color = new Color(255, 0, 0);
198 static final private Color accel_y_color = new Color(0, 255, 0);
199 static final private Color accel_z_color = new Color(0, 0, 255);
200 static final private Color gyro_x_color = new Color(192, 0, 0);
201 static final private Color gyro_y_color = new Color(0, 192, 0);
202 static final private Color gyro_z_color = new Color(0, 0, 192);
203 static final private Color mag_x_color = new Color(128, 0, 0);
204 static final private Color mag_y_color = new Color(0, 128, 0);
205 static final private Color mag_z_color = new Color(0, 0, 128);
206 static final private Color orient_color = new Color(31, 31, 31);
208 static AltosVoltage voltage_units = new AltosVoltage();
209 static AltosPressure pressure_units = new AltosPressure();
210 static AltosNsat nsat_units = new AltosNsat();
211 static AltosDbm dbm_units = new AltosDbm();
212 static AltosGyroUnits gyro_units = new AltosGyroUnits();
213 static AltosOrient orient_units = new AltosOrient();
214 static AltosMagUnits mag_units = new AltosMagUnits();
216 AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
217 AltosUIAxis distance_axis, pressure_axis;
218 AltosUIAxis gyro_axis, orient_axis, mag_axis;
219 AltosUIAxis course_axis;
221 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
224 height_axis = newAxis("Height", AltosConvert.height, height_color);
225 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
226 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
227 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
228 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
229 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
230 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
231 AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
232 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
233 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
235 gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0);
236 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
237 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
238 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
240 addMarker("State", AltosGraphDataPoint.data_state, state_color);
242 if (stats.has_flight_data) {
244 AltosGraphDataPoint.data_height,
249 addSeries("Pressure",
250 AltosGraphDataPoint.data_pressure,
256 AltosGraphDataPoint.data_speed,
261 addSeries("Acceleration",
262 AltosGraphDataPoint.data_accel,
269 boolean enable_gps = false;
271 if (!stats.has_flight_data)
275 AltosGraphDataPoint.data_range,
276 AltosConvert.distance,
280 addSeries("Distance",
281 AltosGraphDataPoint.data_distance,
282 AltosConvert.distance,
286 addSeries("GPS Height",
287 AltosGraphDataPoint.data_gps_height,
292 addSeries("GPS Altitude",
293 AltosGraphDataPoint.data_gps_altitude,
298 addSeries("GPS Satellites in Solution",
299 AltosGraphDataPoint.data_gps_nsat_solution,
301 gps_nsat_solution_color,
304 addSeries("GPS Satellites in View",
305 AltosGraphDataPoint.data_gps_nsat_view,
310 addSeries("GPS Course",
311 AltosGraphDataPoint.data_gps_course,
316 addSeries("GPS Ground Speed",
317 AltosGraphDataPoint.data_gps_ground_speed,
319 gps_ground_speed_color,
322 addSeries("GPS Climb Rate",
323 AltosGraphDataPoint.data_gps_climb_rate,
325 gps_climb_rate_color,
330 addSeries("Received Signal Strength",
331 AltosGraphDataPoint.data_rssi,
337 if (stats.has_battery)
338 addSeries("Battery Voltage",
339 AltosGraphDataPoint.data_battery_voltage,
341 battery_voltage_color,
345 if (stats.has_flight_adc) {
346 addSeries("Temperature",
347 AltosGraphDataPoint.data_temperature,
348 AltosConvert.temperature,
352 addSeries("Drogue Voltage",
353 AltosGraphDataPoint.data_drogue_voltage,
355 drogue_voltage_color,
358 addSeries("Main Voltage",
359 AltosGraphDataPoint.data_main_voltage,
367 addSeries("Acceleration X",
368 AltosGraphDataPoint.data_accel_x,
373 addSeries("Acceleration Y",
374 AltosGraphDataPoint.data_accel_y,
379 addSeries("Acceleration Z",
380 AltosGraphDataPoint.data_accel_z,
385 addSeries("Rotation Rate X",
386 AltosGraphDataPoint.data_gyro_x,
391 addSeries("Rotation Rate Y",
392 AltosGraphDataPoint.data_gyro_y,
397 addSeries("Rotation Rate Z",
398 AltosGraphDataPoint.data_gyro_z,
405 addSeries("Magnetometer X",
406 AltosGraphDataPoint.data_mag_x,
411 addSeries("Magnetometer Y",
412 AltosGraphDataPoint.data_mag_y,
417 addSeries("Magnetometer Z",
418 AltosGraphDataPoint.data_mag_z,
424 if (stats.has_orient)
425 addSeries("Tilt Angle",
426 AltosGraphDataPoint.data_orient,
431 if (stats.num_ignitor > 0) {
432 for (int i = 0; i < stats.num_ignitor; i++)
433 addSeries(AltosLib.ignitor_name(i),
434 AltosGraphDataPoint.data_ignitor_0 + i,
439 for (int i = 0; i < stats.num_ignitor; i++)
440 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);