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;
31 public class AltosPad extends JComponent implements AltosFlightDisplay {
34 public class LaunchStatus {
39 void show(AltosState state, int crc_errors) {}
46 label.setVisible(true);
47 value.setVisible(true);
48 lights.setVisible(true);
52 label.setVisible(false);
53 value.setVisible(false);
54 lights.setVisible(false);
57 public void set_font() {
58 label.setFont(Altos.label_font);
59 value.setFont(Altos.value_font);
62 public LaunchStatus (GridBagLayout layout, int y, String text) {
63 GridBagConstraints c = new GridBagConstraints();
66 lights = new AltosLights();
67 c.gridx = 0; c.gridy = y;
68 c.anchor = GridBagConstraints.CENTER;
69 c.fill = GridBagConstraints.VERTICAL;
71 layout.setConstraints(lights, c);
74 label = new JLabel(text);
75 label.setFont(Altos.label_font);
76 label.setHorizontalAlignment(SwingConstants.LEFT);
77 c.gridx = 1; c.gridy = y;
78 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
79 c.anchor = GridBagConstraints.WEST;
80 c.fill = GridBagConstraints.VERTICAL;
82 layout.setConstraints(label, c);
85 value = new JTextField(Altos.text_width);
86 value.setFont(Altos.value_font);
87 value.setHorizontalAlignment(SwingConstants.RIGHT);
88 c.gridx = 2; c.gridy = y;
89 c.anchor = GridBagConstraints.WEST;
90 c.fill = GridBagConstraints.BOTH;
92 layout.setConstraints(value, c);
98 public class LaunchValue {
101 void show(AltosState state, int crc_errors) {}
104 label.setVisible(true);
105 value.setVisible(true);
109 label.setVisible(false);
110 value.setVisible(false);
113 public void set_font() {
114 label.setFont(Altos.label_font);
115 value.setFont(Altos.value_font);
121 public LaunchValue (GridBagLayout layout, int y, String text) {
122 GridBagConstraints c = new GridBagConstraints();
123 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
126 label = new JLabel(text);
127 label.setFont(Altos.label_font);
128 label.setHorizontalAlignment(SwingConstants.LEFT);
129 c.gridx = 1; c.gridy = y;
130 c.anchor = GridBagConstraints.WEST;
131 c.fill = GridBagConstraints.VERTICAL;
133 layout.setConstraints(label, c);
136 value = new JTextField(Altos.text_width);
137 value.setFont(Altos.value_font);
138 value.setHorizontalAlignment(SwingConstants.RIGHT);
139 c.gridx = 2; c.gridy = y;
140 c.anchor = GridBagConstraints.EAST;
141 c.fill = GridBagConstraints.BOTH;
143 layout.setConstraints(value, c);
148 class Battery extends LaunchStatus {
149 void show (AltosState state, int crc_errors) {
150 value.setText(String.format("%4.2f V", state.battery));
151 lights.set(state.battery > 3.7);
153 public Battery (GridBagLayout layout, int y) {
154 super(layout, y, "Battery Voltage");
160 class Apogee extends LaunchStatus {
161 void show (AltosState state, int crc_errors) {
163 value.setText(String.format("%4.2f V", state.drogue_sense));
164 lights.set(state.drogue_sense > 3.2);
166 public Apogee (GridBagLayout layout, int y) {
167 super(layout, y, "Apogee Igniter Voltage");
173 class Main extends LaunchStatus {
174 void show (AltosState state, int crc_errors) {
176 value.setText(String.format("%4.2f V", state.main_sense));
177 lights.set(state.main_sense > 3.2);
179 public Main (GridBagLayout layout, int y) {
180 super(layout, y, "Main Igniter Voltage");
186 class LoggingReady extends LaunchStatus {
187 void show (AltosState state, int crc_errors) {
189 if (state.data.flight != 0) {
190 if (state.data.state <= Altos.ao_flight_pad)
191 value.setText("Ready to record");
192 else if (state.data.state < Altos.ao_flight_landed)
193 value.setText("Recording data");
195 value.setText("Recorded data");
198 value.setText("Storage full");
199 lights.set(state.data.flight != 0);
201 public LoggingReady (GridBagLayout layout, int y) {
202 super(layout, y, "On-board Data Logging");
206 LoggingReady logging_ready;
208 class GPSLocked extends LaunchStatus {
209 void show (AltosState state, int crc_errors) {
211 value.setText(String.format("%4d sats", state.gps.nsat));
212 lights.set(state.gps.locked && state.gps.nsat >= 4);
214 public GPSLocked (GridBagLayout layout, int y) {
215 super (layout, y, "GPS Locked");
219 GPSLocked gps_locked;
221 class GPSReady extends LaunchStatus {
222 void show (AltosState state, int crc_errors) {
225 value.setText("Ready");
227 value.setText(String.format("Waiting %d", state.gps_waiting));
228 lights.set(state.gps_ready);
230 public GPSReady (GridBagLayout layout, int y) {
231 super (layout, y, "GPS Ready");
237 String pos(double p, String pos, String neg) {
243 int deg = (int) Math.floor(p);
244 double min = (p - Math.floor(p)) * 60.0;
245 return String.format("%s %4d° %9.6f", h, deg, min);
248 class PadLat extends LaunchValue {
249 void show (AltosState state, int crc_errors) {
251 value.setText(pos(state.pad_lat,"N", "S"));
253 public PadLat (GridBagLayout layout, int y) {
254 super (layout, y, "Pad Latitude");
260 class PadLon extends LaunchValue {
261 void show (AltosState state, int crc_errors) {
263 value.setText(pos(state.pad_lon,"E", "W"));
265 public PadLon (GridBagLayout layout, int y) {
266 super (layout, y, "Pad Longitude");
272 class PadAlt extends LaunchValue {
273 void show (AltosState state, int crc_errors) {
274 value.setText(String.format("%4.0f m", state.pad_alt));
276 public PadAlt (GridBagLayout layout, int y) {
277 super (layout, y, "Pad Altitude");
283 public void reset() {
287 logging_ready.reset();
295 public void set_font() {
299 logging_ready.set_font();
300 gps_locked.set_font();
301 gps_ready.set_font();
307 public void show(AltosState state, int crc_errors) {
308 battery.show(state, crc_errors);
309 if (state.drogue_sense == AltosRecord.MISSING)
312 apogee.show(state, crc_errors);
313 if (state.main_sense == AltosRecord.MISSING)
316 main.show(state, crc_errors);
317 logging_ready.show(state, crc_errors);
318 pad_alt.show(state, crc_errors);
319 if (state.gps != null && state.gps.connected) {
320 gps_locked.show(state, crc_errors);
321 gps_ready.show(state, crc_errors);
322 pad_lat.show(state, crc_errors);
323 pad_lon.show(state, crc_errors);
333 layout = new GridBagLayout();
337 /* Elements in pad display:
347 battery = new Battery(layout, 0);
348 apogee = new Apogee(layout, 1);
349 main = new Main(layout, 2);
350 logging_ready = new LoggingReady(layout, 3);
351 gps_locked = new GPSLocked(layout, 4);
352 gps_ready = new GPSReady(layout, 5);
353 pad_lat = new PadLat(layout, 6);
354 pad_lon = new PadLon(layout, 7);
355 pad_alt = new PadAlt(layout, 8);