altosui: Add raw pressure to the AltosUI graph
[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_1.*;
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 public class AltosGraph extends AltosUIGraph {
96
97         static final private Color height_color = new Color(194,31,31);
98         static final private Color gps_height_color = new Color(150,31,31);
99         static final private Color pressure_color = new Color (225,31,31);
100         static final private Color range_color = new Color(100, 31, 31);
101         static final private Color distance_color = new Color(100, 31, 194);
102         static final private Color speed_color = new Color(31,194,31);
103         static final private Color accel_color = new Color(31,31,194);
104         static final private Color voltage_color = new Color(194, 194, 31);
105         static final private Color battery_voltage_color = new Color(194, 194, 31);
106         static final private Color drogue_voltage_color = new Color(150, 150, 31);
107         static final private Color main_voltage_color = new Color(100, 100, 31);
108         static final private Color gps_nsat_color = new Color (194, 31, 194);
109         static final private Color gps_nsat_solution_color = new Color (194, 31, 194);
110         static final private Color gps_nsat_view_color = new Color (150, 31, 150);
111         static final private Color temperature_color = new Color (31, 194, 194);
112         static final private Color dbm_color = new Color(31, 100, 100);
113         static final private Color state_color = new Color(0,0,0);
114
115         static AltosVoltage voltage_units = new AltosVoltage();
116         static AltosPressure pressure_units = new AltosPressure();
117         static AltosNsat nsat_units = new AltosNsat();
118         static AltosDbm dbm_units = new AltosDbm();
119
120         AltosUIAxis     height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis;
121         AltosUIAxis     distance_axis, pressure_axis;
122
123         public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) {
124                 super(enable);
125
126                 height_axis = newAxis("Height", AltosConvert.height, height_color);
127                 pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0);
128                 speed_axis = newAxis("Speed", AltosConvert.speed, speed_color);
129                 accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color);
130                 voltage_axis = newAxis("Voltage", voltage_units, voltage_color);
131                 temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0);
132                 nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color,
133                                     AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer);
134                 dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0);
135                 distance_axis = newAxis("Distance", AltosConvert.distance, range_color);
136
137                 addMarker("State", AltosGraphDataPoint.data_state, state_color);
138                 addSeries("Height",
139                           AltosGraphDataPoint.data_height,
140                           AltosConvert.height,
141                           height_color,
142                           true,
143                           height_axis);
144                 addSeries("Pressure",
145                           AltosGraphDataPoint.data_pressure,
146                           pressure_units,
147                           pressure_color,
148                           false,
149                           pressure_axis);
150                 addSeries("Speed",
151                           AltosGraphDataPoint.data_speed,
152                           AltosConvert.speed,
153                           speed_color,
154                           true,
155                           speed_axis);
156                 addSeries("Acceleration",
157                           AltosGraphDataPoint.data_accel,
158                           AltosConvert.accel,
159                           accel_color,
160                           true,
161                           accel_axis);
162                 if (stats.has_gps) {
163                         addSeries("Range",
164                                   AltosGraphDataPoint.data_range,
165                                   AltosConvert.distance,
166                                   range_color,
167                                   false,
168                                   distance_axis);
169                         addSeries("Distance",
170                                   AltosGraphDataPoint.data_distance,
171                                   AltosConvert.distance,
172                                   distance_color,
173                                   false,
174                                   distance_axis);
175                         addSeries("GPS Height",
176                                   AltosGraphDataPoint.data_gps_height,
177                                   AltosConvert.height,
178                                   gps_height_color,
179                                   false,
180                                   height_axis);
181                         addSeries("GPS Satellites in Solution",
182                                   AltosGraphDataPoint.data_gps_nsat_solution,
183                                   nsat_units,
184                                   gps_nsat_solution_color,
185                                   false,
186                                   nsat_axis);
187                         addSeries("GPS Satellites in View",
188                                   AltosGraphDataPoint.data_gps_nsat_view,
189                                   nsat_units,
190                                   gps_nsat_view_color,
191                                   false,
192                           nsat_axis);
193                 }
194                 if (stats.has_rssi)
195                         addSeries("Received Signal Strength",
196                                   AltosGraphDataPoint.data_rssi,
197                                   dbm_units,
198                                   dbm_color,
199                                   false,
200                                   dbm_axis);
201                 if (stats.has_other_adc) {
202                         addSeries("Temperature",
203                                   AltosGraphDataPoint.data_temperature,
204                                   AltosConvert.temperature,
205                                   temperature_color,
206                                   false,
207                                   temperature_axis);
208                         addSeries("Battery Voltage",
209                                   AltosGraphDataPoint.data_battery_voltage,
210                                   voltage_units,
211                                   battery_voltage_color,
212                                   false,
213                                   voltage_axis);
214                         addSeries("Drogue Voltage",
215                                   AltosGraphDataPoint.data_drogue_voltage,
216                                   voltage_units,
217                                   drogue_voltage_color,
218                                   false,
219                                   voltage_axis);
220                         addSeries("Main Voltage",
221                                   AltosGraphDataPoint.data_main_voltage,
222                                   voltage_units,
223                                   main_voltage_color,
224                                   false,
225                                   voltage_axis);
226                 }
227
228                 setDataSet(dataSet);
229         }
230 }