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);
45 public DescentStatus (GridBagLayout layout, int y, String text) {
46 GridBagConstraints c = new GridBagConstraints();
49 lights = new AltosLights();
50 c.gridx = 0; c.gridy = y;
51 c.anchor = GridBagConstraints.CENTER;
52 c.fill = GridBagConstraints.VERTICAL;
54 layout.setConstraints(lights, c);
57 label = new JLabel(text);
58 label.setFont(Altos.label_font);
59 label.setHorizontalAlignment(SwingConstants.LEFT);
60 c.gridx = 1; c.gridy = y;
61 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
62 c.anchor = GridBagConstraints.WEST;
63 c.fill = GridBagConstraints.VERTICAL;
65 layout.setConstraints(label, c);
68 value = new JTextField(15);
69 value.setFont(Altos.value_font);
70 value.setHorizontalAlignment(SwingConstants.RIGHT);
71 c.gridx = 2; c.gridy = y;
73 c.anchor = GridBagConstraints.WEST;
74 c.fill = GridBagConstraints.BOTH;
76 layout.setConstraints(value, c);
82 public abstract class DescentValue {
90 abstract void show(AltosState state, int crc_errors);
92 void show(String format, double v) {
93 value.setText(String.format(format, v));
96 public DescentValue (GridBagLayout layout, int x, int y, String text) {
97 GridBagConstraints c = new GridBagConstraints();
100 label = new JLabel(text);
101 label.setFont(Altos.label_font);
102 label.setHorizontalAlignment(SwingConstants.LEFT);
103 c.gridx = x + 1; c.gridy = y;
104 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
105 c.anchor = GridBagConstraints.WEST;
106 c.fill = GridBagConstraints.VERTICAL;
108 layout.setConstraints(label, c);
111 value = new JTextField(17);
112 value.setFont(Altos.value_font);
113 value.setHorizontalAlignment(SwingConstants.RIGHT);
114 c.gridx = x + 2; c.gridy = y;
116 c.anchor = GridBagConstraints.WEST;
117 c.fill = GridBagConstraints.BOTH;
119 layout.setConstraints(value, c);
124 public abstract class DescentDualValue {
134 abstract void show(AltosState state, int crc_errors);
135 void show(String v1, String v2) {
139 void show(String f1, double v1, String f2, double v2) {
140 value1.setText(String.format(f1, v1));
141 value2.setText(String.format(f2, v2));
144 public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
145 GridBagConstraints c = new GridBagConstraints();
148 label = new JLabel(text);
149 label.setFont(Altos.label_font);
150 label.setHorizontalAlignment(SwingConstants.LEFT);
151 c.gridx = x + 1; c.gridy = y;
152 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
153 c.anchor = GridBagConstraints.WEST;
154 c.fill = GridBagConstraints.VERTICAL;
156 layout.setConstraints(label, c);
159 value1 = new JTextField(17);
160 value1.setFont(Altos.value_font);
161 value1.setHorizontalAlignment(SwingConstants.RIGHT);
162 c.gridx = x + 2; c.gridy = y;
163 c.anchor = GridBagConstraints.WEST;
164 c.fill = GridBagConstraints.BOTH;
166 layout.setConstraints(value1, c);
169 value2 = new JTextField(17);
170 value2.setFont(Altos.value_font);
171 value2.setHorizontalAlignment(SwingConstants.RIGHT);
172 c.gridx = x + 3; c.gridy = y;
173 c.anchor = GridBagConstraints.WEST;
174 c.fill = GridBagConstraints.BOTH;
176 layout.setConstraints(value2, c);
181 class Height extends DescentDualValue {
182 void show (AltosState state, int crc_errors) {
183 show("%6.0f m", state.height,
184 "%3.0f°", state.elevation);
186 public Height (GridBagLayout layout, int x, int y) {
187 super (layout, x, y, "Height/Elevation");
193 class Speed extends DescentValue {
194 void show (AltosState state, int crc_errors) {
195 double speed = state.speed;
197 speed = state.baro_speed;
198 show("%6.0f m/s", speed);
200 public Speed (GridBagLayout layout, int x, int y) {
201 super (layout, x, y, "Speed");
207 String pos(double p, String pos, String neg) {
213 int deg = (int) Math.floor(p);
214 double min = (p - Math.floor(p)) * 60.0;
215 return String.format("%s %4d° %9.6f", h, deg, min);
218 class LatLon extends DescentDualValue {
219 void show (AltosState state, int crc_errors) {
220 if (state.gps != null)
221 show(pos(state.gps.lat,"N", "S"),
222 pos(state.gps.lon,"W", "E"));
226 public LatLon (GridBagLayout layout, int x, int y) {
227 super (layout, x, y, "Lat/Long");
233 class Apogee extends DescentStatus {
234 void show (AltosState state, int crc_errors) {
235 value.setText(String.format("%4.2f V", state.drogue_sense));
236 lights.set(state.drogue_sense > 3.2);
238 public Apogee (GridBagLayout layout, int y) {
239 super(layout, y, "Apogee Igniter Voltage");
245 class Main extends DescentStatus {
246 void show (AltosState state, int crc_errors) {
247 value.setText(String.format("%4.2f V", state.main_sense));
248 lights.set(state.main_sense > 3.2);
250 public Main (GridBagLayout layout, int y) {
251 super(layout, y, "Main Igniter Voltage");
257 class Bearing extends DescentDualValue {
258 void show (AltosState state, int crc_errors) {
259 if (state.from_pad != null) {
260 show( state.from_pad.bearing_words(
261 AltosGreatCircle.BEARING_LONG),
262 String.format("%3.0f°", state.from_pad.bearing));
267 public Bearing (GridBagLayout layout, int x, int y) {
268 super (layout, x, y, "Bearing");
274 class Range extends DescentValue {
275 void show (AltosState state, int crc_errors) {
276 show("%6.0f m", state.range);
278 public Range (GridBagLayout layout, int x, int y) {
279 super (layout, x, y, "Range");
285 public void reset() {
295 public void show(AltosState state, int crc_errors) {
296 height.show(state, crc_errors);
297 speed.show(state, crc_errors);
298 bearing.show(state, crc_errors);
299 range.show(state, crc_errors);
300 latlon.show(state, crc_errors);
301 main.show(state, crc_errors);
302 apogee.show(state, crc_errors);
305 public AltosDescent() {
306 layout = new GridBagLayout();
310 /* Elements in descent display */
311 speed = new Speed(layout, 0, 0);
312 height = new Height(layout, 0, 1);
313 range = new Range(layout, 0, 2);
314 bearing = new Bearing(layout, 0, 3);
315 latlon = new LatLon(layout, 0, 4);
317 apogee = new Apogee(layout, 5);
318 main = new Main(layout, 6);