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 LaunchStatus (GridBagLayout layout, int y, String text) {
58 GridBagConstraints c = new GridBagConstraints();
61 lights = new AltosLights();
62 c.gridx = 0; c.gridy = y;
63 c.anchor = GridBagConstraints.CENTER;
64 c.fill = GridBagConstraints.VERTICAL;
66 layout.setConstraints(lights, c);
69 label = new JLabel(text);
70 label.setFont(Altos.label_font);
71 label.setHorizontalAlignment(SwingConstants.LEFT);
72 c.gridx = 1; c.gridy = y;
73 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
74 c.anchor = GridBagConstraints.WEST;
75 c.fill = GridBagConstraints.VERTICAL;
77 layout.setConstraints(label, c);
80 value = new JTextField(Altos.text_width);
81 value.setFont(Altos.value_font);
82 value.setHorizontalAlignment(SwingConstants.RIGHT);
83 c.gridx = 2; c.gridy = y;
84 c.anchor = GridBagConstraints.WEST;
85 c.fill = GridBagConstraints.BOTH;
87 layout.setConstraints(value, c);
93 public class LaunchValue {
96 void show(AltosState state, int crc_errors) {}
99 label.setVisible(true);
100 value.setVisible(true);
104 label.setVisible(false);
105 value.setVisible(false);
111 public LaunchValue (GridBagLayout layout, int y, String text) {
112 GridBagConstraints c = new GridBagConstraints();
113 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
116 label = new JLabel(text);
117 label.setFont(Altos.label_font);
118 label.setHorizontalAlignment(SwingConstants.LEFT);
119 c.gridx = 1; c.gridy = y;
120 c.anchor = GridBagConstraints.WEST;
121 c.fill = GridBagConstraints.VERTICAL;
123 layout.setConstraints(label, c);
126 value = new JTextField(Altos.text_width);
127 value.setFont(Altos.value_font);
128 value.setHorizontalAlignment(SwingConstants.RIGHT);
129 c.gridx = 2; c.gridy = y;
130 c.anchor = GridBagConstraints.EAST;
131 c.fill = GridBagConstraints.BOTH;
133 layout.setConstraints(value, c);
138 class Battery extends LaunchStatus {
139 void show (AltosState state, int crc_errors) {
140 value.setText(String.format("%4.2f V", state.battery));
141 lights.set(state.battery > 3.7);
143 public Battery (GridBagLayout layout, int y) {
144 super(layout, y, "Battery Voltage");
150 class Apogee extends LaunchStatus {
151 void show (AltosState state, int crc_errors) {
153 value.setText(String.format("%4.2f V", state.drogue_sense));
154 lights.set(state.drogue_sense > 3.2);
156 public Apogee (GridBagLayout layout, int y) {
157 super(layout, y, "Apogee Igniter Voltage");
163 class Main extends LaunchStatus {
164 void show (AltosState state, int crc_errors) {
166 value.setText(String.format("%4.2f V", state.main_sense));
167 lights.set(state.main_sense > 3.2);
169 public Main (GridBagLayout layout, int y) {
170 super(layout, y, "Main Igniter Voltage");
176 class LoggingReady extends LaunchStatus {
177 void show (AltosState state, int crc_errors) {
179 if (state.data.flight != 0) {
180 if (state.data.state <= Altos.ao_flight_pad)
181 value.setText("Ready to record");
182 else if (state.data.state < Altos.ao_flight_landed)
183 value.setText("Recording data");
185 value.setText("Recorded data");
188 value.setText("Storage full");
189 lights.set(state.data.flight != 0);
191 public LoggingReady (GridBagLayout layout, int y) {
192 super(layout, y, "On-board Data Logging");
196 LoggingReady logging_ready;
198 class GPSLocked extends LaunchStatus {
199 void show (AltosState state, int crc_errors) {
201 value.setText(String.format("%4d sats", state.gps.nsat));
202 lights.set(state.gps.locked && state.gps.nsat >= 4);
204 public GPSLocked (GridBagLayout layout, int y) {
205 super (layout, y, "GPS Locked");
209 GPSLocked gps_locked;
211 class GPSReady extends LaunchStatus {
212 void show (AltosState state, int crc_errors) {
215 value.setText("Ready");
217 value.setText(String.format("Waiting %d", state.gps_waiting));
218 lights.set(state.gps_ready);
220 public GPSReady (GridBagLayout layout, int y) {
221 super (layout, y, "GPS Ready");
227 String pos(double p, String pos, String neg) {
233 int deg = (int) Math.floor(p);
234 double min = (p - Math.floor(p)) * 60.0;
235 return String.format("%s %4d° %9.6f", h, deg, min);
238 class PadLat extends LaunchValue {
239 void show (AltosState state, int crc_errors) {
241 value.setText(pos(state.pad_lat,"N", "S"));
243 public PadLat (GridBagLayout layout, int y) {
244 super (layout, y, "Pad Latitude");
250 class PadLon extends LaunchValue {
251 void show (AltosState state, int crc_errors) {
253 value.setText(pos(state.pad_lon,"E", "W"));
255 public PadLon (GridBagLayout layout, int y) {
256 super (layout, y, "Pad Longitude");
262 class PadAlt extends LaunchValue {
263 void show (AltosState state, int crc_errors) {
264 value.setText(String.format("%4.0f m", state.pad_alt));
266 public PadAlt (GridBagLayout layout, int y) {
267 super (layout, y, "Pad Altitude");
273 public void reset() {
277 logging_ready.reset();
285 public void show(AltosState state, int crc_errors) {
286 battery.show(state, crc_errors);
287 if (state.drogue_sense == AltosRecord.MISSING)
290 apogee.show(state, crc_errors);
291 if (state.main_sense == AltosRecord.MISSING)
294 main.show(state, crc_errors);
295 logging_ready.show(state, crc_errors);
296 pad_alt.show(state, crc_errors);
297 if (state.gps != null && state.gps.connected) {
298 gps_locked.show(state, crc_errors);
299 gps_ready.show(state, crc_errors);
300 pad_lat.show(state, crc_errors);
301 pad_lon.show(state, crc_errors);
311 layout = new GridBagLayout();
315 /* Elements in pad display:
325 battery = new Battery(layout, 0);
326 apogee = new Apogee(layout, 1);
327 main = new Main(layout, 2);
328 logging_ready = new LoggingReady(layout, 3);
329 gps_locked = new GPSLocked(layout, 4);
330 gps_ready = new GPSReady(layout, 5);
331 pad_lat = new PadLat(layout, 6);
332 pad_lon = new PadLon(layout, 7);
333 pad_alt = new PadAlt(layout, 8);