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_1.*;
24 public class AltosPad extends JComponent implements AltosFlightDisplay {
27 public class LaunchStatus {
32 void show(AltosState state, AltosListenerState listener_state) {}
40 label.setVisible(true);
41 value.setVisible(true);
42 lights.setVisible(true);
50 void show(String format, double value) {
51 show(String.format(format, value));
54 void show(String format, int value) {
55 show(String.format(format, value));
59 label.setVisible(false);
60 value.setVisible(false);
61 lights.setVisible(false);
64 public void set_font() {
65 label.setFont(Altos.label_font);
66 value.setFont(Altos.value_font);
69 public void set_label(String text) {
73 public LaunchStatus (GridBagLayout layout, int y, String text) {
74 GridBagConstraints c = new GridBagConstraints();
77 lights = new AltosLights();
78 c.gridx = 0; c.gridy = y;
79 c.anchor = GridBagConstraints.CENTER;
80 c.fill = GridBagConstraints.VERTICAL;
82 layout.setConstraints(lights, c);
85 label = new JLabel(text);
86 label.setFont(Altos.label_font);
87 label.setHorizontalAlignment(SwingConstants.LEFT);
88 c.gridx = 1; c.gridy = y;
89 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
90 c.anchor = GridBagConstraints.WEST;
91 c.fill = GridBagConstraints.VERTICAL;
93 layout.setConstraints(label, c);
96 value = new JTextField(Altos.text_width);
97 value.setFont(Altos.value_font);
98 value.setHorizontalAlignment(SwingConstants.RIGHT);
99 c.gridx = 2; c.gridy = y;
100 c.anchor = GridBagConstraints.WEST;
101 c.fill = GridBagConstraints.BOTH;
103 layout.setConstraints(value, c);
109 public class LaunchValue {
112 void show(AltosState state, AltosListenerState listener_state) {}
115 label.setVisible(true);
116 value.setVisible(true);
120 label.setVisible(false);
121 value.setVisible(false);
124 public void set_font() {
125 label.setFont(Altos.label_font);
126 value.setFont(Altos.value_font);
129 void show(String s) {
134 void show(AltosUnits units, double v) {
135 show(units.show(8, v));
138 void show(String format, double v) {
139 show(String.format(format, v));
142 public void set_label(String text) {
150 public LaunchValue (GridBagLayout layout, int y, String text) {
151 GridBagConstraints c = new GridBagConstraints();
152 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
155 label = new JLabel(text);
156 label.setFont(Altos.label_font);
157 label.setHorizontalAlignment(SwingConstants.LEFT);
158 c.gridx = 1; c.gridy = y;
159 c.anchor = GridBagConstraints.WEST;
160 c.fill = GridBagConstraints.VERTICAL;
162 layout.setConstraints(label, c);
165 value = new JTextField(Altos.text_width);
166 value.setFont(Altos.value_font);
167 value.setHorizontalAlignment(SwingConstants.RIGHT);
168 c.gridx = 2; c.gridy = y;
169 c.anchor = GridBagConstraints.EAST;
170 c.fill = GridBagConstraints.BOTH;
172 layout.setConstraints(value, c);
177 class Battery extends LaunchStatus {
178 void show (AltosState state, AltosListenerState listener_state) {
179 if (state == null || state.battery == AltosRecord.MISSING)
182 show("%4.2f V", state.battery);
183 lights.set(state.battery > 3.7);
186 public Battery (GridBagLayout layout, int y) {
187 super(layout, y, "Battery Voltage");
193 class Apogee extends LaunchStatus {
194 void show (AltosState state, AltosListenerState listener_state) {
195 if (state == null || state.drogue_sense == AltosRecord.MISSING)
198 show("%4.2f V", state.drogue_sense);
199 lights.set(state.drogue_sense > 3.2);
202 public Apogee (GridBagLayout layout, int y) {
203 super(layout, y, "Apogee Igniter Voltage");
209 class Main extends LaunchStatus {
210 void show (AltosState state, AltosListenerState listener_state) {
211 if (state == null || state.main_sense == AltosRecord.MISSING)
214 show("%4.2f V", state.main_sense);
215 lights.set(state.main_sense > 3.2);
218 public Main (GridBagLayout layout, int y) {
219 super(layout, y, "Main Igniter Voltage");
225 class LoggingReady extends LaunchStatus {
226 void show (AltosState state, AltosListenerState listener_state) {
227 if (state == null || state.data.flight == AltosRecord.MISSING) {
230 if (state.data.flight != 0) {
231 if (state.data.state <= Altos.ao_flight_pad)
232 show("Ready to record");
233 else if (state.data.state < Altos.ao_flight_landed)
234 show("Recording data");
236 show("Recorded data");
238 show("Storage full");
239 lights.set(state.data.flight != 0);
242 public LoggingReady (GridBagLayout layout, int y) {
243 super(layout, y, "On-board Data Logging");
247 LoggingReady logging_ready;
249 class GPSLocked extends LaunchStatus {
250 void show (AltosState state, AltosListenerState listener_state) {
251 if (state == null || state.gps == null)
254 show("%4d sats", state.gps.nsat);
255 lights.set(state.gps.locked && state.gps.nsat >= 4);
258 public GPSLocked (GridBagLayout layout, int y) {
259 super (layout, y, "GPS Locked");
263 GPSLocked gps_locked;
265 class GPSReady extends LaunchStatus {
266 void show (AltosState state, AltosListenerState listener_state) {
267 if (state == null || state.gps == null)
273 show("Waiting %d", state.gps_waiting);
274 lights.set(state.gps_ready);
277 public GPSReady (GridBagLayout layout, int y) {
278 super (layout, y, "GPS Ready");
284 class ReceiverBattery extends LaunchStatus {
285 void show (AltosState state, AltosListenerState listener_state) {
286 if (listener_state == null || listener_state.battery == AltosRecord.MISSING)
289 show("%4.2f V", listener_state.battery);
290 lights.set(listener_state.battery > 3.7);
293 public ReceiverBattery (GridBagLayout layout, int y) {
294 super(layout, y, "Receiver Battery");
298 ReceiverBattery receiver_battery;
300 String pos(double p, String pos, String neg) {
306 int deg = (int) Math.floor(p);
307 double min = (p - Math.floor(p)) * 60.0;
308 return String.format("%s %4d° %9.6f", h, deg, min);
311 class PadLat extends LaunchValue {
312 void show (AltosState state, AltosListenerState listener_state) {
313 if (state == null || state.gps == null) {
316 if (state.state < AltosLib.ao_flight_pad) {
317 show(pos(state.gps.lat,"N", "S"));
318 set_label("Latitude");
320 show(pos(state.pad_lat,"N", "S"));
321 set_label("Pad Latitude");
325 public PadLat (GridBagLayout layout, int y) {
326 super (layout, y, "Pad Latitude");
332 class PadLon extends LaunchValue {
333 void show (AltosState state, AltosListenerState listener_state) {
334 if (state == null || state.gps == null) {
337 if (state.state < AltosLib.ao_flight_pad) {
338 show(pos(state.gps.lon,"E", "W"));
339 set_label("Longitude");
341 show(pos(state.pad_lon,"E", "W"));
342 set_label("Pad Longitude");
346 public PadLon (GridBagLayout layout, int y) {
347 super (layout, y, "Pad Longitude");
353 class PadAlt extends LaunchValue {
354 void show (AltosState state, AltosListenerState listener_state) {
358 if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
359 show("%4.0f m", state.gps.alt);
360 set_label("Altitude");
362 if (state.pad_alt == AltosRecord.MISSING)
365 show("%4.0f m", state.pad_alt);
366 set_label("Pad Altitude");
371 public PadAlt (GridBagLayout layout, int y) {
372 super (layout, y, "Pad Altitude");
378 public void reset() {
382 logging_ready.reset();
385 receiver_battery.reset();
391 public void set_font() {
395 logging_ready.set_font();
396 gps_locked.set_font();
397 gps_ready.set_font();
398 receiver_battery.set_font();
404 public void show(AltosState state, AltosListenerState listener_state) {
405 battery.show(state, listener_state);
406 apogee.show(state, listener_state);
407 main.show(state, listener_state);
408 logging_ready.show(state, listener_state);
409 pad_alt.show(state, listener_state);
410 receiver_battery.show(state, listener_state);
411 gps_locked.show(state, listener_state);
412 gps_ready.show(state, listener_state);
413 pad_lat.show(state, listener_state);
414 pad_lon.show(state, listener_state);
418 layout = new GridBagLayout();
422 /* Elements in pad display:
432 battery = new Battery(layout, 0);
433 apogee = new Apogee(layout, 1);
434 main = new Main(layout, 2);
435 logging_ready = new LoggingReady(layout, 3);
436 gps_locked = new GPSLocked(layout, 4);
437 gps_ready = new GPSReady(layout, 5);
438 receiver_battery = new ReceiverBattery(layout, 6);
439 pad_lat = new PadLat(layout, 7);
440 pad_lon = new PadLon(layout, 8);
441 pad_alt = new PadAlt(layout, 9);