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) {}
92 label.setVisible(true);
93 value.setVisible(true);
97 label.setVisible(false);
98 value.setVisible(false);
100 public AscentValue (GridBagLayout layout, int y, String text) {
101 GridBagConstraints c = new GridBagConstraints();
104 label = new JLabel(text);
105 label.setFont(Altos.label_font);
106 label.setHorizontalAlignment(SwingConstants.LEFT);
107 c.gridx = 1; c.gridy = y;
108 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
109 c.anchor = GridBagConstraints.WEST;
110 c.fill = GridBagConstraints.VERTICAL;
112 layout.setConstraints(label, c);
115 value = new JTextField(Altos.text_width);
116 value.setFont(Altos.value_font);
117 value.setHorizontalAlignment(SwingConstants.RIGHT);
118 c.gridx = 2; c.gridy = y;
119 c.anchor = GridBagConstraints.WEST;
120 c.fill = GridBagConstraints.BOTH;
123 layout.setConstraints(value, c);
128 public class AscentValueHold {
131 JTextField max_value;
134 void show(AltosState state, int crc_errors) {}
138 max_value.setText("");
142 void show(String format, double v) {
143 value.setText(String.format(format, v));
145 max_value.setText(String.format(format, v));
149 public AscentValueHold (GridBagLayout layout, int y, String text) {
150 GridBagConstraints c = new GridBagConstraints();
153 label = new JLabel(text);
154 label.setFont(Altos.label_font);
155 label.setHorizontalAlignment(SwingConstants.LEFT);
156 c.gridx = 1; c.gridy = y;
157 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
158 c.anchor = GridBagConstraints.WEST;
159 c.fill = GridBagConstraints.VERTICAL;
161 layout.setConstraints(label, c);
164 value = new JTextField(Altos.text_width);
165 value.setFont(Altos.value_font);
166 value.setHorizontalAlignment(SwingConstants.RIGHT);
167 c.gridx = 2; c.gridy = y;
168 c.anchor = GridBagConstraints.EAST;
169 c.fill = GridBagConstraints.BOTH;
171 layout.setConstraints(value, c);
174 max_value = new JTextField(Altos.text_width);
175 max_value.setFont(Altos.value_font);
176 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
177 c.gridx = 3; c.gridy = y;
178 c.anchor = GridBagConstraints.EAST;
179 c.fill = GridBagConstraints.BOTH;
181 layout.setConstraints(max_value, c);
187 class Height extends AscentValueHold {
188 void show (AltosState state, int crc_errors) {
189 show("%6.0f m", state.height);
191 public Height (GridBagLayout layout, int y) {
192 super (layout, y, "Height");
198 class Speed extends AscentValueHold {
199 void show (AltosState state, int crc_errors) {
200 double speed = state.speed;
202 speed = state.baro_speed;
203 show("%6.0f m/s", speed);
205 public Speed (GridBagLayout layout, int y) {
206 super (layout, y, "Speed");
212 class Accel extends AscentValueHold {
213 void show (AltosState state, int crc_errors) {
214 show("%6.0f m/s²", state.acceleration);
216 public Accel (GridBagLayout layout, int y) {
217 super (layout, y, "Acceleration");
223 String pos(double p, String pos, String neg) {
229 int deg = (int) Math.floor(p);
230 double min = (p - Math.floor(p)) * 60.0;
231 return String.format("%s %4d° %9.6f", h, deg, min);
234 class Apogee extends AscentStatus {
235 void show (AltosState state, int crc_errors) {
236 value.setText(String.format("%4.2f V", state.drogue_sense));
237 lights.set(state.drogue_sense > 3.2);
239 public Apogee (GridBagLayout layout, int y) {
240 super(layout, y, "Apogee Igniter Voltage");
246 class Main extends AscentStatus {
247 void show (AltosState state, int crc_errors) {
248 value.setText(String.format("%4.2f V", state.main_sense));
249 lights.set(state.main_sense > 3.2);
251 public Main (GridBagLayout layout, int y) {
252 super(layout, y, "Main Igniter Voltage");
258 class Lat extends AscentValue {
259 void show (AltosState state, int crc_errors) {
261 if (state.gps != null)
262 value.setText(pos(state.gps.lat,"N", "S"));
264 value.setText("???");
266 public Lat (GridBagLayout layout, int y) {
267 super (layout, y, "Latitude");
273 class Lon extends AscentValue {
274 void show (AltosState state, int crc_errors) {
276 if (state.gps != null)
277 value.setText(pos(state.gps.lon,"E", "W"));
279 value.setText("???");
281 public Lon (GridBagLayout layout, int y) {
282 super (layout, y, "Longitude");
288 public void reset() {
298 public void show(AltosState state, int crc_errors) {
299 if (state.gps != null) {
300 lat.show(state, crc_errors);
301 lon.show(state, crc_errors);
306 height.show(state, crc_errors);
307 main.show(state, crc_errors);
308 apogee.show(state, crc_errors);
309 speed.show(state, crc_errors);
310 accel.show(state, crc_errors);
313 public void labels(GridBagLayout layout, int y) {
314 GridBagConstraints c;
317 cur = new JLabel("Current");
318 cur.setFont(Altos.label_font);
319 c = new GridBagConstraints();
320 c.gridx = 2; c.gridy = y;
321 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
322 layout.setConstraints(cur, c);
325 max = new JLabel("Maximum");
326 max.setFont(Altos.label_font);
327 c.gridx = 3; c.gridy = y;
328 layout.setConstraints(max, c);
332 public AltosAscent() {
333 layout = new GridBagLayout();
337 /* Elements in ascent display:
344 height = new Height(layout, 1);
345 speed = new Speed(layout, 2);
346 accel = new Accel(layout, 3);
347 lat = new Lat(layout, 4);
348 lon = new Lon(layout, 5);
349 apogee = new Apogee(layout, 6);
350 main = new Main(layout, 7);