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 AltosGraphDataPoint.data_height,
247 addSeries("Pressure",
248 AltosGraphDataPoint.data_pressure,
254 AltosGraphDataPoint.data_speed,
259 addSeries("Acceleration",
260 AltosGraphDataPoint.data_accel,
267 AltosGraphDataPoint.data_range,
268 AltosConvert.distance,
272 addSeries("Distance",
273 AltosGraphDataPoint.data_distance,
274 AltosConvert.distance,
278 addSeries("GPS Height",
279 AltosGraphDataPoint.data_gps_height,
284 addSeries("GPS Satellites in Solution",
285 AltosGraphDataPoint.data_gps_nsat_solution,
287 gps_nsat_solution_color,
290 addSeries("GPS Satellites in View",
291 AltosGraphDataPoint.data_gps_nsat_view,
296 addSeries("GPS Course",
297 AltosGraphDataPoint.data_gps_course,
302 addSeries("GPS Ground Speed",
303 AltosGraphDataPoint.data_gps_ground_speed,
305 gps_ground_speed_color,
308 addSeries("GPS Climb Rate",
309 AltosGraphDataPoint.data_gps_climb_rate,
311 gps_climb_rate_color,
316 addSeries("Received Signal Strength",
317 AltosGraphDataPoint.data_rssi,
322 if (stats.has_other_adc) {
323 addSeries("Temperature",
324 AltosGraphDataPoint.data_temperature,
325 AltosConvert.temperature,
329 addSeries("Battery Voltage",
330 AltosGraphDataPoint.data_battery_voltage,
332 battery_voltage_color,
335 addSeries("Drogue Voltage",
336 AltosGraphDataPoint.data_drogue_voltage,
338 drogue_voltage_color,
341 addSeries("Main Voltage",
342 AltosGraphDataPoint.data_main_voltage,
350 addSeries("Acceleration X",
351 AltosGraphDataPoint.data_accel_x,
356 addSeries("Acceleration Y",
357 AltosGraphDataPoint.data_accel_y,
362 addSeries("Acceleration Z",
363 AltosGraphDataPoint.data_accel_z,
368 addSeries("Rotation Rate X",
369 AltosGraphDataPoint.data_gyro_x,
374 addSeries("Rotation Rate Y",
375 AltosGraphDataPoint.data_gyro_y,
380 addSeries("Rotation Rate Z",
381 AltosGraphDataPoint.data_gyro_z,
388 addSeries("Magnetometer X",
389 AltosGraphDataPoint.data_mag_x,
394 addSeries("Magnetometer Y",
395 AltosGraphDataPoint.data_mag_y,
400 addSeries("Magnetometer Z",
401 AltosGraphDataPoint.data_mag_z,
407 if (stats.has_orient)
408 addSeries("Tilt Angle",
409 AltosGraphDataPoint.data_orient,
414 if (stats.num_ignitor > 0) {
415 for (int i = 0; i < stats.num_ignitor; i++)
416 addSeries(AltosLib.ignitor_name(i),
417 AltosGraphDataPoint.data_ignitor_0 + i,
422 for (int i = 0; i < stats.num_ignitor; i++)
423 addMarker(AltosLib.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);