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_4.*;
23 import org.altusmetrum.altosuilib_2.*;
25 public class AltosPad extends JComponent implements AltosFlightDisplay {
28 public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
33 void show(AltosState state, AltosListenerState listener_state) {}
41 label.setVisible(true);
42 value.setVisible(true);
43 lights.setVisible(true);
51 void show(String format, double value) {
52 show(String.format(format, value));
55 void show(String format, int value) {
56 show(String.format(format, value));
60 label.setVisible(false);
61 value.setVisible(false);
62 lights.setVisible(false);
65 public void font_size_changed(int font_size) {
66 label.setFont(Altos.label_font);
67 value.setFont(Altos.value_font);
70 public void units_changed(boolean imperial_units) {
73 public void set_label(String text) {
77 public LaunchStatus (GridBagLayout layout, int y, String text) {
78 GridBagConstraints c = new GridBagConstraints();
81 lights = new AltosLights();
82 c.gridx = 0; c.gridy = y;
83 c.anchor = GridBagConstraints.CENTER;
84 c.fill = GridBagConstraints.VERTICAL;
86 layout.setConstraints(lights, c);
89 label = new JLabel(text);
90 label.setFont(Altos.label_font);
91 label.setHorizontalAlignment(SwingConstants.LEFT);
92 c.gridx = 1; c.gridy = y;
93 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
94 c.anchor = GridBagConstraints.WEST;
95 c.fill = GridBagConstraints.VERTICAL;
97 layout.setConstraints(label, c);
100 value = new JTextField(Altos.text_width);
101 value.setEditable(false);
102 value.setFont(Altos.value_font);
103 value.setHorizontalAlignment(SwingConstants.RIGHT);
104 c.gridx = 2; c.gridy = y;
105 c.anchor = GridBagConstraints.WEST;
106 c.fill = GridBagConstraints.BOTH;
108 layout.setConstraints(value, c);
114 public abstract class LaunchValue implements AltosFontListener, AltosUnitsListener {
120 abstract void show(AltosState state, AltosListenerState listener_state);
123 label.setVisible(true);
124 value.setVisible(true);
128 label.setVisible(false);
129 value.setVisible(false);
132 public void font_size_changed(int font_size) {
133 label.setFont(Altos.label_font);
134 value.setFont(Altos.value_font);
137 public void units_changed(boolean imperial_units) {
142 void show(String s) {
147 void show(double v) {
149 show(units.show(8, v));
152 void show(String format, double v) {
153 show(String.format(format, v));
156 public void set_label(String text) {
164 public LaunchValue (GridBagLayout layout, int y, AltosUnits units, String text) {
167 GridBagConstraints c = new GridBagConstraints();
168 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
171 label = new JLabel(text);
172 label.setFont(Altos.label_font);
173 label.setHorizontalAlignment(SwingConstants.LEFT);
174 c.gridx = 1; c.gridy = y;
175 c.anchor = GridBagConstraints.WEST;
176 c.fill = GridBagConstraints.VERTICAL;
178 layout.setConstraints(label, c);
181 value = new JTextField(Altos.text_width);
182 value.setEditable(false);
183 value.setFont(Altos.value_font);
184 value.setHorizontalAlignment(SwingConstants.RIGHT);
185 c.gridx = 2; c.gridy = y;
186 c.anchor = GridBagConstraints.EAST;
187 c.fill = GridBagConstraints.BOTH;
189 layout.setConstraints(value, c);
193 public LaunchValue (GridBagLayout layout, int y, String text) {
194 this(layout, y, null, text);
198 class Voltage extends LaunchStatus {
200 double voltage(AltosState state) { return AltosLib.MISSING; };
201 double good() { return 0; };
203 double last_voltage = -1;
205 void show (AltosState state, AltosListenerState listener_state) {
206 double voltage = AltosLib.MISSING;
208 voltage = voltage(state);
210 if (voltage != last_voltage) {
211 if (voltage == AltosLib.MISSING)
214 show("%4.2f V", voltage);
215 lights.set(voltage >= good());
217 last_voltage = voltage;
220 public Voltage (GridBagLayout layout, int y, String name) { super(layout, y, name); }
224 class Battery extends Voltage {
225 double voltage(AltosState state) { return state.battery_voltage; }
226 double good() { return AltosLib.ao_battery_good; }
228 public Battery (GridBagLayout layout, int y) {
229 super(layout, y, "Battery Voltage");
236 class Apogee extends Voltage {
237 double voltage(AltosState state) { return state.apogee_voltage; }
238 double good() { return AltosLib.ao_igniter_good; }
239 public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); }
244 class Main extends Voltage {
245 double voltage(AltosState state) { return state.main_voltage; }
246 double good() { return AltosLib.ao_igniter_good; }
247 public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); }
252 class LoggingReady extends LaunchStatus {
253 void show (AltosState state, AltosListenerState listener_state) {
254 if (state == null || state.flight == AltosLib.MISSING) {
257 if (state.flight != 0) {
258 if (state.state <= Altos.ao_flight_pad)
259 show("Ready to record");
260 else if (state.state < Altos.ao_flight_landed)
261 show("Recording data");
263 show("Recorded data");
265 show("Storage full");
266 lights.set(state.flight != 0);
269 public LoggingReady (GridBagLayout layout, int y) {
270 super(layout, y, "On-board Data Logging");
274 LoggingReady logging_ready;
276 class GPSLocked extends LaunchStatus {
277 void show (AltosState state, AltosListenerState listener_state) {
278 if (state == null || state.gps == null)
281 show("%4d sats", state.gps.nsat);
282 lights.set(state.gps.locked && state.gps.nsat >= 4);
285 public GPSLocked (GridBagLayout layout, int y) {
286 super (layout, y, "GPS Locked");
290 GPSLocked gps_locked;
292 class GPSReady extends LaunchStatus {
293 void show (AltosState state, AltosListenerState listener_state) {
294 if (state == null || state.gps == null)
300 show("Waiting %d", state.gps_waiting);
301 lights.set(state.gps_ready);
304 public GPSReady (GridBagLayout layout, int y) {
305 super (layout, y, "GPS Ready");
311 class ReceiverBattery extends LaunchStatus {
312 void show (AltosState state, AltosListenerState listener_state) {
313 if (listener_state == null || listener_state.battery == AltosLib.MISSING)
316 show("%4.2f V", listener_state.battery);
317 lights.set(listener_state.battery > AltosLib.ao_battery_good);
320 public ReceiverBattery (GridBagLayout layout, int y) {
321 super(layout, y, "Receiver Battery");
325 ReceiverBattery receiver_battery;
327 String pos(double p, String pos, String neg) {
333 int deg = (int) Math.floor(p);
334 double min = (p - Math.floor(p)) * 60.0;
335 return String.format("%s %4d° %9.6f", h, deg, min);
338 class PadLat extends LaunchValue {
340 double last_lat = 1000;
342 void show (AltosState state, AltosListenerState listener_state) {
343 double lat = AltosLib.MISSING;
347 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosLib.MISSING) {
352 label = "Pad Latitude";
355 if (lat != last_lat) {
356 if (lat != AltosLib.MISSING) {
357 show(pos(lat,"N", "S"));
364 public PadLat (GridBagLayout layout, int y) {
365 super (layout, y, "Pad Latitude");
371 class PadLon extends LaunchValue {
373 double last_lon = 1000;
375 void show (AltosState state, AltosListenerState listener_state) {
376 double lon = AltosLib.MISSING;
380 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosLib.MISSING) {
385 label = "Pad Longitude";
388 if (lon != last_lon) {
389 if (lon != AltosLib.MISSING) {
390 show(pos(lon,"E", "W"));
397 public PadLon (GridBagLayout layout, int y) {
398 super (layout, y, "Pad Longitude");
404 class PadAlt extends LaunchValue {
406 double last_alt = -1000000;
408 void show (AltosState state, AltosListenerState listener_state) {
409 double alt = AltosLib.MISSING;
413 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosLib.MISSING) {
418 label = "Pad Altitude";
421 if (alt != last_alt) {
422 if (alt != AltosLib.MISSING) {
430 public PadAlt (GridBagLayout layout, int y) {
431 super (layout, y, AltosConvert.height, "Pad Altitude");
437 public void reset() {
441 logging_ready.reset();
444 receiver_battery.reset();
450 public void font_size_changed(int font_size) {
451 battery.font_size_changed(font_size);
452 apogee.font_size_changed(font_size);
453 main.font_size_changed(font_size);
454 logging_ready.font_size_changed(font_size);
455 gps_locked.font_size_changed(font_size);
456 gps_ready.font_size_changed(font_size);
457 receiver_battery.font_size_changed(font_size);
458 pad_lat.font_size_changed(font_size);
459 pad_lon.font_size_changed(font_size);
460 pad_alt.font_size_changed(font_size);
463 public void units_changed(boolean imperial_units) {
464 battery.units_changed(imperial_units);
465 apogee.units_changed(imperial_units);
466 main.units_changed(imperial_units);
467 logging_ready.units_changed(imperial_units);
468 gps_locked.units_changed(imperial_units);
469 gps_ready.units_changed(imperial_units);
470 receiver_battery.units_changed(imperial_units);
471 pad_lat.units_changed(imperial_units);
472 pad_lon.units_changed(imperial_units);
473 pad_alt.units_changed(imperial_units);
476 public void show(AltosState state, AltosListenerState listener_state) {
477 battery.show(state, listener_state);
478 apogee.show(state, listener_state);
479 main.show(state, listener_state);
480 logging_ready.show(state, listener_state);
481 pad_alt.show(state, listener_state);
482 receiver_battery.show(state, listener_state);
483 gps_locked.show(state, listener_state);
484 gps_ready.show(state, listener_state);
485 pad_lat.show(state, listener_state);
486 pad_lon.show(state, listener_state);
490 layout = new GridBagLayout();
494 /* Elements in pad display:
504 battery = new Battery(layout, 0);
505 apogee = new Apogee(layout, 1);
506 main = new Main(layout, 2);
507 logging_ready = new LoggingReady(layout, 3);
508 gps_locked = new GPSLocked(layout, 4);
509 gps_ready = new GPSReady(layout, 5);
510 receiver_battery = new ReceiverBattery(layout, 6);
511 pad_lat = new PadLat(layout, 7);
512 pad_lon = new PadLon(layout, 8);
513 pad_alt = new PadAlt(layout, 9);