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 AltosDescent extends JComponent implements AltosFlightDisplay {
34 public abstract class DescentStatus {
39 abstract void show(AltosState state, int crc_errors);
42 label.setVisible(true);
43 value.setVisible(true);
44 lights.setVisible(true);
48 label.setVisible(false);
49 value.setVisible(false);
50 lights.setVisible(false);
58 public DescentStatus (GridBagLayout layout, int y, String text) {
59 GridBagConstraints c = new GridBagConstraints();
62 lights = new AltosLights();
63 c.gridx = 0; c.gridy = y;
64 c.anchor = GridBagConstraints.CENTER;
65 c.fill = GridBagConstraints.VERTICAL;
67 layout.setConstraints(lights, c);
70 label = new JLabel(text);
71 label.setFont(Altos.label_font);
72 label.setHorizontalAlignment(SwingConstants.LEFT);
73 c.gridx = 1; c.gridy = y;
74 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
75 c.anchor = GridBagConstraints.WEST;
76 c.fill = GridBagConstraints.VERTICAL;
79 layout.setConstraints(label, c);
82 value = new JTextField(Altos.text_width);
83 value.setFont(Altos.value_font);
84 value.setHorizontalAlignment(SwingConstants.RIGHT);
85 c.gridx = 4; c.gridy = y;
87 c.anchor = GridBagConstraints.WEST;
88 c.fill = GridBagConstraints.BOTH;
90 layout.setConstraints(value, c);
96 public abstract class DescentValue {
104 abstract void show(AltosState state, int crc_errors);
107 label.setVisible(true);
108 value.setVisible(true);
112 label.setVisible(false);
113 value.setVisible(false);
116 void show(String format, double v) {
117 value.setText(String.format(format, v));
120 void show(String v) {
124 public DescentValue (GridBagLayout layout, int x, 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 = x + 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;
138 value = new JTextField(Altos.text_width);
139 value.setFont(Altos.value_font);
140 value.setHorizontalAlignment(SwingConstants.RIGHT);
141 c.gridx = x + 2; c.gridy = y;
143 c.anchor = GridBagConstraints.WEST;
144 c.fill = GridBagConstraints.BOTH;
150 public abstract class DescentDualValue {
161 label.setVisible(true);
162 value1.setVisible(true);
163 value2.setVisible(true);
167 label.setVisible(false);
168 value1.setVisible(false);
169 value2.setVisible(false);
172 abstract void show(AltosState state, int crc_errors);
174 void show(String v1, String v2) {
179 void show(String f1, double v1, String f2, double v2) {
181 value1.setText(String.format(f1, v1));
182 value2.setText(String.format(f2, v2));
185 public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
186 GridBagConstraints c = new GridBagConstraints();
189 label = new JLabel(text);
190 label.setFont(Altos.label_font);
191 label.setHorizontalAlignment(SwingConstants.LEFT);
192 c.gridx = x + 1; c.gridy = y;
193 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
194 c.anchor = GridBagConstraints.WEST;
195 c.fill = GridBagConstraints.VERTICAL;
197 layout.setConstraints(label, c);
200 value1 = new JTextField(Altos.text_width);
201 value1.setFont(Altos.value_font);
202 value1.setHorizontalAlignment(SwingConstants.RIGHT);
203 c.gridx = x + 2; c.gridy = y;
204 c.anchor = GridBagConstraints.WEST;
205 c.fill = GridBagConstraints.BOTH;
207 layout.setConstraints(value1, c);
210 value2 = new JTextField(Altos.text_width);
211 value2.setFont(Altos.value_font);
212 value2.setHorizontalAlignment(SwingConstants.RIGHT);
213 c.gridx = x + 4; c.gridy = y;
214 c.anchor = GridBagConstraints.WEST;
215 c.fill = GridBagConstraints.BOTH;
218 layout.setConstraints(value2, c);
223 class Height extends DescentValue {
224 void show (AltosState state, int crc_errors) {
225 show("%6.0f m", state.height);
227 public Height (GridBagLayout layout, int x, int y) {
228 super (layout, x, y, "Height");
234 class Speed extends DescentValue {
235 void show (AltosState state, int crc_errors) {
236 double speed = state.speed;
238 speed = state.baro_speed;
239 show("%6.0f m/s", speed);
241 public Speed (GridBagLayout layout, int x, int y) {
242 super (layout, x, y, "Speed");
248 String pos(double p, String pos, String neg) {
254 int deg = (int) Math.floor(p);
255 double min = (p - Math.floor(p)) * 60.0;
256 return String.format("%s %d° %9.6f", h, deg, min);
259 class Lat extends DescentValue {
260 void show (AltosState state, int crc_errors) {
261 if (state.gps != null && state.gps.connected)
262 show(pos(state.gps.lat,"N", "S"));
266 public Lat (GridBagLayout layout, int x, int y) {
267 super (layout, x, y, "Latitude");
273 class Lon extends DescentValue {
274 void show (AltosState state, int crc_errors) {
275 if (state.gps != null && state.gps.connected)
276 show(pos(state.gps.lon,"W", "E"));
280 public Lon (GridBagLayout layout, int x, int y) {
281 super (layout, x, y, "Longitude");
287 class Apogee extends DescentStatus {
288 void show (AltosState state, int crc_errors) {
290 value.setText(String.format("%4.2f V", state.drogue_sense));
291 lights.set(state.drogue_sense > 3.2);
293 public Apogee (GridBagLayout layout, int y) {
294 super(layout, y, "Apogee Igniter Voltage");
300 class Main extends DescentStatus {
301 void show (AltosState state, int crc_errors) {
303 value.setText(String.format("%4.2f V", state.main_sense));
304 lights.set(state.main_sense > 3.2);
306 public Main (GridBagLayout layout, int y) {
307 super(layout, y, "Main Igniter Voltage");
313 class Bearing extends DescentDualValue {
314 void show (AltosState state, int crc_errors) {
315 if (state.from_pad != null) {
316 show( String.format("%3.0f°", state.from_pad.bearing),
317 state.from_pad.bearing_words(
318 AltosGreatCircle.BEARING_LONG));
323 public Bearing (GridBagLayout layout, int x, int y) {
324 super (layout, x, y, "Bearing");
330 class Range extends DescentValue {
331 void show (AltosState state, int crc_errors) {
332 show("%6.0f m", state.range);
334 public Range (GridBagLayout layout, int x, int y) {
335 super (layout, x, y, "Range");
341 class Elevation extends DescentValue {
342 void show (AltosState state, int crc_errors) {
343 show("%3.0f°", state.elevation);
345 public Elevation (GridBagLayout layout, int x, int y) {
346 super (layout, x, y, "Elevation");
352 public void reset() {
364 public void show(AltosState state, int crc_errors) {
365 height.show(state, crc_errors);
366 speed.show(state, crc_errors);
367 if (state.gps != null && state.gps.connected) {
368 bearing.show(state, crc_errors);
369 range.show(state, crc_errors);
370 elevation.show(state, crc_errors);
371 lat.show(state, crc_errors);
372 lon.show(state, crc_errors);
380 if (state.main_sense != AltosRecord.MISSING)
381 main.show(state, crc_errors);
384 if (state.drogue_sense != AltosRecord.MISSING)
385 apogee.show(state, crc_errors);
390 public AltosDescent() {
391 layout = new GridBagLayout();
395 /* Elements in descent display */
396 speed = new Speed(layout, 0, 0);
397 height = new Height(layout, 2, 0);
398 elevation = new Elevation(layout, 0, 1);
399 range = new Range(layout, 2, 1);
400 bearing = new Bearing(layout, 0, 2);
401 lat = new Lat(layout, 0, 3);
402 lon = new Lon(layout, 2, 3);
404 apogee = new Apogee(layout, 4);
405 main = new Main(layout, 5);