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) {}
47 label.setVisible(true);
48 value.setVisible(true);
49 lights.setVisible(true);
53 label.setVisible(false);
54 value.setVisible(false);
55 lights.setVisible(false);
58 public void set_font() {
59 label.setFont(Altos.label_font);
60 value.setFont(Altos.value_font);
63 public LaunchStatus (GridBagLayout layout, int y, String text) {
64 GridBagConstraints c = new GridBagConstraints();
67 lights = new AltosLights();
68 c.gridx = 0; c.gridy = y;
69 c.anchor = GridBagConstraints.CENTER;
70 c.fill = GridBagConstraints.VERTICAL;
72 layout.setConstraints(lights, c);
75 label = new JLabel(text);
76 label.setFont(Altos.label_font);
77 label.setHorizontalAlignment(SwingConstants.LEFT);
78 c.gridx = 1; c.gridy = y;
79 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
80 c.anchor = GridBagConstraints.WEST;
81 c.fill = GridBagConstraints.VERTICAL;
83 layout.setConstraints(label, c);
86 value = new JTextField(Altos.text_width);
87 value.setFont(Altos.value_font);
88 value.setHorizontalAlignment(SwingConstants.RIGHT);
89 c.gridx = 2; c.gridy = y;
90 c.anchor = GridBagConstraints.WEST;
91 c.fill = GridBagConstraints.BOTH;
93 layout.setConstraints(value, c);
99 public class LaunchValue {
102 void show(AltosState state, int crc_errors) {}
105 label.setVisible(true);
106 value.setVisible(true);
110 label.setVisible(false);
111 value.setVisible(false);
114 public void set_font() {
115 label.setFont(Altos.label_font);
116 value.setFont(Altos.value_font);
122 public LaunchValue (GridBagLayout layout, int y, String text) {
123 GridBagConstraints c = new GridBagConstraints();
124 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
127 label = new JLabel(text);
128 label.setFont(Altos.label_font);
129 label.setHorizontalAlignment(SwingConstants.LEFT);
130 c.gridx = 1; c.gridy = y;
131 c.anchor = GridBagConstraints.WEST;
132 c.fill = GridBagConstraints.VERTICAL;
134 layout.setConstraints(label, c);
137 value = new JTextField(Altos.text_width);
138 value.setFont(Altos.value_font);
139 value.setHorizontalAlignment(SwingConstants.RIGHT);
140 c.gridx = 2; c.gridy = y;
141 c.anchor = GridBagConstraints.EAST;
142 c.fill = GridBagConstraints.BOTH;
144 layout.setConstraints(value, c);
149 class Battery extends LaunchStatus {
150 void show (AltosState state, int crc_errors) {
151 value.setText(String.format("%4.2f V", state.battery));
152 lights.set(state.battery > 3.7);
154 public Battery (GridBagLayout layout, int y) {
155 super(layout, y, "Battery Voltage");
161 class Apogee extends LaunchStatus {
162 void show (AltosState state, int crc_errors) {
164 value.setText(String.format("%4.2f V", state.drogue_sense));
165 lights.set(state.drogue_sense > 3.2);
167 public Apogee (GridBagLayout layout, int y) {
168 super(layout, y, "Apogee Igniter Voltage");
174 class Main extends LaunchStatus {
175 void show (AltosState state, int crc_errors) {
177 value.setText(String.format("%4.2f V", state.main_sense));
178 lights.set(state.main_sense > 3.2);
180 public Main (GridBagLayout layout, int y) {
181 super(layout, y, "Main Igniter Voltage");
187 class LoggingReady extends LaunchStatus {
188 void show (AltosState state, int crc_errors) {
190 if (state.data.flight != 0) {
191 if (state.data.state <= Altos.ao_flight_pad)
192 value.setText("Ready to record");
193 else if (state.data.state < Altos.ao_flight_landed)
194 value.setText("Recording data");
196 value.setText("Recorded data");
199 value.setText("Storage full");
200 lights.set(state.data.flight != 0);
202 public LoggingReady (GridBagLayout layout, int y) {
203 super(layout, y, "On-board Data Logging");
207 LoggingReady logging_ready;
209 class GPSLocked extends LaunchStatus {
210 void show (AltosState state, int crc_errors) {
212 value.setText(String.format("%4d sats", state.gps.nsat));
213 lights.set(state.gps.locked && state.gps.nsat >= 4);
215 public GPSLocked (GridBagLayout layout, int y) {
216 super (layout, y, "GPS Locked");
220 GPSLocked gps_locked;
222 class GPSReady extends LaunchStatus {
223 void show (AltosState state, int crc_errors) {
226 value.setText("Ready");
228 value.setText(String.format("Waiting %d", state.gps_waiting));
229 lights.set(state.gps_ready);
231 public GPSReady (GridBagLayout layout, int y) {
232 super (layout, y, "GPS Ready");
238 String pos(double p, String pos, String neg) {
244 int deg = (int) Math.floor(p);
245 double min = (p - Math.floor(p)) * 60.0;
246 return String.format("%s %4d° %9.6f", h, deg, min);
249 class PadLat extends LaunchValue {
250 void show (AltosState state, int crc_errors) {
252 value.setText(pos(state.pad_lat,"N", "S"));
254 public PadLat (GridBagLayout layout, int y) {
255 super (layout, y, "Pad Latitude");
261 class PadLon extends LaunchValue {
262 void show (AltosState state, int crc_errors) {
264 value.setText(pos(state.pad_lon,"E", "W"));
266 public PadLon (GridBagLayout layout, int y) {
267 super (layout, y, "Pad Longitude");
273 class PadAlt extends LaunchValue {
274 void show (AltosState state, int crc_errors) {
275 value.setText(String.format("%4.0f m", state.pad_alt));
277 public PadAlt (GridBagLayout layout, int y) {
278 super (layout, y, "Pad Altitude");
284 public void reset() {
288 logging_ready.reset();
296 public void set_font() {
300 logging_ready.set_font();
301 gps_locked.set_font();
302 gps_ready.set_font();
308 public void show(AltosState state, int crc_errors) {
309 battery.show(state, crc_errors);
310 if (state.drogue_sense == AltosRecord.MISSING)
313 apogee.show(state, crc_errors);
314 if (state.main_sense == AltosRecord.MISSING)
317 main.show(state, crc_errors);
318 logging_ready.show(state, crc_errors);
319 pad_alt.show(state, crc_errors);
320 if (state.gps != null && state.gps.connected) {
321 gps_locked.show(state, crc_errors);
322 gps_ready.show(state, crc_errors);
323 pad_lat.show(state, crc_errors);
324 pad_lon.show(state, crc_errors);
334 layout = new GridBagLayout();
338 /* Elements in pad display:
348 battery = new Battery(layout, 0);
349 apogee = new Apogee(layout, 1);
350 main = new Main(layout, 2);
351 logging_ready = new LoggingReady(layout, 3);
352 gps_locked = new GPSLocked(layout, 4);
353 gps_ready = new GPSReady(layout, 5);
354 pad_lat = new PadLat(layout, 6);
355 pad_lon = new PadLon(layout, 7);
356 pad_alt = new PadAlt(layout, 8);