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_3.*;
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, AltosListenerState listener_state) {}
52 void show(AltosUnits units, double v) {
53 show(units.show(8, v));
56 void show(String format, double v) {
57 show(String.format(format, v));
66 label.setFont(Altos.label_font);
67 value.setFont(Altos.value_font);
70 public AscentStatus (GridBagLayout layout, int y, String text) {
71 GridBagConstraints c = new GridBagConstraints();
74 lights = new AltosLights();
75 c.gridx = 0; c.gridy = y;
76 c.anchor = GridBagConstraints.CENTER;
77 c.fill = GridBagConstraints.VERTICAL;
79 layout.setConstraints(lights, c);
82 label = new JLabel(text);
83 label.setFont(Altos.label_font);
84 label.setHorizontalAlignment(SwingConstants.LEFT);
85 c.gridx = 1; c.gridy = y;
86 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
87 c.anchor = GridBagConstraints.WEST;
88 c.fill = GridBagConstraints.VERTICAL;
90 layout.setConstraints(label, c);
93 value = new JTextField(Altos.text_width);
94 value.setFont(Altos.value_font);
95 value.setHorizontalAlignment(SwingConstants.RIGHT);
96 c.gridx = 2; c.gridy = y;
98 c.anchor = GridBagConstraints.WEST;
99 c.fill = GridBagConstraints.BOTH;
101 layout.setConstraints(value, c);
107 public class AscentValue {
110 void show(AltosState state, AltosListenerState listener_state) {}
117 label.setVisible(true);
118 value.setVisible(true);
121 void show(String s) {
126 void show(AltosUnits units, double v) {
127 show(units.show(8, v));
130 void show(String format, double v) {
131 show(String.format(format, v));
135 label.setVisible(false);
136 value.setVisible(false);
139 label.setFont(Altos.label_font);
140 value.setFont(Altos.value_font);
143 public AscentValue (GridBagLayout layout, int y, String text) {
144 GridBagConstraints c = new GridBagConstraints();
147 label = new JLabel(text);
148 label.setFont(Altos.label_font);
149 label.setHorizontalAlignment(SwingConstants.LEFT);
150 c.gridx = 1; c.gridy = y;
151 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
152 c.anchor = GridBagConstraints.WEST;
153 c.fill = GridBagConstraints.VERTICAL;
155 layout.setConstraints(label, c);
158 value = new JTextField(Altos.text_width);
159 value.setFont(Altos.value_font);
160 value.setHorizontalAlignment(SwingConstants.RIGHT);
161 c.gridx = 2; c.gridy = y;
162 c.anchor = GridBagConstraints.WEST;
163 c.fill = GridBagConstraints.BOTH;
166 layout.setConstraints(value, c);
171 public class AscentValueHold {
174 JTextField max_value;
177 void show(AltosState state, AltosListenerState listener_state) {}
181 max_value.setText("");
182 max = AltosLib.MISSING;
186 label.setFont(Altos.label_font);
187 value.setFont(Altos.value_font);
188 max_value.setFont(Altos.value_font);
191 void show(AltosUnits units, double v) {
192 if (v == AltosLib.MISSING) {
193 value.setText("Missing");
194 max_value.setText("Missing");
196 value.setText(units.show(8, v));
197 if (v > max || max == AltosLib.MISSING) {
198 max_value.setText(units.show(8, v));
203 public AscentValueHold (GridBagLayout layout, int y, String text) {
204 GridBagConstraints c = new GridBagConstraints();
207 label = new JLabel(text);
208 label.setFont(Altos.label_font);
209 label.setHorizontalAlignment(SwingConstants.LEFT);
210 c.gridx = 1; c.gridy = y;
211 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
212 c.anchor = GridBagConstraints.WEST;
213 c.fill = GridBagConstraints.VERTICAL;
215 layout.setConstraints(label, c);
218 value = new JTextField(Altos.text_width);
219 value.setFont(Altos.value_font);
220 value.setHorizontalAlignment(SwingConstants.RIGHT);
221 c.gridx = 2; c.gridy = y;
222 c.anchor = GridBagConstraints.EAST;
223 c.fill = GridBagConstraints.BOTH;
225 layout.setConstraints(value, c);
228 max_value = new JTextField(Altos.text_width);
229 max_value.setFont(Altos.value_font);
230 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
231 c.gridx = 3; c.gridy = y;
232 c.anchor = GridBagConstraints.EAST;
233 c.fill = GridBagConstraints.BOTH;
235 layout.setConstraints(max_value, c);
241 class Height extends AscentValueHold {
242 void show (AltosState state, AltosListenerState listener_state) {
243 show(AltosConvert.height, state.height());
245 public Height (GridBagLayout layout, int y) {
246 super (layout, y, "Height");
252 class Speed extends AscentValueHold {
253 void show (AltosState state, AltosListenerState listener_state) {
254 show(AltosConvert.speed, state.speed());
256 public Speed (GridBagLayout layout, int y) {
257 super (layout, y, "Speed");
263 class Accel extends AscentValueHold {
264 void show (AltosState state, AltosListenerState listener_state) {
265 show(AltosConvert.accel, state.acceleration());
267 public Accel (GridBagLayout layout, int y) {
268 super (layout, y, "Acceleration");
274 class Orient extends AscentValueHold {
275 void show (AltosState state, AltosListenerState listener_state) {
276 show(AltosConvert.orient, state.orient());
278 public Orient (GridBagLayout layout, int y) {
279 super (layout, y, "Tilt Angle");
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, AltosListenerState listener_state) {
298 show("%4.2f V", state.apogee_voltage);
299 lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
301 public Apogee (GridBagLayout layout, int y) {
302 super(layout, y, "Apogee Igniter Voltage");
308 class Main extends AscentStatus {
309 void show (AltosState state, AltosListenerState listener_state) {
310 show("%4.2f V", state.main_voltage);
311 lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
313 public Main (GridBagLayout layout, int y) {
314 super(layout, y, "Main Igniter Voltage");
320 class Lat extends AscentValue {
321 void show (AltosState state, AltosListenerState listener_state) {
322 if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
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, AltosListenerState listener_state) {
336 if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
337 show(pos(state.gps.lon,"E", "W"));
341 public Lon (GridBagLayout layout, int y) {
342 super (layout, y, "Longitude");
348 public void reset() {
359 public void set_font() {
360 cur.setFont(Altos.label_font);
361 max.setFont(Altos.label_font);
372 public void show(AltosState state, AltosListenerState listener_state) {
373 if (state.gps != null && state.gps.connected) {
374 lat.show(state, listener_state);
375 lon.show(state, listener_state);
380 height.show(state, listener_state);
381 if (state.main_voltage != AltosLib.MISSING)
382 main.show(state, listener_state);
385 if (state.apogee_voltage != AltosLib.MISSING)
386 apogee.show(state, listener_state);
389 speed.show(state, listener_state);
390 accel.show(state, listener_state);
391 orient.show(state, listener_state);
394 public void labels(GridBagLayout layout, int y) {
395 GridBagConstraints c;
397 cur = new JLabel("Current");
398 cur.setFont(Altos.label_font);
399 c = new GridBagConstraints();
400 c.gridx = 2; c.gridy = y;
401 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
402 layout.setConstraints(cur, c);
405 max = new JLabel("Maximum");
406 max.setFont(Altos.label_font);
407 c.gridx = 3; c.gridy = y;
408 layout.setConstraints(max, c);
412 public String getName() {
416 public AltosAscent() {
417 layout = new GridBagLayout();
421 /* Elements in ascent display:
429 height = new Height(layout, y++);
430 speed = new Speed(layout, y++);
431 accel = new Accel(layout, y++);
432 orient = new Orient(layout, y++);
433 lat = new Lat(layout, y++);
434 lon = new Lon(layout, y++);
435 apogee = new Apogee(layout, y++);
436 main = new Main(layout, y++);