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 {
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 set_font() {
66 label.setFont(Altos.label_font);
67 value.setFont(Altos.value_font);
70 public void set_label(String text) {
74 public LaunchStatus (GridBagLayout layout, int y, String text) {
75 GridBagConstraints c = new GridBagConstraints();
78 lights = new AltosLights();
79 c.gridx = 0; c.gridy = y;
80 c.anchor = GridBagConstraints.CENTER;
81 c.fill = GridBagConstraints.VERTICAL;
83 layout.setConstraints(lights, c);
86 label = new JLabel(text);
87 label.setFont(Altos.label_font);
88 label.setHorizontalAlignment(SwingConstants.LEFT);
89 c.gridx = 1; c.gridy = y;
90 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
91 c.anchor = GridBagConstraints.WEST;
92 c.fill = GridBagConstraints.VERTICAL;
94 layout.setConstraints(label, c);
97 value = new JTextField(Altos.text_width);
98 value.setFont(Altos.value_font);
99 value.setHorizontalAlignment(SwingConstants.RIGHT);
100 c.gridx = 2; c.gridy = y;
101 c.anchor = GridBagConstraints.WEST;
102 c.fill = GridBagConstraints.BOTH;
104 layout.setConstraints(value, c);
110 public class LaunchValue {
113 void show(AltosState state, AltosListenerState listener_state) {}
116 label.setVisible(true);
117 value.setVisible(true);
121 label.setVisible(false);
122 value.setVisible(false);
125 public void set_font() {
126 label.setFont(Altos.label_font);
127 value.setFont(Altos.value_font);
130 void show(String s) {
135 void show(AltosUnits units, double v) {
136 show(units.show(8, v));
139 void show(String format, double v) {
140 show(String.format(format, v));
143 public void set_label(String text) {
151 public LaunchValue (GridBagLayout layout, int y, String text) {
152 GridBagConstraints c = new GridBagConstraints();
153 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
156 label = new JLabel(text);
157 label.setFont(Altos.label_font);
158 label.setHorizontalAlignment(SwingConstants.LEFT);
159 c.gridx = 1; c.gridy = y;
160 c.anchor = GridBagConstraints.WEST;
161 c.fill = GridBagConstraints.VERTICAL;
163 layout.setConstraints(label, c);
166 value = new JTextField(Altos.text_width);
167 value.setFont(Altos.value_font);
168 value.setHorizontalAlignment(SwingConstants.RIGHT);
169 c.gridx = 2; c.gridy = y;
170 c.anchor = GridBagConstraints.EAST;
171 c.fill = GridBagConstraints.BOTH;
173 layout.setConstraints(value, c);
178 class Battery extends LaunchStatus {
179 void show (AltosState state, AltosListenerState listener_state) {
180 if (state == null || state.battery_voltage == AltosLib.MISSING)
183 show("%4.2f V", state.battery_voltage);
184 lights.set(state.battery_voltage >= AltosLib.ao_battery_good);
187 public Battery (GridBagLayout layout, int y) {
188 super(layout, y, "Battery Voltage");
194 class Apogee extends LaunchStatus {
195 void show (AltosState state, AltosListenerState listener_state) {
196 if (state == null || state.apogee_voltage == AltosLib.MISSING)
199 show("%4.2f V", state.apogee_voltage);
200 lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
203 public Apogee (GridBagLayout layout, int y) {
204 super(layout, y, "Apogee Igniter Voltage");
210 class Main extends LaunchStatus {
211 void show (AltosState state, AltosListenerState listener_state) {
212 if (state == null || state.main_voltage == AltosLib.MISSING)
215 show("%4.2f V", state.main_voltage);
216 lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
219 public Main (GridBagLayout layout, int y) {
220 super(layout, y, "Main Igniter Voltage");
226 class LoggingReady extends LaunchStatus {
227 void show (AltosState state, AltosListenerState listener_state) {
228 if (state == null || state.flight == AltosLib.MISSING) {
231 if (state.flight != 0) {
232 if (state.state <= Altos.ao_flight_pad)
233 show("Ready to record");
234 else if (state.state < Altos.ao_flight_landed)
235 show("Recording data");
237 show("Recorded data");
239 show("Storage full");
240 lights.set(state.flight != 0);
243 public LoggingReady (GridBagLayout layout, int y) {
244 super(layout, y, "On-board Data Logging");
248 LoggingReady logging_ready;
250 class GPSLocked extends LaunchStatus {
251 void show (AltosState state, AltosListenerState listener_state) {
252 if (state == null || state.gps == null)
255 show("%4d sats", state.gps.nsat);
256 lights.set(state.gps.locked && state.gps.nsat >= 4);
259 public GPSLocked (GridBagLayout layout, int y) {
260 super (layout, y, "GPS Locked");
264 GPSLocked gps_locked;
266 class GPSReady extends LaunchStatus {
267 void show (AltosState state, AltosListenerState listener_state) {
268 if (state == null || state.gps == null)
274 show("Waiting %d", state.gps_waiting);
275 lights.set(state.gps_ready);
278 public GPSReady (GridBagLayout layout, int y) {
279 super (layout, y, "GPS Ready");
285 class ReceiverBattery extends LaunchStatus {
286 void show (AltosState state, AltosListenerState listener_state) {
287 if (listener_state == null || listener_state.battery == AltosLib.MISSING)
290 show("%4.2f V", listener_state.battery);
291 lights.set(listener_state.battery > AltosLib.ao_battery_good);
294 public ReceiverBattery (GridBagLayout layout, int y) {
295 super(layout, y, "Receiver Battery");
299 ReceiverBattery receiver_battery;
301 String pos(double p, String pos, String neg) {
307 int deg = (int) Math.floor(p);
308 double min = (p - Math.floor(p)) * 60.0;
309 return String.format("%s %4d° %9.6f", h, deg, min);
312 class PadLat extends LaunchValue {
313 void show (AltosState state, AltosListenerState listener_state) {
314 double lat = AltosLib.MISSING;
318 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosLib.MISSING) {
323 label = "Pad Latitude";
326 if (lat != AltosLib.MISSING) {
327 show(pos(lat,"N", "S"));
332 public PadLat (GridBagLayout layout, int y) {
333 super (layout, y, "Pad Latitude");
339 class PadLon extends LaunchValue {
340 void show (AltosState state, AltosListenerState listener_state) {
341 double lon = AltosLib.MISSING;
345 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosLib.MISSING) {
350 label = "Pad Longitude";
353 if (lon != AltosLib.MISSING) {
354 show(pos(lon,"E", "W"));
359 public PadLon (GridBagLayout layout, int y) {
360 super (layout, y, "Pad Longitude");
366 class PadAlt extends LaunchValue {
367 void show (AltosState state, AltosListenerState listener_state) {
368 double alt = AltosLib.MISSING;
372 if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosLib.MISSING) {
377 label = "Pad Altitude";
380 if (alt != AltosLib.MISSING) {
381 show("%4.0f m", state.gps.alt);
386 public PadAlt (GridBagLayout layout, int y) {
387 super (layout, y, "Pad Altitude");
393 public void reset() {
397 logging_ready.reset();
400 receiver_battery.reset();
406 public void set_font() {
410 logging_ready.set_font();
411 gps_locked.set_font();
412 gps_ready.set_font();
413 receiver_battery.set_font();
419 public void show(AltosState state, AltosListenerState listener_state) {
420 battery.show(state, listener_state);
421 apogee.show(state, listener_state);
422 main.show(state, listener_state);
423 logging_ready.show(state, listener_state);
424 pad_alt.show(state, listener_state);
425 receiver_battery.show(state, listener_state);
426 gps_locked.show(state, listener_state);
427 gps_ready.show(state, listener_state);
428 pad_lat.show(state, listener_state);
429 pad_lon.show(state, listener_state);
433 layout = new GridBagLayout();
437 /* Elements in pad display:
447 battery = new Battery(layout, 0);
448 apogee = new Apogee(layout, 1);
449 main = new Main(layout, 2);
450 logging_ready = new LoggingReady(layout, 3);
451 gps_locked = new GPSLocked(layout, 4);
452 gps_ready = new GPSReady(layout, 5);
453 receiver_battery = new ReceiverBattery(layout, 6);
454 pad_lat = new PadLat(layout, 7);
455 pad_lon = new PadLon(layout, 8);
456 pad_alt = new PadAlt(layout, 9);