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 {
36 public class LaunchStatus {
41 void show(AltosState state, int crc_errors) {}
47 public LaunchStatus (GridBagLayout layout, int y, String text) {
48 GridBagConstraints c = new GridBagConstraints();
51 lights = new AltosLights();
52 c.gridx = 0; c.gridy = y;
53 c.anchor = GridBagConstraints.CENTER;
54 c.fill = GridBagConstraints.VERTICAL;
56 layout.setConstraints(lights, c);
59 label = new JLabel(text);
60 label.setFont(label_font);
61 label.setHorizontalAlignment(SwingConstants.LEFT);
62 c.gridx = 1; c.gridy = y;
63 c.insets = new Insets(10, 10, 10, 10);
64 c.anchor = GridBagConstraints.WEST;
65 c.fill = GridBagConstraints.VERTICAL;
67 layout.setConstraints(label, c);
70 value = new JTextField(15);
71 value.setFont(value_font);
72 value.setHorizontalAlignment(SwingConstants.RIGHT);
73 c.gridx = 2; c.gridy = y;
74 c.anchor = GridBagConstraints.WEST;
75 c.fill = GridBagConstraints.BOTH;
77 layout.setConstraints(value, c);
83 public class LaunchValue {
86 void show(AltosState state, int crc_errors) {}
91 public LaunchValue (GridBagLayout layout, int y, String text) {
92 GridBagConstraints c = new GridBagConstraints();
93 c.insets = new Insets(10, 10, 10, 10);
96 label = new JLabel(text);
97 label.setFont(label_font);
98 label.setHorizontalAlignment(SwingConstants.LEFT);
99 c.gridx = 1; c.gridy = y;
100 c.anchor = GridBagConstraints.WEST;
101 c.fill = GridBagConstraints.VERTICAL;
103 layout.setConstraints(label, c);
106 value = new JTextField(30);
107 value.setFont(value_font);
108 value.setHorizontalAlignment(SwingConstants.RIGHT);
109 c.gridx = 2; c.gridy = y;
110 c.anchor = GridBagConstraints.EAST;
111 c.fill = GridBagConstraints.BOTH;
113 layout.setConstraints(value, c);
118 class Battery extends LaunchStatus {
119 void show (AltosState state, int crc_errors) {
120 value.setText(String.format("%4.2f V", state.battery));
121 lights.set(state.battery > 3.7);
123 public Battery (GridBagLayout layout, int y) {
124 super(layout, y, "Battery Voltage");
130 class Apogee extends LaunchStatus {
131 void show (AltosState state, int crc_errors) {
132 value.setText(String.format("%4.2f V", state.drogue_sense));
133 lights.set(state.drogue_sense > 3.2);
135 public Apogee (GridBagLayout layout, int y) {
136 super(layout, y, "Apogee Igniter Voltage");
142 class Main extends LaunchStatus {
143 void show (AltosState state, int crc_errors) {
144 value.setText(String.format("%4.2f V", state.main_sense));
145 lights.set(state.main_sense > 3.2);
147 public Main (GridBagLayout layout, int y) {
148 super(layout, y, "Main Igniter Voltage");
154 class GPS extends LaunchStatus {
155 void show (AltosState state, int crc_errors) {
156 value.setText(String.format("%4d sats", state.gps.nsat));
157 lights.set(state.gps_ready);
159 public GPS (GridBagLayout layout, int y) {
160 super (layout, y, "GPS Status");
166 String pos(double p, String pos, String neg) {
172 int deg = (int) Math.floor(p);
173 double min = (p - Math.floor(p)) * 60.0;
174 return String.format("%s %4d° %9.6f", h, deg, min);
177 class PadLat extends LaunchValue {
178 void show (AltosState state, int crc_errors) {
179 value.setText(pos(state.pad_lat,"N", "S"));
181 public PadLat (GridBagLayout layout, int y) {
182 super (layout, y, "Pad Latitude");
188 class PadLon extends LaunchValue {
189 void show (AltosState state, int crc_errors) {
190 value.setText(pos(state.pad_lon,"E", "W"));
192 public PadLon (GridBagLayout layout, int y) {
193 super (layout, y, "Pad Longitude");
199 class PadAlt extends LaunchValue {
200 void show (AltosState state, int crc_errors) {
201 value.setText(String.format("%4.0f m", state.pad_alt));
203 public PadAlt (GridBagLayout layout, int y) {
204 super (layout, y, "Pad Altitude");
210 public void reset() {
220 public void show(AltosState state, int crc_errors) {
221 battery.show(state, crc_errors);
222 apogee.show(state, crc_errors);
223 main.show(state, crc_errors);
224 gps.show(state, crc_errors);
225 pad_lat.show(state, crc_errors);
226 pad_lon.show(state, crc_errors);
227 pad_alt.show(state, crc_errors);
231 layout = new GridBagLayout();
233 label_font = new Font("Dialog", Font.PLAIN, 24);
234 value_font = new Font("Monospaced", Font.PLAIN, 24);
237 /* Elements in pad display:
241 * GPS lock status and location
245 battery = new Battery(layout, 0);
246 apogee = new Apogee(layout, 1);
247 main = new Main(layout, 2);
248 gps = new GPS(layout, 3);
249 pad_lat = new PadLat(layout, 4);
250 pad_lon = new PadLon(layout, 5);
251 pad_alt = new PadAlt(layout, 6);