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;
31 public class AltosAscent extends JComponent implements AltosFlightDisplay {
35 public class AscentStatus {
41 value.setVisible(true);
42 lights.setVisible(true);
43 label.setVisible(true);
47 value.setVisible(false);
48 lights.setVisible(false);
49 label.setVisible(false);
52 void show(AltosState state, int crc_errors) {}
59 label.setFont(Altos.label_font);
60 value.setFont(Altos.value_font);
63 public AscentStatus (GridBagLayout layout, int y, String text) {
64 GridBagConstraints c = new GridBagConstraints();
67 lights = new AltosLights();
68 c.gridx = 0; c.gridy = y;
69 c.anchor = GridBagConstraints.CENTER;
70 c.fill = GridBagConstraints.VERTICAL;
72 layout.setConstraints(lights, c);
75 label = new JLabel(text);
76 label.setFont(Altos.label_font);
77 label.setHorizontalAlignment(SwingConstants.LEFT);
78 c.gridx = 1; c.gridy = y;
79 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
80 c.anchor = GridBagConstraints.WEST;
81 c.fill = GridBagConstraints.VERTICAL;
83 layout.setConstraints(label, c);
86 value = new JTextField(Altos.text_width);
87 value.setFont(Altos.value_font);
88 value.setHorizontalAlignment(SwingConstants.RIGHT);
89 c.gridx = 2; c.gridy = y;
91 c.anchor = GridBagConstraints.WEST;
92 c.fill = GridBagConstraints.BOTH;
94 layout.setConstraints(value, c);
100 public class AscentValue {
103 void show(AltosState state, int crc_errors) {}
110 label.setVisible(true);
111 value.setVisible(true);
115 label.setVisible(false);
116 value.setVisible(false);
119 label.setFont(Altos.label_font);
120 value.setFont(Altos.value_font);
123 public AscentValue (GridBagLayout layout, int y, String text) {
124 GridBagConstraints c = new GridBagConstraints();
127 label = new JLabel(text);
128 label.setFont(Altos.label_font);
129 label.setHorizontalAlignment(SwingConstants.LEFT);
130 c.gridx = 1; c.gridy = y;
131 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
132 c.anchor = GridBagConstraints.WEST;
133 c.fill = GridBagConstraints.VERTICAL;
135 layout.setConstraints(label, c);
138 value = new JTextField(Altos.text_width);
139 value.setFont(Altos.value_font);
140 value.setHorizontalAlignment(SwingConstants.RIGHT);
141 c.gridx = 2; c.gridy = y;
142 c.anchor = GridBagConstraints.WEST;
143 c.fill = GridBagConstraints.BOTH;
146 layout.setConstraints(value, c);
151 public class AscentValueHold {
154 JTextField max_value;
157 void show(AltosState state, int crc_errors) {}
161 max_value.setText("");
162 max = AltosRecord.MISSING;
166 label.setFont(Altos.label_font);
167 value.setFont(Altos.value_font);
168 max_value.setFont(Altos.value_font);
171 void show(String format, double v) {
172 if (v == AltosRecord.MISSING) {
173 value.setText("Missing");
174 max_value.setText("Missing");
176 value.setText(String.format(format, v));
177 if (v > max || max == AltosRecord.MISSING) {
178 max_value.setText(String.format(format, v));
183 public AscentValueHold (GridBagLayout layout, int y, String text) {
184 GridBagConstraints c = new GridBagConstraints();
187 label = new JLabel(text);
188 label.setFont(Altos.label_font);
189 label.setHorizontalAlignment(SwingConstants.LEFT);
190 c.gridx = 1; c.gridy = y;
191 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
192 c.anchor = GridBagConstraints.WEST;
193 c.fill = GridBagConstraints.VERTICAL;
195 layout.setConstraints(label, c);
198 value = new JTextField(Altos.text_width);
199 value.setFont(Altos.value_font);
200 value.setHorizontalAlignment(SwingConstants.RIGHT);
201 c.gridx = 2; c.gridy = y;
202 c.anchor = GridBagConstraints.EAST;
203 c.fill = GridBagConstraints.BOTH;
205 layout.setConstraints(value, c);
208 max_value = new JTextField(Altos.text_width);
209 max_value.setFont(Altos.value_font);
210 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
211 c.gridx = 3; c.gridy = y;
212 c.anchor = GridBagConstraints.EAST;
213 c.fill = GridBagConstraints.BOTH;
215 layout.setConstraints(max_value, c);
221 class Height extends AscentValueHold {
222 void show (AltosState state, int crc_errors) {
223 show("%6.0f m", state.height);
225 public Height (GridBagLayout layout, int y) {
226 super (layout, y, "Height");
232 class Speed extends AscentValueHold {
233 void show (AltosState state, int crc_errors) {
234 double speed = state.speed;
236 speed = state.baro_speed;
237 show("%6.0f m/s", speed);
239 public Speed (GridBagLayout layout, int y) {
240 super (layout, y, "Speed");
246 class Accel extends AscentValueHold {
247 void show (AltosState state, int crc_errors) {
248 show("%6.0f m/s²", state.acceleration);
250 public Accel (GridBagLayout layout, int y) {
251 super (layout, y, "Acceleration");
257 String pos(double p, String pos, String neg) {
263 int deg = (int) Math.floor(p);
264 double min = (p - Math.floor(p)) * 60.0;
265 return String.format("%s %4d° %9.6f", h, deg, min);
268 class Apogee extends AscentStatus {
269 void show (AltosState state, int crc_errors) {
271 value.setText(String.format("%4.2f V", state.drogue_sense));
272 lights.set(state.drogue_sense > 3.2);
274 public Apogee (GridBagLayout layout, int y) {
275 super(layout, y, "Apogee Igniter Voltage");
281 class Main extends AscentStatus {
282 void show (AltosState state, int crc_errors) {
284 value.setText(String.format("%4.2f V", state.main_sense));
285 lights.set(state.main_sense > 3.2);
287 public Main (GridBagLayout layout, int y) {
288 super(layout, y, "Main Igniter Voltage");
294 class Lat extends AscentValue {
295 void show (AltosState state, int crc_errors) {
297 if (state.gps != null)
298 value.setText(pos(state.gps.lat,"N", "S"));
300 value.setText("???");
302 public Lat (GridBagLayout layout, int y) {
303 super (layout, y, "Latitude");
309 class Lon extends AscentValue {
310 void show (AltosState state, int crc_errors) {
312 if (state.gps != null)
313 value.setText(pos(state.gps.lon,"E", "W"));
315 value.setText("???");
317 public Lon (GridBagLayout layout, int y) {
318 super (layout, y, "Longitude");
324 public void reset() {
334 public void set_font() {
335 cur.setFont(Altos.label_font);
336 max.setFont(Altos.label_font);
346 public void show(AltosState state, int crc_errors) {
347 if (state.gps != null && state.gps.connected) {
348 lat.show(state, crc_errors);
349 lon.show(state, crc_errors);
354 height.show(state, crc_errors);
355 if (state.main_sense != AltosRecord.MISSING)
356 main.show(state, crc_errors);
359 if (state.drogue_sense != AltosRecord.MISSING)
360 apogee.show(state, crc_errors);
363 speed.show(state, crc_errors);
364 accel.show(state, crc_errors);
367 public void labels(GridBagLayout layout, int y) {
368 GridBagConstraints c;
370 cur = new JLabel("Current");
371 cur.setFont(Altos.label_font);
372 c = new GridBagConstraints();
373 c.gridx = 2; c.gridy = y;
374 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
375 layout.setConstraints(cur, c);
378 max = new JLabel("Maximum");
379 max.setFont(Altos.label_font);
380 c.gridx = 3; c.gridy = y;
381 layout.setConstraints(max, c);
385 public AltosAscent() {
386 layout = new GridBagLayout();
390 /* Elements in ascent display:
397 height = new Height(layout, 1);
398 speed = new Speed(layout, 2);
399 accel = new Accel(layout, 3);
400 lat = new Lat(layout, 4);
401 lon = new Lon(layout, 5);
402 apogee = new Apogee(layout, 6);
403 main = new Main(layout, 7);