altosui: Mark TeleMega additional pyro ignitor fired points in graphs
[fw/altos] / altosui / AltosGraph.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import java.io.*;
21 import java.util.ArrayList;
22
23 import java.awt.*;
24 import javax.swing.*;
25 import org.altusmetrum.altoslib_3.*;
26 import org.altusmetrum.altosuilib_1.*;
27
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.*;
37
38 class AltosVoltage extends AltosUnits {
39
40         public double value(double v, boolean imperial_units) {
41                 return v;
42         }
43
44         public double inverse(double v, boolean imperial_units) {
45                 return v;
46         }
47
48         public String show_units(boolean imperial_units) {
49                 return "V";
50         }
51
52         public String say_units(boolean imperial_units) {
53                 return "volts";
54         }
55
56         public int show_fraction(int width, boolean imperial_units) {
57                 return width / 2;
58         }
59 }
60
61 class AltosNsat extends AltosUnits {
62
63         public double value(double v, boolean imperial_units) {
64                 return v;
65         }
66
67         public double inverse(double v, boolean imperial_units) {
68                 return v;
69         }
70
71         public String show_units(boolean imperial_units) {
72                 return "Sats";
73         }
74
75         public String say_units(boolean imperial_units) {
76                 return "Satellites";
77         }
78
79         public int show_fraction(int width, boolean imperial_units) {
80                 return 0;
81         }
82 }
83
84 class AltosPressure extends AltosUnits {
85
86         public double value(double p, boolean imperial_units) {
87                 return p;
88         }
89
90         public double inverse(double p, boolean imperial_units) {
91                 return p;
92         }
93
94         public String show_units(boolean imperial_units) {
95                 return "Pa";
96         }
97
98         public String say_units(boolean imperial_units) {
99                 return "pascals";
100         }
101
102         public int show_fraction(int width, boolean imperial_units) {
103                 return 0;
104         }
105 }
106
107 class AltosDbm extends AltosUnits {
108
109         public double value(double d, boolean imperial_units) {
110                 return d;
111         }
112
113         public double inverse(double d, boolean imperial_units) {
114                 return d;
115         }
116
117         public String show_units(boolean imperial_units) {
118                 return "dBm";
119         }
120
121         public String say_units(boolean imperial_units) {
122                 return "D B M";
123         }
124
125         public int show_fraction(int width, boolean imperial_units) {
126                 return 0;
127         }
128 }
129
130 class AltosGyroUnits extends AltosUnits {
131
132         public double value(double p, boolean imperial_units) {
133                 return p;
134         }
135
136         public double inverse(double p, boolean imperial_units) {
137                 return p;
138         }
139
140         public String show_units(boolean imperial_units) {
141                 return "°/sec";
142         }
143
144         public String say_units(boolean imperial_units) {
145                 return "degrees per second";
146         }
147
148         public int show_fraction(int width, boolean imperial_units) {
149                 return 1;
150         }
151 }
152
153 class AltosMagUnits extends AltosUnits {
154
155         public double value(double p, boolean imperial_units) {
156                 return p;
157         }
158
159         public double inverse(double p, boolean imperial_units) {
160                 return p;
161         }
162
163         public String show_units(boolean imperial_units) {
164                 return "Ga";
165         }
166
167         public String say_units(boolean imperial_units) {
168                 return "gauss";
169         }
170
171         public int show_fraction(int width, boolean imperial_units) {
172                 return 2;
173         }
174 }
175
176 public class AltosGraph extends AltosUIGraph {
177
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 temperature_color = new Color (31, 194, 194);
193         static final private Color dbm_color = new Color(31, 100, 100);
194         static final private Color state_color = new Color(0,0,0);
195         static final private Color accel_x_color = new Color(255, 0, 0);
196         static final private Color accel_y_color = new Color(0, 255, 0);
197         static final private Color accel_z_color = new Color(0, 0, 255);
198         static final private Color gyro_x_color = new Color(192, 0, 0);
199         static final private Color gyro_y_color = new Color(0, 192, 0);
200         static final private Color gyro_z_color = new Color(0, 0, 192);
201         static final private Color mag_x_color = new Color(128, 0, 0);
202         static final private Color mag_y_color = new Color(0, 128, 0);
203         static final private Color mag_z_color = new Color(0, 0, 128);
204         static final private Color orient_color = new Color(31, 31, 31);
205
206         static AltosVoltage voltage_units = new AltosVoltage();
207         static AltosPressure pressure_units = new AltosPressure();
208         static AltosNsat nsat_units = new AltosNsat();
209         static AltosDbm dbm_units = new AltosDbm();
210         static AltosGyroUnits gyro_units = new AltosGyroUnits();
211         static AltosOrient orient_units = new AltosOrient();
212         static AltosMagUnits mag_units = new AltosMagUnits();
213
214         AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
215         AltosUIAxis     distance_axis, pressure_axis;
216         AltosUIAxis     gyro_axis, orient_axis, mag_axis;
217
218         public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
219                 super(enable);
220
221                 height_axis = newAxis("Height", AltosConvert.height, height_color);
222                 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
223                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
224                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
225                 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
226                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
227                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
228                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
229                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
230                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
231
232                 gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0);
233                 orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0);
234                 mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0);
235
236                 addMarker("State", AltosGraphDataPoint.data_state, state_color);
237                 addSeries("Height",
238                           AltosGraphDataPoint.data_height,
239                           AltosConvert.height,
240                           height_color,
241                           true,
242                           height_axis);
243                 addSeries("Pressure",
244                           AltosGraphDataPoint.data_pressure,
245                           pressure_units,
246                           pressure_color,
247                           false,
248                           pressure_axis);
249                 addSeries("Speed",
250                           AltosGraphDataPoint.data_speed,
251                           AltosConvert.speed,
252                           speed_color,
253                           true,
254                           speed_axis);
255                 addSeries("Acceleration",
256                           AltosGraphDataPoint.data_accel,
257                           AltosConvert.accel,
258                           accel_color,
259                           true,
260                           accel_axis);
261                 if (stats.has_gps) {
262                         addSeries("Range",
263                                   AltosGraphDataPoint.data_range,
264                                   AltosConvert.distance,
265                                   range_color,
266                                   false,
267                                   distance_axis);
268                         addSeries("Distance",
269                                   AltosGraphDataPoint.data_distance,
270                                   AltosConvert.distance,
271                                   distance_color,
272                                   false,
273                                   distance_axis);
274                         addSeries("GPS Height",
275                                   AltosGraphDataPoint.data_gps_height,
276                                   AltosConvert.height,
277                                   gps_height_color,
278                                   false,
279                                   height_axis);
280                         addSeries("GPS Satellites in Solution",
281                                   AltosGraphDataPoint.data_gps_nsat_solution,
282                                   nsat_units,
283                                   gps_nsat_solution_color,
284                                   false,
285                                   nsat_axis);
286                         addSeries("GPS Satellites in View",
287                                   AltosGraphDataPoint.data_gps_nsat_view,
288                                   nsat_units,
289                                   gps_nsat_view_color,
290                                   false,
291                           nsat_axis);
292                 }
293                 if (stats.has_rssi)
294                         addSeries("Received Signal Strength",
295                                   AltosGraphDataPoint.data_rssi,
296                                   dbm_units,
297                                   dbm_color,
298                                   false,
299                                   dbm_axis);
300                 if (stats.has_other_adc) {
301                         addSeries("Temperature",
302                                   AltosGraphDataPoint.data_temperature,
303                                   AltosConvert.temperature,
304                                   temperature_color,
305                                   false,
306                                   temperature_axis);
307                         addSeries("Battery Voltage",
308                                   AltosGraphDataPoint.data_battery_voltage,
309                                   voltage_units,
310                                   battery_voltage_color,
311                                   false,
312                                   voltage_axis);
313                         addSeries("Drogue Voltage",
314                                   AltosGraphDataPoint.data_drogue_voltage,
315                                   voltage_units,
316                                   drogue_voltage_color,
317                                   false,
318                                   voltage_axis);
319                         addSeries("Main Voltage",
320                                   AltosGraphDataPoint.data_main_voltage,
321                                   voltage_units,
322                                   main_voltage_color,
323                                   false,
324                                   voltage_axis);
325                 }
326
327                 if (stats.has_imu) {
328                         addSeries("Acceleration X",
329                                   AltosGraphDataPoint.data_accel_x,
330                                   AltosConvert.accel,
331                                   accel_x_color,
332                                   false,
333                                   accel_axis);
334                         addSeries("Acceleration Y",
335                                   AltosGraphDataPoint.data_accel_y,
336                                   AltosConvert.accel,
337                                   accel_y_color,
338                                   false,
339                                   accel_axis);
340                         addSeries("Acceleration Z",
341                                   AltosGraphDataPoint.data_accel_z,
342                                   AltosConvert.accel,
343                                   accel_z_color,
344                                   false,
345                                   accel_axis);
346                         addSeries("Rotation Rate X",
347                                   AltosGraphDataPoint.data_gyro_x,
348                                   gyro_units,
349                                   gyro_x_color,
350                                   false,
351                                   gyro_axis);
352                         addSeries("Rotation Rate Y",
353                                   AltosGraphDataPoint.data_gyro_y,
354                                   gyro_units,
355                                   gyro_y_color,
356                                   false,
357                                   gyro_axis);
358                         addSeries("Rotation Rate Z",
359                                   AltosGraphDataPoint.data_gyro_z,
360                                   gyro_units,
361                                   gyro_z_color,
362                                   false,
363                                   gyro_axis);
364                 }
365                 if (stats.has_mag) {
366                         addSeries("Magnetometer X",
367                                   AltosGraphDataPoint.data_mag_x,
368                                   mag_units,
369                                   mag_x_color,
370                                   false,
371                                   mag_axis);
372                         addSeries("Magnetometer Y",
373                                   AltosGraphDataPoint.data_mag_y,
374                                   mag_units,
375                                   mag_y_color,
376                                   false,
377                                   mag_axis);
378                         addSeries("Magnetometer Z",
379                                   AltosGraphDataPoint.data_mag_z,
380                                   mag_units,
381                                   mag_z_color,
382                                   false,
383                                   mag_axis);
384                 }
385                 if (stats.has_orient)
386                         addSeries("Tilt Angle",
387                                   AltosGraphDataPoint.data_orient,
388                                   orient_units,
389                                   orient_color,
390                                   false,
391                                   orient_axis);
392                 if (stats.num_ignitor > 0) {
393                         for (int i = 0; i < stats.num_ignitor; i++)
394                                 addSeries(AltosIgnitor.ignitor_name(i),
395                                           AltosGraphDataPoint.data_ignitor_0 + i,
396                                           voltage_units,
397                                           main_voltage_color,
398                                           false,
399                                           voltage_axis);
400                         for (int i = 0; i < stats.num_ignitor; i++)
401                                 addMarker(AltosIgnitor.ignitor_name(i), AltosGraphDataPoint.data_ignitor_fired_0 + i, state_color);
402                 }
403
404                 setDataSet(dataSet);
405         }
406 }