altos: Use #define values for ublox packet types
[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_2.*;
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) {
41                 return v;
42         }
43
44         public String show_units() {
45                 return "V";
46         }
47
48         public String say_units() {
49                 return "volts";
50         }
51
52         public int show_fraction(int width) {
53                 return width / 2;
54         }
55 }
56
57 class AltosNsat extends AltosUnits {
58
59         public double value(double v) {
60                 return v;
61         }
62
63         public String show_units() {
64                 return "Sats";
65         }
66
67         public String say_units() {
68                 return "Satellites";
69         }
70
71         public int show_fraction(int width) {
72                 return 0;
73         }
74 }
75
76 class AltosPressure extends AltosUnits {
77
78         public double value(double p) {
79                 return p;
80         }
81
82         public String show_units() {
83                 return "Pa";
84         }
85
86         public String say_units() {
87                 return "pascals";
88         }
89
90         public int show_fraction(int width) {
91                 return 0;
92         }
93 }
94
95 class AltosDbm extends AltosUnits {
96
97         public double value(double d) {
98                 return d;
99         }
100
101         public String show_units() {
102                 return "dBm";
103         }
104
105         public String say_units() {
106                 return "D B M";
107         }
108
109         public int show_fraction(int width) {
110                 return 0;
111         }
112 }
113
114 public class AltosGraph extends AltosUIGraph {
115
116         static final private Color height_color = new Color(194,31,31);
117         static final private Color gps_height_color = new Color(150,31,31);
118         static final private Color pressure_color = new Color (225,31,31);
119         static final private Color range_color = new Color(100, 31, 31);
120         static final private Color distance_color = new Color(100, 31, 194);
121         static final private Color speed_color = new Color(31,194,31);
122         static final private Color accel_color = new Color(31,31,194);
123         static final private Color voltage_color = new Color(194, 194, 31);
124         static final private Color battery_voltage_color = new Color(194, 194, 31);
125         static final private Color drogue_voltage_color = new Color(150, 150, 31);
126         static final private Color main_voltage_color = new Color(100, 100, 31);
127         static final private Color gps_nsat_color = new Color (194, 31, 194);
128         static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
129         static final private Color gps_nsat_view_color = new Color (150, 31, 150);
130         static final private Color temperature_color = new Color (31, 194, 194);
131         static final private Color dbm_color = new Color(31, 100, 100);
132         static final private Color state_color = new Color(0,0,0);
133
134         static AltosVoltage voltage_units = new AltosVoltage();
135         static AltosPressure pressure_units = new AltosPressure();
136         static AltosNsat nsat_units = new AltosNsat();
137         static AltosDbm dbm_units = new AltosDbm();
138
139         AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
140         AltosUIAxis     distance_axis, pressure_axis;
141
142         public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
143                 super(enable);
144
145                 height_axis = newAxis("Height", AltosConvert.height, height_color);
146                 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
147                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
148                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
149                 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
150                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
151                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
152                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
153                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
154                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
155
156                 addMarker("State", AltosGraphDataPoint.data_state, state_color);
157                 addSeries("Height",
158                           AltosGraphDataPoint.data_height,
159                           AltosConvert.height,
160                           height_color,
161                           true,
162                           height_axis);
163                 addSeries("Pressure",
164                           AltosGraphDataPoint.data_pressure,
165                           pressure_units,
166                           pressure_color,
167                           false,
168                           pressure_axis);
169                 addSeries("Speed",
170                           AltosGraphDataPoint.data_speed,
171                           AltosConvert.speed,
172                           speed_color,
173                           true,
174                           speed_axis);
175                 addSeries("Acceleration",
176                           AltosGraphDataPoint.data_accel,
177                           AltosConvert.accel,
178                           accel_color,
179                           true,
180                           accel_axis);
181                 if (stats.has_gps) {
182                         addSeries("Range",
183                                   AltosGraphDataPoint.data_range,
184                                   AltosConvert.distance,
185                                   range_color,
186                                   false,
187                                   distance_axis);
188                         addSeries("Distance",
189                                   AltosGraphDataPoint.data_distance,
190                                   AltosConvert.distance,
191                                   distance_color,
192                                   false,
193                                   distance_axis);
194                         addSeries("GPS Height",
195                                   AltosGraphDataPoint.data_gps_height,
196                                   AltosConvert.height,
197                                   gps_height_color,
198                                   false,
199                                   height_axis);
200                         addSeries("GPS Satellites in Solution",
201                                   AltosGraphDataPoint.data_gps_nsat_solution,
202                                   nsat_units,
203                                   gps_nsat_solution_color,
204                                   false,
205                                   nsat_axis);
206                         addSeries("GPS Satellites in View",
207                                   AltosGraphDataPoint.data_gps_nsat_view,
208                                   nsat_units,
209                                   gps_nsat_view_color,
210                                   false,
211                           nsat_axis);
212                 }
213                 if (stats.has_rssi)
214                         addSeries("Received Signal Strength",
215                                   AltosGraphDataPoint.data_rssi,
216                                   dbm_units,
217                                   dbm_color,
218                                   false,
219                                   dbm_axis);
220                 if (stats.has_other_adc) {
221                         addSeries("Temperature",
222                                   AltosGraphDataPoint.data_temperature,
223                                   AltosConvert.temperature,
224                                   temperature_color,
225                                   false,
226                                   temperature_axis);
227                         addSeries("Battery Voltage",
228                                   AltosGraphDataPoint.data_battery_voltage,
229                                   voltage_units,
230                                   battery_voltage_color,
231                                   false,
232                                   voltage_axis);
233                         addSeries("Drogue Voltage",
234                                   AltosGraphDataPoint.data_drogue_voltage,
235                                   voltage_units,
236                                   drogue_voltage_color,
237                                   false,
238                                   voltage_axis);
239                         addSeries("Main Voltage",
240                                   AltosGraphDataPoint.data_main_voltage,
241                                   voltage_units,
242                                   main_voltage_color,
243                                   false,
244                                   voltage_axis);
245                 }
246
247                 setDataSet(dataSet);
248         }
249 }