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, int crc_errors) {}
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, int crc_errors) {}
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, int crc_errors) {
179 if (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, int crc_errors) {
195 show("%4.2f V", state.drogue_sense);
196 lights.set(state.drogue_sense > 3.2);
198 public Apogee (GridBagLayout layout, int y) {
199 super(layout, y, "Apogee Igniter Voltage");
205 class Main extends LaunchStatus {
206 void show (AltosState state, int crc_errors) {
207 show("%4.2f V", state.main_sense);
208 lights.set(state.main_sense > 3.2);
210 public Main (GridBagLayout layout, int y) {
211 super(layout, y, "Main Igniter Voltage");
217 class LoggingReady extends LaunchStatus {
218 void show (AltosState state, int crc_errors) {
219 if (state.data.flight != 0) {
220 if (state.data.state <= Altos.ao_flight_pad)
221 show("Ready to record");
222 else if (state.data.state < Altos.ao_flight_landed)
223 show("Recording data");
225 show("Recorded data");
228 show("Storage full");
229 lights.set(state.data.flight != 0);
231 public LoggingReady (GridBagLayout layout, int y) {
232 super(layout, y, "On-board Data Logging");
236 LoggingReady logging_ready;
238 class GPSLocked extends LaunchStatus {
239 void show (AltosState state, int crc_errors) {
240 show("%4d sats", state.gps.nsat);
241 lights.set(state.gps.locked && state.gps.nsat >= 4);
243 public GPSLocked (GridBagLayout layout, int y) {
244 super (layout, y, "GPS Locked");
248 GPSLocked gps_locked;
250 class GPSReady extends LaunchStatus {
251 void show (AltosState state, int crc_errors) {
255 show("Waiting %d", state.gps_waiting);
256 lights.set(state.gps_ready);
258 public GPSReady (GridBagLayout layout, int y) {
259 super (layout, y, "GPS Ready");
265 String pos(double p, String pos, String neg) {
271 int deg = (int) Math.floor(p);
272 double min = (p - Math.floor(p)) * 60.0;
273 return String.format("%s %4d° %9.6f", h, deg, min);
276 class PadLat extends LaunchValue {
277 void show (AltosState state, int crc_errors) {
278 if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
279 show(pos(state.gps.lat,"N", "S"));
280 set_label("Latitude");
282 show(pos(state.pad_lat,"N", "S"));
283 set_label("Pad Latitude");
286 public PadLat (GridBagLayout layout, int y) {
287 super (layout, y, "Pad Latitude");
293 class PadLon extends LaunchValue {
294 void show (AltosState state, int crc_errors) {
295 if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
296 show(pos(state.gps.lon,"E", "W"));
297 set_label("Longitude");
299 show(pos(state.pad_lon,"E", "W"));
300 set_label("Pad Longitude");
303 public PadLon (GridBagLayout layout, int y) {
304 super (layout, y, "Pad Longitude");
310 class PadAlt extends LaunchValue {
311 void show (AltosState state, int crc_errors) {
312 if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
313 show("%4.0f m", state.gps.alt);
314 set_label("Altitude");
316 if (state.pad_alt == AltosRecord.MISSING)
319 show("%4.0f m", state.pad_alt);
320 set_label("Pad Altitude");
324 public PadAlt (GridBagLayout layout, int y) {
325 super (layout, y, "Pad Altitude");
331 public void reset() {
335 logging_ready.reset();
343 public void set_font() {
347 logging_ready.set_font();
348 gps_locked.set_font();
349 gps_ready.set_font();
355 public void show(AltosState state, int crc_errors) {
356 battery.show(state, crc_errors);
357 if (state.drogue_sense == AltosRecord.MISSING)
360 apogee.show(state, crc_errors);
361 if (state.main_sense == AltosRecord.MISSING)
364 main.show(state, crc_errors);
365 logging_ready.show(state, crc_errors);
366 pad_alt.show(state, crc_errors);
367 if (state.gps != null && state.gps.connected) {
368 gps_locked.show(state, crc_errors);
369 gps_ready.show(state, crc_errors);
370 pad_lat.show(state, crc_errors);
371 pad_lon.show(state, crc_errors);
381 layout = new GridBagLayout();
385 /* Elements in pad display:
395 battery = new Battery(layout, 0);
396 apogee = new Apogee(layout, 1);
397 main = new Main(layout, 2);
398 logging_ready = new LoggingReady(layout, 3);
399 gps_locked = new GPSLocked(layout, 4);
400 gps_ready = new GPSReady(layout, 5);
401 pad_lat = new PadLat(layout, 6);
402 pad_lon = new PadLon(layout, 7);
403 pad_alt = new PadAlt(layout, 8);