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.
21 import java.util.ArrayList;
25 import org.altusmetrum.altoslib_4.*;
26 import org.altusmetrum.altosuilib_2.*;
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 public class AltosGraph extends AltosUIGraph {
178 static final private Color height_color = new Color(194,31,31);
179 static final private Color gps_height_color = new Color(150,31,31);
180 static final private Color pressure_color = new Color (225,31,31);
181 static final private Color range_color = new Color(100, 31, 31);
182 static final private Color distance_color = new Color(100, 31, 194);
183 static final private Color speed_color = new Color(31,194,31);
184 static final private Color accel_color = new Color(31,31,194);
185 static final private Color voltage_color = new Color(194, 194, 31);
186 static final private Color battery_voltage_color = new Color(194, 194, 31);
187 static final private Color drogue_voltage_color = new Color(150, 150, 31);
188 static final private Color main_voltage_color = new Color(100, 100, 31);
189 static final private Color gps_nsat_color = new Color (194, 31, 194);
190 static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
191 static final private Color gps_nsat_view_color = new Color (150, 31, 150);
192 static final private Color gps_course_color = new Color (100, 31, 112);
193 static final private Color gps_ground_speed_color = new Color (31, 112, 100);
194 static final private Color gps_climb_rate_color = new Color (31, 31, 112);
195 static final private Color temperature_color = new Color (31, 194, 194);
196 static final private Color dbm_color = new Color(31, 100, 100);
197 static final private Color state_color = new Color(0,0,0);
198 static final private Color accel_x_color = new Color(255, 0, 0);
199 static final private Color accel_y_color = new Color(0, 255, 0);
200 static final private Color accel_z_color = new Color(0, 0, 255);
201 static final private Color gyro_x_color = new Color(192, 0, 0);
202 static final private Color gyro_y_color = new Color(0, 192, 0);
203 static final private Color gyro_z_color = new Color(0, 0, 192);
204 static final private Color mag_x_color = new Color(128, 0, 0);
205 static final private Color mag_y_color = new Color(0, 128, 0);
206 static final private Color mag_z_color = new Color(0, 0, 128);
207 static final private Color orient_color = new Color(31, 31, 31);
209 static AltosVoltage voltage_units = new AltosVoltage();
210 static AltosPressure pressure_units = new AltosPressure();
211 static AltosNsat nsat_units = new AltosNsat();
212 static AltosDbm dbm_units = new AltosDbm();
213 static AltosGyroUnits gyro_units = new AltosGyroUnits();
214 static AltosOrient orient_units = new AltosOrient();
215 static AltosMagUnits mag_units = new AltosMagUnits();
217 AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
218 AltosUIAxis distance_axis, pressure_axis;
219 AltosUIAxis gyro_axis, orient_axis, mag_axis;
220 AltosUIAxis course_axis;
222 public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
225 height_axis = newAxis("Height", AltosConvert.height, height_color);
226 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
227 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
228 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
229 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
230 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
231 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
232 AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
233 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
234 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
236 gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0);
237 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
238 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
239 course_axis = newAxis("Course", orient_units, gps_course_color, 0);
241 addMarker("State", AltosGraphDataPoint.data_state, state_color);
243 AltosGraphDataPoint.data_height,
248 addSeries("Pressure",
249 AltosGraphDataPoint.data_pressure,
255 AltosGraphDataPoint.data_speed,
260 addSeries("Acceleration",
261 AltosGraphDataPoint.data_accel,
268 AltosGraphDataPoint.data_range,
269 AltosConvert.distance,
273 addSeries("Distance",
274 AltosGraphDataPoint.data_distance,
275 AltosConvert.distance,
279 addSeries("GPS Height",
280 AltosGraphDataPoint.data_gps_height,
285 addSeries("GPS Satellites in Solution",
286 AltosGraphDataPoint.data_gps_nsat_solution,
288 gps_nsat_solution_color,
291 addSeries("GPS Satellites in View",
292 AltosGraphDataPoint.data_gps_nsat_view,
297 addSeries("GPS Course",
298 AltosGraphDataPoint.data_gps_course,
303 addSeries("GPS Ground Speed",
304 AltosGraphDataPoint.data_gps_ground_speed,
306 gps_ground_speed_color,
309 addSeries("GPS Climb Rate",
310 AltosGraphDataPoint.data_gps_climb_rate,
312 gps_climb_rate_color,
317 addSeries("Received Signal Strength",
318 AltosGraphDataPoint.data_rssi,
323 if (stats.has_other_adc) {
324 addSeries("Temperature",
325 AltosGraphDataPoint.data_temperature,
326 AltosConvert.temperature,
330 addSeries("Battery Voltage",
331 AltosGraphDataPoint.data_battery_voltage,
333 battery_voltage_color,
336 addSeries("Drogue Voltage",
337 AltosGraphDataPoint.data_drogue_voltage,
339 drogue_voltage_color,
342 addSeries("Main Voltage",
343 AltosGraphDataPoint.data_main_voltage,
351 addSeries("Acceleration X",
352 AltosGraphDataPoint.data_accel_x,
357 addSeries("Acceleration Y",
358 AltosGraphDataPoint.data_accel_y,
363 addSeries("Acceleration Z",
364 AltosGraphDataPoint.data_accel_z,
369 addSeries("Rotation Rate X",
370 AltosGraphDataPoint.data_gyro_x,
375 addSeries("Rotation Rate Y",
376 AltosGraphDataPoint.data_gyro_y,
381 addSeries("Rotation Rate Z",
382 AltosGraphDataPoint.data_gyro_z,
389 addSeries("Magnetometer X",
390 AltosGraphDataPoint.data_mag_x,
395 addSeries("Magnetometer Y",
396 AltosGraphDataPoint.data_mag_y,
401 addSeries("Magnetometer Z",
402 AltosGraphDataPoint.data_mag_z,
408 if (stats.has_orient)
409 addSeries("Tilt Angle",
410 AltosGraphDataPoint.data_orient,
415 if (stats.num_ignitor > 0) {
416 for (int i = 0; i < stats.num_ignitor; i++)
417 addSeries(AltosIgnitor.ignitor_name(i),
418 AltosGraphDataPoint.data_ignitor_0 + i,
423 for (int i = 0; i < stats.num_ignitor; i++)
424 addMarker(AltosIgnitor.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);