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) {}
45 public LaunchStatus (GridBagLayout layout, int y, String text) {
46 GridBagConstraints c = new GridBagConstraints();
49 lights = new AltosLights();
50 c.gridx = 0; c.gridy = y;
51 c.anchor = GridBagConstraints.CENTER;
52 c.fill = GridBagConstraints.VERTICAL;
54 layout.setConstraints(lights, c);
57 label = new JLabel(text);
58 label.setFont(Altos.label_font);
59 label.setHorizontalAlignment(SwingConstants.LEFT);
60 c.gridx = 1; c.gridy = y;
61 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
62 c.anchor = GridBagConstraints.WEST;
63 c.fill = GridBagConstraints.VERTICAL;
65 layout.setConstraints(label, c);
68 value = new JTextField(Altos.text_width);
69 value.setFont(Altos.value_font);
70 value.setHorizontalAlignment(SwingConstants.RIGHT);
71 c.gridx = 2; c.gridy = y;
72 c.anchor = GridBagConstraints.WEST;
73 c.fill = GridBagConstraints.BOTH;
75 layout.setConstraints(value, c);
81 public class LaunchValue {
84 void show(AltosState state, int crc_errors) {}
89 public LaunchValue (GridBagLayout layout, int y, String text) {
90 GridBagConstraints c = new GridBagConstraints();
91 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
94 label = new JLabel(text);
95 label.setFont(Altos.label_font);
96 label.setHorizontalAlignment(SwingConstants.LEFT);
97 c.gridx = 1; c.gridy = y;
98 c.anchor = GridBagConstraints.WEST;
99 c.fill = GridBagConstraints.VERTICAL;
101 layout.setConstraints(label, c);
104 value = new JTextField(Altos.text_width);
105 value.setFont(Altos.value_font);
106 value.setHorizontalAlignment(SwingConstants.RIGHT);
107 c.gridx = 2; c.gridy = y;
108 c.anchor = GridBagConstraints.EAST;
109 c.fill = GridBagConstraints.BOTH;
111 layout.setConstraints(value, c);
116 class Battery extends LaunchStatus {
117 void show (AltosState state, int crc_errors) {
118 value.setText(String.format("%4.2f V", state.battery));
119 lights.set(state.battery > 3.7);
121 public Battery (GridBagLayout layout, int y) {
122 super(layout, y, "Battery Voltage");
128 class Apogee extends LaunchStatus {
129 void show (AltosState state, int crc_errors) {
130 value.setText(String.format("%4.2f V", state.drogue_sense));
131 lights.set(state.drogue_sense > 3.2);
133 public Apogee (GridBagLayout layout, int y) {
134 super(layout, y, "Apogee Igniter Voltage");
140 class Main extends LaunchStatus {
141 void show (AltosState state, int crc_errors) {
142 value.setText(String.format("%4.2f V", state.main_sense));
143 lights.set(state.main_sense > 3.2);
145 public Main (GridBagLayout layout, int y) {
146 super(layout, y, "Main Igniter Voltage");
152 class GPSLocked extends LaunchStatus {
153 void show (AltosState state, int crc_errors) {
154 value.setText(String.format("%4d sats", state.gps.nsat));
155 lights.set(state.gps.locked && state.gps.nsat >= 4);
157 public GPSLocked (GridBagLayout layout, int y) {
158 super (layout, y, "GPS Locked");
162 GPSLocked gps_locked;
164 class GPSReady extends LaunchStatus {
165 void show (AltosState state, int crc_errors) {
167 value.setText("Ready");
169 value.setText(String.format("Waiting %d", state.gps_waiting));
170 lights.set(state.gps_ready);
172 public GPSReady (GridBagLayout layout, int y) {
173 super (layout, y, "GPS Ready");
179 String pos(double p, String pos, String neg) {
185 int deg = (int) Math.floor(p);
186 double min = (p - Math.floor(p)) * 60.0;
187 return String.format("%s %4d° %9.6f", h, deg, min);
190 class PadLat extends LaunchValue {
191 void show (AltosState state, int crc_errors) {
192 value.setText(pos(state.pad_lat,"N", "S"));
194 public PadLat (GridBagLayout layout, int y) {
195 super (layout, y, "Pad Latitude");
201 class PadLon extends LaunchValue {
202 void show (AltosState state, int crc_errors) {
203 value.setText(pos(state.pad_lon,"E", "W"));
205 public PadLon (GridBagLayout layout, int y) {
206 super (layout, y, "Pad Longitude");
212 class PadAlt extends LaunchValue {
213 void show (AltosState state, int crc_errors) {
214 value.setText(String.format("%4.0f m", state.pad_alt));
216 public PadAlt (GridBagLayout layout, int y) {
217 super (layout, y, "Pad Altitude");
223 public void reset() {
234 public void show(AltosState state, int crc_errors) {
235 battery.show(state, crc_errors);
236 apogee.show(state, crc_errors);
237 main.show(state, crc_errors);
238 gps_locked.show(state, crc_errors);
239 gps_ready.show(state, crc_errors);
240 pad_lat.show(state, crc_errors);
241 pad_lon.show(state, crc_errors);
242 pad_alt.show(state, crc_errors);
246 layout = new GridBagLayout();
250 /* Elements in pad display:
260 battery = new Battery(layout, 0);
261 apogee = new Apogee(layout, 1);
262 main = new Main(layout, 2);
263 gps_locked = new GPSLocked(layout, 3);
264 gps_ready = new GPSReady(layout, 4);
265 pad_lat = new PadLat(layout, 5);
266 pad_lon = new PadLon(layout, 6);
267 pad_alt = new PadAlt(layout, 7);