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.
22 import org.altusmetrum.altoslib_1.*;
24 public class AltosDescent extends JComponent implements AltosFlightDisplay {
27 public abstract class DescentStatus {
32 abstract void show(AltosState state, AltosListenerState listener_state);
35 label.setVisible(true);
36 value.setVisible(true);
37 lights.setVisible(true);
45 void show(String format, double value) {
46 show(String.format(format, value));
50 label.setVisible(false);
51 value.setVisible(false);
52 lights.setVisible(false);
61 label.setFont(Altos.label_font);
62 value.setFont(Altos.value_font);
65 public DescentStatus (GridBagLayout layout, int y, String text) {
66 GridBagConstraints c = new GridBagConstraints();
69 lights = new AltosLights();
70 c.gridx = 0; c.gridy = y;
71 c.anchor = GridBagConstraints.CENTER;
72 c.fill = GridBagConstraints.VERTICAL;
74 layout.setConstraints(lights, c);
77 label = new JLabel(text);
78 label.setFont(Altos.label_font);
79 label.setHorizontalAlignment(SwingConstants.LEFT);
80 c.gridx = 1; c.gridy = y;
81 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
82 c.anchor = GridBagConstraints.WEST;
83 c.fill = GridBagConstraints.VERTICAL;
86 layout.setConstraints(label, c);
89 value = new JTextField(Altos.text_width);
90 value.setFont(Altos.value_font);
91 value.setHorizontalAlignment(SwingConstants.RIGHT);
92 c.gridx = 4; c.gridy = y;
94 c.anchor = GridBagConstraints.WEST;
95 c.fill = GridBagConstraints.BOTH;
97 layout.setConstraints(value, c);
103 public abstract class DescentValue {
111 abstract void show(AltosState state, AltosListenerState listener_state);
114 label.setVisible(true);
115 value.setVisible(true);
119 label.setVisible(false);
120 value.setVisible(false);
123 void show(String v) {
128 void show(AltosUnits units, double v) {
129 show(units.show(8, v));
132 void show(String format, double v) {
133 show(String.format(format, v));
137 label.setFont(Altos.label_font);
138 value.setFont(Altos.value_font);
141 public DescentValue (GridBagLayout layout, int x, int y, String text) {
142 GridBagConstraints c = new GridBagConstraints();
145 label = new JLabel(text);
146 label.setFont(Altos.label_font);
147 label.setHorizontalAlignment(SwingConstants.LEFT);
148 c.gridx = x + 1; c.gridy = y;
149 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
150 c.anchor = GridBagConstraints.WEST;
151 c.fill = GridBagConstraints.VERTICAL;
155 value = new JTextField(Altos.text_width);
156 value.setFont(Altos.value_font);
157 value.setHorizontalAlignment(SwingConstants.RIGHT);
158 c.gridx = x + 2; c.gridy = y;
160 c.anchor = GridBagConstraints.WEST;
161 c.fill = GridBagConstraints.BOTH;
167 public abstract class DescentDualValue {
178 label.setVisible(true);
179 value1.setVisible(true);
180 value2.setVisible(true);
184 label.setVisible(false);
185 value1.setVisible(false);
186 value2.setVisible(false);
190 label.setFont(Altos.label_font);
191 value1.setFont(Altos.value_font);
192 value2.setFont(Altos.value_font);
195 abstract void show(AltosState state, AltosListenerState listener_state);
197 void show(String v1, String v2) {
202 void show(String f1, double v1, String f2, double v2) {
204 value1.setText(String.format(f1, v1));
205 value2.setText(String.format(f2, v2));
208 public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
209 GridBagConstraints c = new GridBagConstraints();
212 label = new JLabel(text);
213 label.setFont(Altos.label_font);
214 label.setHorizontalAlignment(SwingConstants.LEFT);
215 c.gridx = x + 1; c.gridy = y;
216 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
217 c.anchor = GridBagConstraints.WEST;
218 c.fill = GridBagConstraints.VERTICAL;
220 layout.setConstraints(label, c);
223 value1 = new JTextField(Altos.text_width);
224 value1.setFont(Altos.value_font);
225 value1.setHorizontalAlignment(SwingConstants.RIGHT);
226 c.gridx = x + 2; c.gridy = y;
227 c.anchor = GridBagConstraints.WEST;
228 c.fill = GridBagConstraints.BOTH;
230 layout.setConstraints(value1, c);
233 value2 = new JTextField(Altos.text_width);
234 value2.setFont(Altos.value_font);
235 value2.setHorizontalAlignment(SwingConstants.RIGHT);
236 c.gridx = x + 4; c.gridy = y;
237 c.anchor = GridBagConstraints.WEST;
238 c.fill = GridBagConstraints.BOTH;
241 layout.setConstraints(value2, c);
246 class Height extends DescentValue {
247 void show (AltosState state, AltosListenerState listener_state) {
248 show(AltosConvert.height, state.height);
250 public Height (GridBagLayout layout, int x, int y) {
251 super (layout, x, y, "Height");
257 class Speed extends DescentValue {
258 void show (AltosState state, AltosListenerState listener_state) {
259 double speed = state.accel_speed;
261 speed = state.baro_speed;
262 show(AltosConvert.speed, speed);
264 public Speed (GridBagLayout layout, int x, int y) {
265 super (layout, x, y, "Speed");
271 String pos(double p, String pos, String neg) {
277 int deg = (int) Math.floor(p);
278 double min = (p - Math.floor(p)) * 60.0;
279 return String.format("%s %d° %9.6f", h, deg, min);
282 class Lat extends DescentValue {
283 void show (AltosState state, AltosListenerState listener_state) {
284 if (state.gps != null && state.gps.connected)
285 show(pos(state.gps.lat,"N", "S"));
289 public Lat (GridBagLayout layout, int x, int y) {
290 super (layout, x, y, "Latitude");
296 class Lon extends DescentValue {
297 void show (AltosState state, AltosListenerState listener_state) {
298 if (state.gps != null && state.gps.connected)
299 show(pos(state.gps.lon,"W", "E"));
303 public Lon (GridBagLayout layout, int x, int y) {
304 super (layout, x, y, "Longitude");
310 class Distance extends DescentValue {
311 void show(AltosState state, AltosListenerState listener_state) {
312 if (state.from_pad != null)
313 show(AltosConvert.distance, state.from_pad.distance);
318 public Distance (GridBagLayout layout, int x, int y) {
319 super(layout, x, y, "Ground Distance");
326 class Apogee extends DescentStatus {
327 void show (AltosState state, AltosListenerState listener_state) {
328 show("%4.2f V", state.drogue_sense);
329 lights.set(state.drogue_sense > 3.2);
331 public Apogee (GridBagLayout layout, int y) {
332 super(layout, y, "Apogee Igniter Voltage");
338 class Main extends DescentStatus {
339 void show (AltosState state, AltosListenerState listener_state) {
340 show("%4.2f V", state.main_sense);
341 lights.set(state.main_sense > 3.2);
343 public Main (GridBagLayout layout, int y) {
344 super(layout, y, "Main Igniter Voltage");
350 class Bearing extends DescentDualValue {
351 void show (AltosState state, AltosListenerState listener_state) {
352 if (state.from_pad != null) {
353 show( String.format("%3.0f°", state.from_pad.bearing),
354 state.from_pad.bearing_words(
355 AltosGreatCircle.BEARING_LONG));
360 public Bearing (GridBagLayout layout, int x, int y) {
361 super (layout, x, y, "Bearing");
367 class Range extends DescentValue {
368 void show (AltosState state, AltosListenerState listener_state) {
369 show(AltosConvert.distance, state.range);
371 public Range (GridBagLayout layout, int x, int y) {
372 super (layout, x, y, "Range");
378 class Elevation extends DescentValue {
379 void show (AltosState state, AltosListenerState listener_state) {
380 show("%3.0f°", state.elevation);
382 public Elevation (GridBagLayout layout, int x, int y) {
383 super (layout, x, y, "Elevation");
389 public void reset() {
402 public void set_font() {
410 elevation.set_font();
415 public void show(AltosState state, AltosListenerState listener_state) {
416 height.show(state, listener_state);
417 speed.show(state, listener_state);
418 if (state.gps != null && state.gps.connected) {
419 bearing.show(state, listener_state);
420 range.show(state, listener_state);
421 distance.show(state, listener_state);
422 elevation.show(state, listener_state);
423 lat.show(state, listener_state);
424 lon.show(state, listener_state);
433 if (state.main_sense != AltosRecord.MISSING)
434 main.show(state, listener_state);
437 if (state.drogue_sense != AltosRecord.MISSING)
438 apogee.show(state, listener_state);
443 public String getName() {
447 public AltosDescent() {
448 layout = new GridBagLayout();
452 /* Elements in descent display */
453 speed = new Speed(layout, 0, 0);
454 height = new Height(layout, 2, 0);
455 elevation = new Elevation(layout, 0, 1);
456 range = new Range(layout, 2, 1);
457 bearing = new Bearing(layout, 0, 2);
458 distance = new Distance(layout, 0, 3);
459 lat = new Lat(layout, 0, 4);
460 lon = new Lon(layout, 2, 4);
462 apogee = new Apogee(layout, 5);
463 main = new Main(layout, 6);