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 AltosAscent extends JComponent implements AltosFlightDisplay {
28 public class AscentStatus {
34 value.setVisible(true);
35 lights.setVisible(true);
36 label.setVisible(true);
40 value.setVisible(false);
41 lights.setVisible(false);
42 label.setVisible(false);
45 void show(AltosState state, int crc_errors) {}
52 label.setFont(Altos.label_font);
53 value.setFont(Altos.value_font);
56 public AscentStatus (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;
76 layout.setConstraints(label, c);
79 value = new JTextField(Altos.text_width);
80 value.setFont(Altos.value_font);
81 value.setHorizontalAlignment(SwingConstants.RIGHT);
82 c.gridx = 2; c.gridy = y;
84 c.anchor = GridBagConstraints.WEST;
85 c.fill = GridBagConstraints.BOTH;
87 layout.setConstraints(value, c);
93 public class AscentValue {
96 void show(AltosState state, int crc_errors) {}
103 label.setVisible(true);
104 value.setVisible(true);
108 label.setVisible(false);
109 value.setVisible(false);
112 label.setFont(Altos.label_font);
113 value.setFont(Altos.value_font);
116 public AscentValue (GridBagLayout layout, int y, String text) {
117 GridBagConstraints c = new GridBagConstraints();
120 label = new JLabel(text);
121 label.setFont(Altos.label_font);
122 label.setHorizontalAlignment(SwingConstants.LEFT);
123 c.gridx = 1; c.gridy = y;
124 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
125 c.anchor = GridBagConstraints.WEST;
126 c.fill = GridBagConstraints.VERTICAL;
128 layout.setConstraints(label, c);
131 value = new JTextField(Altos.text_width);
132 value.setFont(Altos.value_font);
133 value.setHorizontalAlignment(SwingConstants.RIGHT);
134 c.gridx = 2; c.gridy = y;
135 c.anchor = GridBagConstraints.WEST;
136 c.fill = GridBagConstraints.BOTH;
139 layout.setConstraints(value, c);
144 public class AscentValueHold {
147 JTextField max_value;
150 void show(AltosState state, int crc_errors) {}
154 max_value.setText("");
155 max = AltosRecord.MISSING;
159 label.setFont(Altos.label_font);
160 value.setFont(Altos.value_font);
161 max_value.setFont(Altos.value_font);
164 void show(AltosUnits units, double v) {
165 if (v == AltosRecord.MISSING) {
166 value.setText("Missing");
167 max_value.setText("Missing");
169 value.setText(units.show(8, v));
170 if (v > max || max == AltosRecord.MISSING) {
171 max_value.setText(units.show(8, v));
176 public AscentValueHold (GridBagLayout layout, int y, String text) {
177 GridBagConstraints c = new GridBagConstraints();
180 label = new JLabel(text);
181 label.setFont(Altos.label_font);
182 label.setHorizontalAlignment(SwingConstants.LEFT);
183 c.gridx = 1; c.gridy = y;
184 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
185 c.anchor = GridBagConstraints.WEST;
186 c.fill = GridBagConstraints.VERTICAL;
188 layout.setConstraints(label, c);
191 value = new JTextField(Altos.text_width);
192 value.setFont(Altos.value_font);
193 value.setHorizontalAlignment(SwingConstants.RIGHT);
194 c.gridx = 2; c.gridy = y;
195 c.anchor = GridBagConstraints.EAST;
196 c.fill = GridBagConstraints.BOTH;
198 layout.setConstraints(value, c);
201 max_value = new JTextField(Altos.text_width);
202 max_value.setFont(Altos.value_font);
203 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
204 c.gridx = 3; c.gridy = y;
205 c.anchor = GridBagConstraints.EAST;
206 c.fill = GridBagConstraints.BOTH;
208 layout.setConstraints(max_value, c);
214 class Height extends AscentValueHold {
215 void show (AltosState state, int crc_errors) {
216 show(AltosConvert.height, state.height);
218 public Height (GridBagLayout layout, int y) {
219 super (layout, y, "Height");
225 class Speed extends AscentValueHold {
226 void show (AltosState state, int crc_errors) {
227 double speed = state.speed;
229 speed = state.baro_speed;
230 show(AltosConvert.speed, speed);
232 public Speed (GridBagLayout layout, int y) {
233 super (layout, y, "Speed");
239 class Accel extends AscentValueHold {
240 void show (AltosState state, int crc_errors) {
241 show(AltosConvert.accel, state.acceleration);
243 public Accel (GridBagLayout layout, int y) {
244 super (layout, y, "Acceleration");
250 String pos(double p, String pos, String neg) {
256 int deg = (int) Math.floor(p);
257 double min = (p - Math.floor(p)) * 60.0;
258 return String.format("%s %4d° %9.6f", h, deg, min);
261 class Apogee extends AscentStatus {
262 void show (AltosState state, int crc_errors) {
264 value.setText(String.format("%4.2f V", state.drogue_sense));
265 lights.set(state.drogue_sense > 3.2);
267 public Apogee (GridBagLayout layout, int y) {
268 super(layout, y, "Apogee Igniter Voltage");
274 class Main extends AscentStatus {
275 void show (AltosState state, int crc_errors) {
277 value.setText(String.format("%4.2f V", state.main_sense));
278 lights.set(state.main_sense > 3.2);
280 public Main (GridBagLayout layout, int y) {
281 super(layout, y, "Main Igniter Voltage");
287 class Lat extends AscentValue {
288 void show (AltosState state, int crc_errors) {
290 if (state.gps != null)
291 value.setText(pos(state.gps.lat,"N", "S"));
293 value.setText("???");
295 public Lat (GridBagLayout layout, int y) {
296 super (layout, y, "Latitude");
302 class Lon extends AscentValue {
303 void show (AltosState state, int crc_errors) {
305 if (state.gps != null)
306 value.setText(pos(state.gps.lon,"E", "W"));
308 value.setText("???");
310 public Lon (GridBagLayout layout, int y) {
311 super (layout, y, "Longitude");
317 public void reset() {
327 public void set_font() {
328 cur.setFont(Altos.label_font);
329 max.setFont(Altos.label_font);
339 public void show(AltosState state, int crc_errors) {
340 if (state.gps != null && state.gps.connected) {
341 lat.show(state, crc_errors);
342 lon.show(state, crc_errors);
347 height.show(state, crc_errors);
348 if (state.main_sense != AltosRecord.MISSING)
349 main.show(state, crc_errors);
352 if (state.drogue_sense != AltosRecord.MISSING)
353 apogee.show(state, crc_errors);
356 speed.show(state, crc_errors);
357 accel.show(state, crc_errors);
360 public void labels(GridBagLayout layout, int y) {
361 GridBagConstraints c;
363 cur = new JLabel("Current");
364 cur.setFont(Altos.label_font);
365 c = new GridBagConstraints();
366 c.gridx = 2; c.gridy = y;
367 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
368 layout.setConstraints(cur, c);
371 max = new JLabel("Maximum");
372 max.setFont(Altos.label_font);
373 c.gridx = 3; c.gridy = y;
374 layout.setConstraints(max, c);
378 public AltosAscent() {
379 layout = new GridBagLayout();
383 /* Elements in ascent display:
390 height = new Height(layout, 1);
391 speed = new Speed(layout, 2);
392 accel = new Accel(layout, 3);
393 lat = new Lat(layout, 4);
394 lon = new Lon(layout, 5);
395 apogee = new Apogee(layout, 6);
396 main = new Main(layout, 7);