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 {
34 public class AscentStatus {
40 value.setVisible(true);
41 lights.setVisible(true);
42 label.setVisible(true);
46 value.setVisible(false);
47 lights.setVisible(false);
48 label.setVisible(false);
51 void show(AltosState state, int crc_errors) {}
57 public AscentStatus (GridBagLayout layout, int y, String text) {
58 GridBagConstraints c = new GridBagConstraints();
61 lights = new AltosLights();
62 c.gridx = 0; c.gridy = y;
63 c.anchor = GridBagConstraints.CENTER;
64 c.fill = GridBagConstraints.VERTICAL;
66 layout.setConstraints(lights, c);
69 label = new JLabel(text);
70 label.setFont(Altos.label_font);
71 label.setHorizontalAlignment(SwingConstants.LEFT);
72 c.gridx = 1; c.gridy = y;
73 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
74 c.anchor = GridBagConstraints.WEST;
75 c.fill = GridBagConstraints.VERTICAL;
77 layout.setConstraints(label, c);
80 value = new JTextField(Altos.text_width);
81 value.setFont(Altos.value_font);
82 value.setHorizontalAlignment(SwingConstants.RIGHT);
83 c.gridx = 2; c.gridy = y;
85 c.anchor = GridBagConstraints.WEST;
86 c.fill = GridBagConstraints.BOTH;
88 layout.setConstraints(value, c);
94 public class AscentValue {
97 void show(AltosState state, int crc_errors) {}
104 label.setVisible(true);
105 value.setVisible(true);
109 label.setVisible(false);
110 value.setVisible(false);
112 public AscentValue (GridBagLayout layout, int y, String text) {
113 GridBagConstraints c = new GridBagConstraints();
116 label = new JLabel(text);
117 label.setFont(Altos.label_font);
118 label.setHorizontalAlignment(SwingConstants.LEFT);
119 c.gridx = 1; c.gridy = y;
120 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
121 c.anchor = GridBagConstraints.WEST;
122 c.fill = GridBagConstraints.VERTICAL;
124 layout.setConstraints(label, c);
127 value = new JTextField(Altos.text_width);
128 value.setFont(Altos.value_font);
129 value.setHorizontalAlignment(SwingConstants.RIGHT);
130 c.gridx = 2; c.gridy = y;
131 c.anchor = GridBagConstraints.WEST;
132 c.fill = GridBagConstraints.BOTH;
135 layout.setConstraints(value, c);
140 public class AscentValueHold {
143 JTextField max_value;
146 void show(AltosState state, int crc_errors) {}
150 max_value.setText("");
151 max = AltosRecord.MISSING;
154 void show(String format, double v) {
155 if (v == AltosRecord.MISSING) {
156 value.setText("Missing");
157 max_value.setText("Missing");
159 value.setText(String.format(format, v));
160 if (v > max || max == AltosRecord.MISSING) {
161 max_value.setText(String.format(format, v));
166 public AscentValueHold (GridBagLayout layout, int y, String text) {
167 GridBagConstraints c = new GridBagConstraints();
170 label = new JLabel(text);
171 label.setFont(Altos.label_font);
172 label.setHorizontalAlignment(SwingConstants.LEFT);
173 c.gridx = 1; c.gridy = y;
174 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
175 c.anchor = GridBagConstraints.WEST;
176 c.fill = GridBagConstraints.VERTICAL;
178 layout.setConstraints(label, c);
181 value = new JTextField(Altos.text_width);
182 value.setFont(Altos.value_font);
183 value.setHorizontalAlignment(SwingConstants.RIGHT);
184 c.gridx = 2; c.gridy = y;
185 c.anchor = GridBagConstraints.EAST;
186 c.fill = GridBagConstraints.BOTH;
188 layout.setConstraints(value, c);
191 max_value = new JTextField(Altos.text_width);
192 max_value.setFont(Altos.value_font);
193 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
194 c.gridx = 3; c.gridy = y;
195 c.anchor = GridBagConstraints.EAST;
196 c.fill = GridBagConstraints.BOTH;
198 layout.setConstraints(max_value, c);
204 class Height extends AscentValueHold {
205 void show (AltosState state, int crc_errors) {
206 show("%6.0f m", state.height);
208 public Height (GridBagLayout layout, int y) {
209 super (layout, y, "Height");
215 class Speed extends AscentValueHold {
216 void show (AltosState state, int crc_errors) {
217 double speed = state.speed;
219 speed = state.baro_speed;
220 show("%6.0f m/s", speed);
222 public Speed (GridBagLayout layout, int y) {
223 super (layout, y, "Speed");
229 class Accel extends AscentValueHold {
230 void show (AltosState state, int crc_errors) {
231 show("%6.0f m/s²", state.acceleration);
233 public Accel (GridBagLayout layout, int y) {
234 super (layout, y, "Acceleration");
240 String pos(double p, String pos, String neg) {
246 int deg = (int) Math.floor(p);
247 double min = (p - Math.floor(p)) * 60.0;
248 return String.format("%s %4d° %9.6f", h, deg, min);
251 class Apogee extends AscentStatus {
252 void show (AltosState state, int crc_errors) {
254 value.setText(String.format("%4.2f V", state.drogue_sense));
255 lights.set(state.drogue_sense > 3.2);
257 public Apogee (GridBagLayout layout, int y) {
258 super(layout, y, "Apogee Igniter Voltage");
264 class Main extends AscentStatus {
265 void show (AltosState state, int crc_errors) {
267 value.setText(String.format("%4.2f V", state.main_sense));
268 lights.set(state.main_sense > 3.2);
270 public Main (GridBagLayout layout, int y) {
271 super(layout, y, "Main Igniter Voltage");
277 class Lat extends AscentValue {
278 void show (AltosState state, int crc_errors) {
280 if (state.gps != null)
281 value.setText(pos(state.gps.lat,"N", "S"));
283 value.setText("???");
285 public Lat (GridBagLayout layout, int y) {
286 super (layout, y, "Latitude");
292 class Lon extends AscentValue {
293 void show (AltosState state, int crc_errors) {
295 if (state.gps != null)
296 value.setText(pos(state.gps.lon,"E", "W"));
298 value.setText("???");
300 public Lon (GridBagLayout layout, int y) {
301 super (layout, y, "Longitude");
307 public void reset() {
317 public void show(AltosState state, int crc_errors) {
318 if (state.gps != null && state.gps.connected) {
319 lat.show(state, crc_errors);
320 lon.show(state, crc_errors);
325 height.show(state, crc_errors);
326 if (state.main_sense != AltosRecord.MISSING)
327 main.show(state, crc_errors);
330 if (state.drogue_sense != AltosRecord.MISSING)
331 apogee.show(state, crc_errors);
334 speed.show(state, crc_errors);
335 accel.show(state, crc_errors);
338 public void labels(GridBagLayout layout, int y) {
339 GridBagConstraints c;
342 cur = new JLabel("Current");
343 cur.setFont(Altos.label_font);
344 c = new GridBagConstraints();
345 c.gridx = 2; c.gridy = y;
346 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
347 layout.setConstraints(cur, c);
350 max = new JLabel("Maximum");
351 max.setFont(Altos.label_font);
352 c.gridx = 3; c.gridy = y;
353 layout.setConstraints(max, c);
357 public AltosAscent() {
358 layout = new GridBagLayout();
362 /* Elements in ascent display:
369 height = new Height(layout, 1);
370 speed = new Speed(layout, 2);
371 accel = new Accel(layout, 3);
372 lat = new Lat(layout, 4);
373 lon = new Lon(layout, 5);
374 apogee = new Apogee(layout, 6);
375 main = new Main(layout, 7);