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 AltosAscent extends JComponent implements AltosFlightDisplay {
34 public class AscentStatus {
39 void show(AltosState state, int crc_errors) {}
45 public AscentStatus (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(Altos.text_width);
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 class AscentValue {
85 void show(AltosState state, int crc_errors) {}
90 public AscentValue (GridBagLayout layout, int y, String text) {
91 GridBagConstraints c = new GridBagConstraints();
94 label = new JLabel(text);
95 label.setFont(Altos.label_font);
96 label.setHorizontalAlignment(SwingConstants.LEFT);
97 c.gridx = 1; c.gridy = y;
98 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
99 c.anchor = GridBagConstraints.WEST;
100 c.fill = GridBagConstraints.VERTICAL;
102 layout.setConstraints(label, c);
105 value = new JTextField(Altos.text_width);
106 value.setFont(Altos.value_font);
107 value.setHorizontalAlignment(SwingConstants.RIGHT);
108 c.gridx = 2; c.gridy = y;
109 c.anchor = GridBagConstraints.WEST;
110 c.fill = GridBagConstraints.BOTH;
113 layout.setConstraints(value, c);
118 public class AscentValueHold {
121 JTextField max_value;
124 void show(AltosState state, int crc_errors) {}
128 max_value.setText("");
132 void show(String format, double v) {
133 value.setText(String.format(format, v));
135 max_value.setText(String.format(format, v));
139 public AscentValueHold (GridBagLayout layout, int y, String text) {
140 GridBagConstraints c = new GridBagConstraints();
143 label = new JLabel(text);
144 label.setFont(Altos.label_font);
145 label.setHorizontalAlignment(SwingConstants.LEFT);
146 c.gridx = 1; c.gridy = y;
147 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
148 c.anchor = GridBagConstraints.WEST;
149 c.fill = GridBagConstraints.VERTICAL;
151 layout.setConstraints(label, c);
154 value = new JTextField(Altos.text_width);
155 value.setFont(Altos.value_font);
156 value.setHorizontalAlignment(SwingConstants.RIGHT);
157 c.gridx = 2; c.gridy = y;
158 c.anchor = GridBagConstraints.EAST;
159 c.fill = GridBagConstraints.BOTH;
161 layout.setConstraints(value, c);
164 max_value = new JTextField(Altos.text_width);
165 max_value.setFont(Altos.value_font);
166 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
167 c.gridx = 3; c.gridy = y;
168 c.anchor = GridBagConstraints.EAST;
169 c.fill = GridBagConstraints.BOTH;
171 layout.setConstraints(max_value, c);
177 class Height extends AscentValueHold {
178 void show (AltosState state, int crc_errors) {
179 show("%6.0f m", state.height);
181 public Height (GridBagLayout layout, int y) {
182 super (layout, y, "Height");
188 class Speed extends AscentValueHold {
189 void show (AltosState state, int crc_errors) {
190 double speed = state.speed;
192 speed = state.baro_speed;
193 show("%6.0f m/s", speed);
195 public Speed (GridBagLayout layout, int y) {
196 super (layout, y, "Speed");
202 class Accel extends AscentValueHold {
203 void show (AltosState state, int crc_errors) {
204 show("%6.0f m/s²", state.acceleration);
206 public Accel (GridBagLayout layout, int y) {
207 super (layout, y, "Acceleration");
213 String pos(double p, String pos, String neg) {
219 int deg = (int) Math.floor(p);
220 double min = (p - Math.floor(p)) * 60.0;
221 return String.format("%s %4d° %9.6f", h, deg, min);
224 class Apogee extends AscentStatus {
225 void show (AltosState state, int crc_errors) {
226 value.setText(String.format("%4.2f V", state.drogue_sense));
227 lights.set(state.drogue_sense > 3.2);
229 public Apogee (GridBagLayout layout, int y) {
230 super(layout, y, "Apogee Igniter Voltage");
236 class Main extends AscentStatus {
237 void show (AltosState state, int crc_errors) {
238 value.setText(String.format("%4.2f V", state.main_sense));
239 lights.set(state.main_sense > 3.2);
241 public Main (GridBagLayout layout, int y) {
242 super(layout, y, "Main Igniter Voltage");
248 class Lat extends AscentValue {
249 void show (AltosState state, int crc_errors) {
250 if (state.gps != null)
251 value.setText(pos(state.gps.lat,"N", "S"));
253 value.setText("???");
255 public Lat (GridBagLayout layout, int y) {
256 super (layout, y, "Latitude");
262 class Lon extends AscentValue {
263 void show (AltosState state, int crc_errors) {
264 if (state.gps != null)
265 value.setText(pos(state.gps.lon,"E", "W"));
267 value.setText("???");
269 public Lon (GridBagLayout layout, int y) {
270 super (layout, y, "Longitude");
276 public void reset() {
286 public void show(AltosState state, int crc_errors) {
287 lat.show(state, crc_errors);
288 lon.show(state, crc_errors);
289 height.show(state, crc_errors);
290 main.show(state, crc_errors);
291 apogee.show(state, crc_errors);
292 speed.show(state, crc_errors);
293 accel.show(state, crc_errors);
296 public void labels(GridBagLayout layout, int y) {
297 GridBagConstraints c;
300 cur = new JLabel("Current");
301 cur.setFont(Altos.label_font);
302 c = new GridBagConstraints();
303 c.gridx = 2; c.gridy = y;
304 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
305 layout.setConstraints(cur, c);
308 max = new JLabel("Maximum");
309 max.setFont(Altos.label_font);
310 c.gridx = 3; c.gridy = y;
311 layout.setConstraints(max, c);
315 public AltosAscent() {
316 layout = new GridBagLayout();
320 /* Elements in ascent display:
327 height = new Height(layout, 1);
328 speed = new Speed(layout, 2);
329 accel = new Accel(layout, 3);
330 lat = new Lat(layout, 4);
331 lon = new Lon(layout, 5);
332 apogee = new Apogee(layout, 6);
333 main = new Main(layout, 7);