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;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosAscent extends JComponent implements AltosFlightDisplay {
36 public class AscentStatus {
42 value.setVisible(true);
43 lights.setVisible(true);
44 label.setVisible(true);
48 value.setVisible(false);
49 lights.setVisible(false);
50 label.setVisible(false);
53 void show(AltosState state, int crc_errors) {}
60 void show(AltosUnits units, double v) {
61 show(units.show(8, v));
64 void show(String format, double v) {
65 show(String.format(format, v));
74 label.setFont(Altos.label_font);
75 value.setFont(Altos.value_font);
78 public AscentStatus (GridBagLayout layout, int y, String text) {
79 GridBagConstraints c = new GridBagConstraints();
82 lights = new AltosLights();
83 c.gridx = 0; c.gridy = y;
84 c.anchor = GridBagConstraints.CENTER;
85 c.fill = GridBagConstraints.VERTICAL;
87 layout.setConstraints(lights, c);
90 label = new JLabel(text);
91 label.setFont(Altos.label_font);
92 label.setHorizontalAlignment(SwingConstants.LEFT);
93 c.gridx = 1; c.gridy = y;
94 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
95 c.anchor = GridBagConstraints.WEST;
96 c.fill = GridBagConstraints.VERTICAL;
98 layout.setConstraints(label, c);
101 value = new JTextField(Altos.text_width);
102 value.setFont(Altos.value_font);
103 value.setHorizontalAlignment(SwingConstants.RIGHT);
104 c.gridx = 2; c.gridy = y;
106 c.anchor = GridBagConstraints.WEST;
107 c.fill = GridBagConstraints.BOTH;
109 layout.setConstraints(value, c);
115 public class AscentValue {
118 void show(AltosState state, int crc_errors) {}
125 label.setVisible(true);
126 value.setVisible(true);
129 void show(String s) {
134 void show(AltosUnits units, double v) {
135 show(units.show(8, v));
138 void show(String format, double v) {
139 show(String.format(format, v));
143 label.setVisible(false);
144 value.setVisible(false);
147 label.setFont(Altos.label_font);
148 value.setFont(Altos.value_font);
151 public AscentValue (GridBagLayout layout, int y, String text) {
152 GridBagConstraints c = new GridBagConstraints();
155 label = new JLabel(text);
156 label.setFont(Altos.label_font);
157 label.setHorizontalAlignment(SwingConstants.LEFT);
158 c.gridx = 1; c.gridy = y;
159 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
160 c.anchor = GridBagConstraints.WEST;
161 c.fill = GridBagConstraints.VERTICAL;
163 layout.setConstraints(label, c);
166 value = new JTextField(Altos.text_width);
167 value.setFont(Altos.value_font);
168 value.setHorizontalAlignment(SwingConstants.RIGHT);
169 c.gridx = 2; c.gridy = y;
170 c.anchor = GridBagConstraints.WEST;
171 c.fill = GridBagConstraints.BOTH;
174 layout.setConstraints(value, c);
179 public class AscentValueHold {
182 JTextField max_value;
185 void show(AltosState state, int crc_errors) {}
189 max_value.setText("");
190 max = AltosRecord.MISSING;
194 label.setFont(Altos.label_font);
195 value.setFont(Altos.value_font);
196 max_value.setFont(Altos.value_font);
199 void show(AltosUnits units, double v) {
200 if (v == AltosRecord.MISSING) {
201 value.setText("Missing");
202 max_value.setText("Missing");
204 value.setText(units.show(8, v));
205 if (v > max || max == AltosRecord.MISSING) {
206 max_value.setText(units.show(8, v));
211 public AscentValueHold (GridBagLayout layout, int y, String text) {
212 GridBagConstraints c = new GridBagConstraints();
215 label = new JLabel(text);
216 label.setFont(Altos.label_font);
217 label.setHorizontalAlignment(SwingConstants.LEFT);
218 c.gridx = 1; c.gridy = y;
219 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
220 c.anchor = GridBagConstraints.WEST;
221 c.fill = GridBagConstraints.VERTICAL;
223 layout.setConstraints(label, c);
226 value = new JTextField(Altos.text_width);
227 value.setFont(Altos.value_font);
228 value.setHorizontalAlignment(SwingConstants.RIGHT);
229 c.gridx = 2; c.gridy = y;
230 c.anchor = GridBagConstraints.EAST;
231 c.fill = GridBagConstraints.BOTH;
233 layout.setConstraints(value, c);
236 max_value = new JTextField(Altos.text_width);
237 max_value.setFont(Altos.value_font);
238 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
239 c.gridx = 3; c.gridy = y;
240 c.anchor = GridBagConstraints.EAST;
241 c.fill = GridBagConstraints.BOTH;
243 layout.setConstraints(max_value, c);
249 class Height extends AscentValueHold {
250 void show (AltosState state, int crc_errors) {
251 show(AltosConvert.height, state.height);
253 public Height (GridBagLayout layout, int y) {
254 super (layout, y, "Height");
260 class Speed extends AscentValueHold {
261 void show (AltosState state, int crc_errors) {
262 double speed = state.speed;
264 speed = state.baro_speed;
265 show(AltosConvert.speed, speed);
267 public Speed (GridBagLayout layout, int y) {
268 super (layout, y, "Speed");
274 class Accel extends AscentValueHold {
275 void show (AltosState state, int crc_errors) {
276 show(AltosConvert.accel, state.acceleration);
278 public Accel (GridBagLayout layout, int y) {
279 super (layout, y, "Acceleration");
285 String pos(double p, String pos, String neg) {
291 int deg = (int) Math.floor(p);
292 double min = (p - Math.floor(p)) * 60.0;
293 return String.format("%s %4d° %9.6f", h, deg, min);
296 class Apogee extends AscentStatus {
297 void show (AltosState state, int crc_errors) {
298 show("%4.2f V", state.drogue_sense);
299 lights.set(state.drogue_sense > 3.2);
301 public Apogee (GridBagLayout layout, int y) {
302 super(layout, y, "Apogee Igniter Voltage");
308 class Main extends AscentStatus {
309 void show (AltosState state, int crc_errors) {
310 show("%4.2f V", state.main_sense);
311 lights.set(state.main_sense > 3.2);
313 public Main (GridBagLayout layout, int y) {
314 super(layout, y, "Main Igniter Voltage");
320 class Lat extends AscentValue {
321 void show (AltosState state, int crc_errors) {
322 if (state.gps != null)
323 show(pos(state.gps.lat,"N", "S"));
327 public Lat (GridBagLayout layout, int y) {
328 super (layout, y, "Latitude");
334 class Lon extends AscentValue {
335 void show (AltosState state, int crc_errors) {
336 if (state.gps != null)
337 show(pos(state.gps.lon,"E", "W"));
341 public Lon (GridBagLayout layout, int y) {
342 super (layout, y, "Longitude");
348 public void reset() {
358 public void set_font() {
359 cur.setFont(Altos.label_font);
360 max.setFont(Altos.label_font);
370 public void show(AltosState state, int crc_errors) {
371 if (state.gps != null && state.gps.connected) {
372 lat.show(state, crc_errors);
373 lon.show(state, crc_errors);
378 height.show(state, crc_errors);
379 if (state.main_sense != AltosRecord.MISSING)
380 main.show(state, crc_errors);
383 if (state.drogue_sense != AltosRecord.MISSING)
384 apogee.show(state, crc_errors);
387 speed.show(state, crc_errors);
388 accel.show(state, crc_errors);
391 public void labels(GridBagLayout layout, int y) {
392 GridBagConstraints c;
394 cur = new JLabel("Current");
395 cur.setFont(Altos.label_font);
396 c = new GridBagConstraints();
397 c.gridx = 2; c.gridy = y;
398 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
399 layout.setConstraints(cur, c);
402 max = new JLabel("Maximum");
403 max.setFont(Altos.label_font);
404 c.gridx = 3; c.gridy = y;
405 layout.setConstraints(max, c);
409 public AltosAscent() {
410 layout = new GridBagLayout();
414 /* Elements in ascent display:
421 height = new Height(layout, 1);
422 speed = new Speed(layout, 2);
423 accel = new Accel(layout, 3);
424 lat = new Lat(layout, 4);
425 lon = new Lon(layout, 5);
426 apogee = new Apogee(layout, 6);
427 main = new Main(layout, 7);