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.*;
24 public class AltosDescent extends JComponent implements AltosFlightDisplay {
27 public abstract class DescentStatus {
32 abstract void show(AltosState state, int crc_errors);
35 label.setVisible(true);
36 value.setVisible(true);
37 lights.setVisible(true);
41 label.setVisible(false);
42 value.setVisible(false);
43 lights.setVisible(false);
52 label.setFont(Altos.label_font);
53 value.setFont(Altos.value_font);
56 public DescentStatus (GridBagLayout layout, int y, String text) {
57 GridBagConstraints c = new GridBagConstraints();
60 lights = new AltosLights();
61 c.gridx = 0; c.gridy = y;
62 c.anchor = GridBagConstraints.CENTER;
63 c.fill = GridBagConstraints.VERTICAL;
65 layout.setConstraints(lights, c);
68 label = new JLabel(text);
69 label.setFont(Altos.label_font);
70 label.setHorizontalAlignment(SwingConstants.LEFT);
71 c.gridx = 1; c.gridy = y;
72 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
73 c.anchor = GridBagConstraints.WEST;
74 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 = 4; c.gridy = y;
85 c.anchor = GridBagConstraints.WEST;
86 c.fill = GridBagConstraints.BOTH;
88 layout.setConstraints(value, c);
94 public abstract class DescentValue {
102 abstract void show(AltosState state, int crc_errors);
105 label.setVisible(true);
106 value.setVisible(true);
110 label.setVisible(false);
111 value.setVisible(false);
114 void show(AltosUnits units, double v) {
115 value.setText(units.show(8, v));
118 void show(String format, double v) {
119 value.setText(String.format(format, v));
122 void show(String v) {
127 label.setFont(Altos.label_font);
128 value.setFont(Altos.value_font);
131 public DescentValue (GridBagLayout layout, int x, int y, String text) {
132 GridBagConstraints c = new GridBagConstraints();
135 label = new JLabel(text);
136 label.setFont(Altos.label_font);
137 label.setHorizontalAlignment(SwingConstants.LEFT);
138 c.gridx = x + 1; c.gridy = y;
139 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
140 c.anchor = GridBagConstraints.WEST;
141 c.fill = GridBagConstraints.VERTICAL;
145 value = new JTextField(Altos.text_width);
146 value.setFont(Altos.value_font);
147 value.setHorizontalAlignment(SwingConstants.RIGHT);
148 c.gridx = x + 2; c.gridy = y;
150 c.anchor = GridBagConstraints.WEST;
151 c.fill = GridBagConstraints.BOTH;
157 public abstract class DescentDualValue {
168 label.setVisible(true);
169 value1.setVisible(true);
170 value2.setVisible(true);
174 label.setVisible(false);
175 value1.setVisible(false);
176 value2.setVisible(false);
180 label.setFont(Altos.label_font);
181 value1.setFont(Altos.value_font);
182 value2.setFont(Altos.value_font);
185 abstract void show(AltosState state, int crc_errors);
187 void show(String v1, String v2) {
192 void show(String f1, double v1, String f2, double v2) {
194 value1.setText(String.format(f1, v1));
195 value2.setText(String.format(f2, v2));
198 public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
199 GridBagConstraints c = new GridBagConstraints();
202 label = new JLabel(text);
203 label.setFont(Altos.label_font);
204 label.setHorizontalAlignment(SwingConstants.LEFT);
205 c.gridx = x + 1; c.gridy = y;
206 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
207 c.anchor = GridBagConstraints.WEST;
208 c.fill = GridBagConstraints.VERTICAL;
210 layout.setConstraints(label, c);
213 value1 = new JTextField(Altos.text_width);
214 value1.setFont(Altos.value_font);
215 value1.setHorizontalAlignment(SwingConstants.RIGHT);
216 c.gridx = x + 2; c.gridy = y;
217 c.anchor = GridBagConstraints.WEST;
218 c.fill = GridBagConstraints.BOTH;
220 layout.setConstraints(value1, c);
223 value2 = new JTextField(Altos.text_width);
224 value2.setFont(Altos.value_font);
225 value2.setHorizontalAlignment(SwingConstants.RIGHT);
226 c.gridx = x + 4; c.gridy = y;
227 c.anchor = GridBagConstraints.WEST;
228 c.fill = GridBagConstraints.BOTH;
231 layout.setConstraints(value2, c);
236 class Height extends DescentValue {
237 void show (AltosState state, int crc_errors) {
238 show(AltosConvert.height, state.height);
240 public Height (GridBagLayout layout, int x, int y) {
241 super (layout, x, y, "Height");
247 class Speed extends DescentValue {
248 void show (AltosState state, int crc_errors) {
249 double speed = state.speed;
251 speed = state.baro_speed;
252 show(AltosConvert.speed, speed);
254 public Speed (GridBagLayout layout, int x, int y) {
255 super (layout, x, y, "Speed");
261 String pos(double p, String pos, String neg) {
267 int deg = (int) Math.floor(p);
268 double min = (p - Math.floor(p)) * 60.0;
269 return String.format("%s %d° %9.6f", h, deg, min);
272 class Lat extends DescentValue {
273 void show (AltosState state, int crc_errors) {
274 if (state.gps != null && state.gps.connected)
275 show(pos(state.gps.lat,"N", "S"));
279 public Lat (GridBagLayout layout, int x, int y) {
280 super (layout, x, y, "Latitude");
286 class Lon extends DescentValue {
287 void show (AltosState state, int crc_errors) {
288 if (state.gps != null && state.gps.connected)
289 show(pos(state.gps.lon,"W", "E"));
293 public Lon (GridBagLayout layout, int x, int y) {
294 super (layout, x, y, "Longitude");
300 class Apogee extends DescentStatus {
301 void show (AltosState state, int crc_errors) {
303 value.setText(String.format("%4.2f V", state.drogue_sense));
304 lights.set(state.drogue_sense > 3.2);
306 public Apogee (GridBagLayout layout, int y) {
307 super(layout, y, "Apogee Igniter Voltage");
313 class Main extends DescentStatus {
314 void show (AltosState state, int crc_errors) {
316 value.setText(String.format("%4.2f V", state.main_sense));
317 lights.set(state.main_sense > 3.2);
319 public Main (GridBagLayout layout, int y) {
320 super(layout, y, "Main Igniter Voltage");
326 class Bearing extends DescentDualValue {
327 void show (AltosState state, int crc_errors) {
328 if (state.from_pad != null) {
329 show( String.format("%3.0f°", state.from_pad.bearing),
330 state.from_pad.bearing_words(
331 AltosGreatCircle.BEARING_LONG));
336 public Bearing (GridBagLayout layout, int x, int y) {
337 super (layout, x, y, "Bearing");
343 class Range extends DescentValue {
344 void show (AltosState state, int crc_errors) {
345 show(AltosConvert.distance, state.range);
347 public Range (GridBagLayout layout, int x, int y) {
348 super (layout, x, y, "Range");
354 class Elevation extends DescentValue {
355 void show (AltosState state, int crc_errors) {
356 show("%3.0f°", state.elevation);
358 public Elevation (GridBagLayout layout, int x, int y) {
359 super (layout, x, y, "Elevation");
365 public void reset() {
377 public void set_font() {
384 elevation.set_font();
389 public void show(AltosState state, int crc_errors) {
390 height.show(state, crc_errors);
391 speed.show(state, crc_errors);
392 if (state.gps != null && state.gps.connected) {
393 bearing.show(state, crc_errors);
394 range.show(state, crc_errors);
395 elevation.show(state, crc_errors);
396 lat.show(state, crc_errors);
397 lon.show(state, crc_errors);
405 if (state.main_sense != AltosRecord.MISSING)
406 main.show(state, crc_errors);
409 if (state.drogue_sense != AltosRecord.MISSING)
410 apogee.show(state, crc_errors);
415 public AltosDescent() {
416 layout = new GridBagLayout();
420 /* Elements in descent display */
421 speed = new Speed(layout, 0, 0);
422 height = new Height(layout, 2, 0);
423 elevation = new Elevation(layout, 0, 1);
424 range = new Range(layout, 2, 1);
425 bearing = new Bearing(layout, 0, 2);
426 lat = new Lat(layout, 0, 3);
427 lon = new Lon(layout, 2, 3);
429 apogee = new Apogee(layout, 4);
430 main = new Main(layout, 5);