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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosPad extends JComponent implements AltosFlightDisplay {
35 public class LaunchStatus {
40 void show(AltosState state, int crc_errors) {}
48 label.setVisible(true);
49 value.setVisible(true);
50 lights.setVisible(true);
58 void show(String format, double value) {
59 show(String.format(format, value));
62 void show(String format, int value) {
63 show(String.format(format, value));
67 label.setVisible(false);
68 value.setVisible(false);
69 lights.setVisible(false);
72 public void set_font() {
73 label.setFont(Altos.label_font);
74 value.setFont(Altos.value_font);
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.setFont(Altos.value_font);
102 value.setHorizontalAlignment(SwingConstants.RIGHT);
103 c.gridx = 2; c.gridy = y;
104 c.anchor = GridBagConstraints.WEST;
105 c.fill = GridBagConstraints.BOTH;
107 layout.setConstraints(value, c);
113 public class LaunchValue {
116 void show(AltosState state, int crc_errors) {}
119 label.setVisible(true);
120 value.setVisible(true);
124 label.setVisible(false);
125 value.setVisible(false);
128 public void set_font() {
129 label.setFont(Altos.label_font);
130 value.setFont(Altos.value_font);
133 void show(String s) {
138 void show(AltosUnits units, double v) {
139 show(units.show(8, v));
142 void show(String format, double v) {
143 show(String.format(format, v));
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 show("%4.2f V", state.battery);
180 lights.set(state.battery > 3.7);
182 public Battery (GridBagLayout layout, int y) {
183 super(layout, y, "Battery Voltage");
189 class Apogee extends LaunchStatus {
190 void show (AltosState state, int crc_errors) {
191 show("%4.2f V", state.drogue_sense);
192 lights.set(state.drogue_sense > 3.2);
194 public Apogee (GridBagLayout layout, int y) {
195 super(layout, y, "Apogee Igniter Voltage");
201 class Main extends LaunchStatus {
202 void show (AltosState state, int crc_errors) {
203 show("%4.2f V", state.main_sense);
204 lights.set(state.main_sense > 3.2);
206 public Main (GridBagLayout layout, int y) {
207 super(layout, y, "Main Igniter Voltage");
213 class LoggingReady extends LaunchStatus {
214 void show (AltosState state, int crc_errors) {
215 if (state.data.flight != 0) {
216 if (state.data.state <= Altos.ao_flight_pad)
217 show("Ready to record");
218 else if (state.data.state < Altos.ao_flight_landed)
219 show("Recording data");
221 show("Recorded data");
224 show("Storage full");
225 lights.set(state.data.flight != 0);
227 public LoggingReady (GridBagLayout layout, int y) {
228 super(layout, y, "On-board Data Logging");
232 LoggingReady logging_ready;
234 class GPSLocked extends LaunchStatus {
235 void show (AltosState state, int crc_errors) {
236 show("%4d sats", state.gps.nsat);
237 lights.set(state.gps.locked && state.gps.nsat >= 4);
239 public GPSLocked (GridBagLayout layout, int y) {
240 super (layout, y, "GPS Locked");
244 GPSLocked gps_locked;
246 class GPSReady extends LaunchStatus {
247 void show (AltosState state, int crc_errors) {
251 show("Waiting %d", state.gps_waiting);
252 lights.set(state.gps_ready);
254 public GPSReady (GridBagLayout layout, int y) {
255 super (layout, y, "GPS Ready");
261 String pos(double p, String pos, String neg) {
267 int deg = (int) Math.floor(p);
268 double min = (p - Math.floor(p)) * 60.0;
269 return String.format("%s %4d° %9.6f", h, deg, min);
272 class PadLat extends LaunchValue {
273 void show (AltosState state, int crc_errors) {
274 show(pos(state.pad_lat,"N", "S"));
276 public PadLat (GridBagLayout layout, int y) {
277 super (layout, y, "Pad Latitude");
283 class PadLon extends LaunchValue {
284 void show (AltosState state, int crc_errors) {
285 show(pos(state.pad_lon,"E", "W"));
287 public PadLon (GridBagLayout layout, int y) {
288 super (layout, y, "Pad Longitude");
294 class PadAlt extends LaunchValue {
295 void show (AltosState state, int crc_errors) {
296 show("%4.0f m", state.pad_alt);
298 public PadAlt (GridBagLayout layout, int y) {
299 super (layout, y, "Pad Altitude");
305 public void reset() {
309 logging_ready.reset();
317 public void set_font() {
321 logging_ready.set_font();
322 gps_locked.set_font();
323 gps_ready.set_font();
329 public void show(AltosState state, int crc_errors) {
330 battery.show(state, crc_errors);
331 if (state.drogue_sense == AltosRecord.MISSING)
334 apogee.show(state, crc_errors);
335 if (state.main_sense == AltosRecord.MISSING)
338 main.show(state, crc_errors);
339 logging_ready.show(state, crc_errors);
340 pad_alt.show(state, crc_errors);
341 if (state.gps != null && state.gps.connected) {
342 gps_locked.show(state, crc_errors);
343 gps_ready.show(state, crc_errors);
344 pad_lat.show(state, crc_errors);
345 pad_lon.show(state, crc_errors);
355 layout = new GridBagLayout();
359 /* Elements in pad display:
369 battery = new Battery(layout, 0);
370 apogee = new Apogee(layout, 1);
371 main = new Main(layout, 2);
372 logging_ready = new LoggingReady(layout, 3);
373 gps_locked = new GPSLocked(layout, 4);
374 gps_ready = new GPSReady(layout, 5);
375 pad_lat = new PadLat(layout, 6);
376 pad_lon = new PadLon(layout, 7);
377 pad_alt = new PadAlt(layout, 8);