2 * Copyright © 2010 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.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosAscent extends JComponent implements AltosFlightDisplay {
36 public class AscentStatus {
42 value.setVisible(true);
43 lights.setVisible(true);
44 label.setVisible(true);
48 value.setVisible(false);
49 lights.setVisible(false);
50 label.setVisible(false);
53 void show(AltosState state, int crc_errors) {}
60 label.setFont(Altos.label_font);
61 value.setFont(Altos.value_font);
64 public AscentStatus (GridBagLayout layout, int y, String text) {
65 GridBagConstraints c = new GridBagConstraints();
68 lights = new AltosLights();
69 c.gridx = 0; c.gridy = y;
70 c.anchor = GridBagConstraints.CENTER;
71 c.fill = GridBagConstraints.VERTICAL;
73 layout.setConstraints(lights, c);
76 label = new JLabel(text);
77 label.setFont(Altos.label_font);
78 label.setHorizontalAlignment(SwingConstants.LEFT);
79 c.gridx = 1; c.gridy = y;
80 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
81 c.anchor = GridBagConstraints.WEST;
82 c.fill = GridBagConstraints.VERTICAL;
84 layout.setConstraints(label, c);
87 value = new JTextField(Altos.text_width);
88 value.setFont(Altos.value_font);
89 value.setHorizontalAlignment(SwingConstants.RIGHT);
90 c.gridx = 2; c.gridy = y;
92 c.anchor = GridBagConstraints.WEST;
93 c.fill = GridBagConstraints.BOTH;
95 layout.setConstraints(value, c);
101 public class AscentValue {
104 void show(AltosState state, int crc_errors) {}
111 label.setVisible(true);
112 value.setVisible(true);
116 label.setVisible(false);
117 value.setVisible(false);
120 label.setFont(Altos.label_font);
121 value.setFont(Altos.value_font);
124 public AscentValue (GridBagLayout layout, int y, String text) {
125 GridBagConstraints c = new GridBagConstraints();
128 label = new JLabel(text);
129 label.setFont(Altos.label_font);
130 label.setHorizontalAlignment(SwingConstants.LEFT);
131 c.gridx = 1; c.gridy = y;
132 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
133 c.anchor = GridBagConstraints.WEST;
134 c.fill = GridBagConstraints.VERTICAL;
136 layout.setConstraints(label, c);
139 value = new JTextField(Altos.text_width);
140 value.setFont(Altos.value_font);
141 value.setHorizontalAlignment(SwingConstants.RIGHT);
142 c.gridx = 2; c.gridy = y;
143 c.anchor = GridBagConstraints.WEST;
144 c.fill = GridBagConstraints.BOTH;
147 layout.setConstraints(value, c);
152 public class AscentValueHold {
155 JTextField max_value;
158 void show(AltosState state, int crc_errors) {}
162 max_value.setText("");
163 max = AltosRecord.MISSING;
167 label.setFont(Altos.label_font);
168 value.setFont(Altos.value_font);
169 max_value.setFont(Altos.value_font);
172 void show(AltosUnits units, double v) {
173 if (v == AltosRecord.MISSING) {
174 value.setText("Missing");
175 max_value.setText("Missing");
177 value.setText(units.show(8, v));
178 if (v > max || max == AltosRecord.MISSING) {
179 max_value.setText(units.show(8, v));
184 public AscentValueHold (GridBagLayout layout, int y, String text) {
185 GridBagConstraints c = new GridBagConstraints();
188 label = new JLabel(text);
189 label.setFont(Altos.label_font);
190 label.setHorizontalAlignment(SwingConstants.LEFT);
191 c.gridx = 1; c.gridy = y;
192 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
193 c.anchor = GridBagConstraints.WEST;
194 c.fill = GridBagConstraints.VERTICAL;
196 layout.setConstraints(label, c);
199 value = new JTextField(Altos.text_width);
200 value.setFont(Altos.value_font);
201 value.setHorizontalAlignment(SwingConstants.RIGHT);
202 c.gridx = 2; c.gridy = y;
203 c.anchor = GridBagConstraints.EAST;
204 c.fill = GridBagConstraints.BOTH;
206 layout.setConstraints(value, c);
209 max_value = new JTextField(Altos.text_width);
210 max_value.setFont(Altos.value_font);
211 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
212 c.gridx = 3; c.gridy = y;
213 c.anchor = GridBagConstraints.EAST;
214 c.fill = GridBagConstraints.BOTH;
216 layout.setConstraints(max_value, c);
222 class Height extends AscentValueHold {
223 void show (AltosState state, int crc_errors) {
224 show(AltosConvert.height, state.height);
226 public Height (GridBagLayout layout, int y) {
227 super (layout, y, "Height");
233 class Speed extends AscentValueHold {
234 void show (AltosState state, int crc_errors) {
235 double speed = state.speed;
237 speed = state.baro_speed;
238 show(AltosConvert.speed, speed);
240 public Speed (GridBagLayout layout, int y) {
241 super (layout, y, "Speed");
247 class Accel extends AscentValueHold {
248 void show (AltosState state, int crc_errors) {
249 show(AltosConvert.accel, state.acceleration);
251 public Accel (GridBagLayout layout, int y) {
252 super (layout, y, "Acceleration");
258 String pos(double p, String pos, String neg) {
264 int deg = (int) Math.floor(p);
265 double min = (p - Math.floor(p)) * 60.0;
266 return String.format("%s %4d° %9.6f", h, deg, min);
269 class Apogee extends AscentStatus {
270 void show (AltosState state, int crc_errors) {
272 value.setText(String.format("%4.2f V", state.drogue_sense));
273 lights.set(state.drogue_sense > 3.2);
275 public Apogee (GridBagLayout layout, int y) {
276 super(layout, y, "Apogee Igniter Voltage");
282 class Main extends AscentStatus {
283 void show (AltosState state, int crc_errors) {
285 value.setText(String.format("%4.2f V", state.main_sense));
286 lights.set(state.main_sense > 3.2);
288 public Main (GridBagLayout layout, int y) {
289 super(layout, y, "Main Igniter Voltage");
295 class Lat extends AscentValue {
296 void show (AltosState state, int crc_errors) {
298 if (state.gps != null)
299 value.setText(pos(state.gps.lat,"N", "S"));
301 value.setText("???");
303 public Lat (GridBagLayout layout, int y) {
304 super (layout, y, "Latitude");
310 class Lon extends AscentValue {
311 void show (AltosState state, int crc_errors) {
313 if (state.gps != null)
314 value.setText(pos(state.gps.lon,"E", "W"));
316 value.setText("???");
318 public Lon (GridBagLayout layout, int y) {
319 super (layout, y, "Longitude");
325 public void reset() {
335 public void set_font() {
336 cur.setFont(Altos.label_font);
337 max.setFont(Altos.label_font);
347 public void show(AltosState state, int crc_errors) {
348 if (state.gps != null && state.gps.connected) {
349 lat.show(state, crc_errors);
350 lon.show(state, crc_errors);
355 height.show(state, crc_errors);
356 if (state.main_sense != AltosRecord.MISSING)
357 main.show(state, crc_errors);
360 if (state.drogue_sense != AltosRecord.MISSING)
361 apogee.show(state, crc_errors);
364 speed.show(state, crc_errors);
365 accel.show(state, crc_errors);
368 public void labels(GridBagLayout layout, int y) {
369 GridBagConstraints c;
371 cur = new JLabel("Current");
372 cur.setFont(Altos.label_font);
373 c = new GridBagConstraints();
374 c.gridx = 2; c.gridy = y;
375 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
376 layout.setConstraints(cur, c);
379 max = new JLabel("Maximum");
380 max.setFont(Altos.label_font);
381 c.gridx = 3; c.gridy = y;
382 layout.setConstraints(max, c);
386 public AltosAscent() {
387 layout = new GridBagLayout();
391 /* Elements in ascent display:
398 height = new Height(layout, 1);
399 speed = new Speed(layout, 2);
400 accel = new Accel(layout, 3);
401 lat = new Lat(layout, 4);
402 lon = new Lon(layout, 5);
403 apogee = new Apogee(layout, 6);
404 main = new Main(layout, 7);