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);
59 label.setFont(Altos.label_font);
60 value.setFont(Altos.value_font);
63 public DescentStatus (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;
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 = 4; c.gridy = y;
92 c.anchor = GridBagConstraints.WEST;
93 c.fill = GridBagConstraints.BOTH;
95 layout.setConstraints(value, c);
101 public abstract class DescentValue {
109 abstract void show(AltosState state, int crc_errors);
112 label.setVisible(true);
113 value.setVisible(true);
117 label.setVisible(false);
118 value.setVisible(false);
121 void show(String format, double v) {
122 value.setText(String.format(format, v));
125 void show(String v) {
130 label.setFont(Altos.label_font);
131 value.setFont(Altos.value_font);
134 public DescentValue (GridBagLayout layout, int x, int y, String text) {
135 GridBagConstraints c = new GridBagConstraints();
138 label = new JLabel(text);
139 label.setFont(Altos.label_font);
140 label.setHorizontalAlignment(SwingConstants.LEFT);
141 c.gridx = x + 1; c.gridy = y;
142 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
143 c.anchor = GridBagConstraints.WEST;
144 c.fill = GridBagConstraints.VERTICAL;
148 value = new JTextField(Altos.text_width);
149 value.setFont(Altos.value_font);
150 value.setHorizontalAlignment(SwingConstants.RIGHT);
151 c.gridx = x + 2; c.gridy = y;
153 c.anchor = GridBagConstraints.WEST;
154 c.fill = GridBagConstraints.BOTH;
160 public abstract class DescentDualValue {
171 label.setVisible(true);
172 value1.setVisible(true);
173 value2.setVisible(true);
177 label.setVisible(false);
178 value1.setVisible(false);
179 value2.setVisible(false);
183 label.setFont(Altos.label_font);
184 value1.setFont(Altos.value_font);
185 value2.setFont(Altos.value_font);
188 abstract void show(AltosState state, int crc_errors);
190 void show(String v1, String v2) {
195 void show(String f1, double v1, String f2, double v2) {
197 value1.setText(String.format(f1, v1));
198 value2.setText(String.format(f2, v2));
201 public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
202 GridBagConstraints c = new GridBagConstraints();
205 label = new JLabel(text);
206 label.setFont(Altos.label_font);
207 label.setHorizontalAlignment(SwingConstants.LEFT);
208 c.gridx = x + 1; c.gridy = y;
209 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
210 c.anchor = GridBagConstraints.WEST;
211 c.fill = GridBagConstraints.VERTICAL;
213 layout.setConstraints(label, c);
216 value1 = new JTextField(Altos.text_width);
217 value1.setFont(Altos.value_font);
218 value1.setHorizontalAlignment(SwingConstants.RIGHT);
219 c.gridx = x + 2; c.gridy = y;
220 c.anchor = GridBagConstraints.WEST;
221 c.fill = GridBagConstraints.BOTH;
223 layout.setConstraints(value1, c);
226 value2 = new JTextField(Altos.text_width);
227 value2.setFont(Altos.value_font);
228 value2.setHorizontalAlignment(SwingConstants.RIGHT);
229 c.gridx = x + 4; c.gridy = y;
230 c.anchor = GridBagConstraints.WEST;
231 c.fill = GridBagConstraints.BOTH;
234 layout.setConstraints(value2, c);
239 class Height extends DescentValue {
240 void show (AltosState state, int crc_errors) {
241 show("%6.0f m", state.height);
243 public Height (GridBagLayout layout, int x, int y) {
244 super (layout, x, y, "Height");
250 class Speed extends DescentValue {
251 void show (AltosState state, int crc_errors) {
252 double speed = state.speed;
254 speed = state.baro_speed;
255 show("%6.0f m/s", speed);
257 public Speed (GridBagLayout layout, int x, int y) {
258 super (layout, x, y, "Speed");
264 String pos(double p, String pos, String neg) {
270 int deg = (int) Math.floor(p);
271 double min = (p - Math.floor(p)) * 60.0;
272 return String.format("%s %d° %9.6f", h, deg, min);
275 class Lat extends DescentValue {
276 void show (AltosState state, int crc_errors) {
277 if (state.gps != null && state.gps.connected)
278 show(pos(state.gps.lat,"N", "S"));
282 public Lat (GridBagLayout layout, int x, int y) {
283 super (layout, x, y, "Latitude");
289 class Lon extends DescentValue {
290 void show (AltosState state, int crc_errors) {
291 if (state.gps != null && state.gps.connected)
292 show(pos(state.gps.lon,"W", "E"));
296 public Lon (GridBagLayout layout, int x, int y) {
297 super (layout, x, y, "Longitude");
303 class Apogee extends DescentStatus {
304 void show (AltosState state, int crc_errors) {
306 value.setText(String.format("%4.2f V", state.drogue_sense));
307 lights.set(state.drogue_sense > 3.2);
309 public Apogee (GridBagLayout layout, int y) {
310 super(layout, y, "Apogee Igniter Voltage");
316 class Main extends DescentStatus {
317 void show (AltosState state, int crc_errors) {
319 value.setText(String.format("%4.2f V", state.main_sense));
320 lights.set(state.main_sense > 3.2);
322 public Main (GridBagLayout layout, int y) {
323 super(layout, y, "Main Igniter Voltage");
329 class Bearing extends DescentDualValue {
330 void show (AltosState state, int crc_errors) {
331 if (state.from_pad != null) {
332 show( String.format("%3.0f°", state.from_pad.bearing),
333 state.from_pad.bearing_words(
334 AltosGreatCircle.BEARING_LONG));
339 public Bearing (GridBagLayout layout, int x, int y) {
340 super (layout, x, y, "Bearing");
346 class Range extends DescentValue {
347 void show (AltosState state, int crc_errors) {
348 show("%6.0f m", state.range);
350 public Range (GridBagLayout layout, int x, int y) {
351 super (layout, x, y, "Range");
357 class Elevation extends DescentValue {
358 void show (AltosState state, int crc_errors) {
359 show("%3.0f°", state.elevation);
361 public Elevation (GridBagLayout layout, int x, int y) {
362 super (layout, x, y, "Elevation");
368 public void reset() {
380 public void set_font() {
387 elevation.set_font();
392 public void show(AltosState state, int crc_errors) {
393 height.show(state, crc_errors);
394 speed.show(state, crc_errors);
395 if (state.gps != null && state.gps.connected) {
396 bearing.show(state, crc_errors);
397 range.show(state, crc_errors);
398 elevation.show(state, crc_errors);
399 lat.show(state, crc_errors);
400 lon.show(state, crc_errors);
408 if (state.main_sense != AltosRecord.MISSING)
409 main.show(state, crc_errors);
412 if (state.drogue_sense != AltosRecord.MISSING)
413 apogee.show(state, crc_errors);
418 public AltosDescent() {
419 layout = new GridBagLayout();
423 /* Elements in descent display */
424 speed = new Speed(layout, 0, 0);
425 height = new Height(layout, 2, 0);
426 elevation = new Elevation(layout, 0, 1);
427 range = new Range(layout, 2, 1);
428 bearing = new Bearing(layout, 0, 2);
429 lat = new Lat(layout, 0, 3);
430 lon = new Lon(layout, 2, 3);
432 apogee = new Apogee(layout, 4);
433 main = new Main(layout, 5);