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();
50 lights = new AltosLights();
51 c.gridx = 0; c.gridy = y;
52 c.anchor = GridBagConstraints.CENTER;
53 c.fill = GridBagConstraints.CENTER;
54 layout.setConstraints(lights, c);
57 label = new JLabel(text);
58 label.setFont(label_font);
59 label.setHorizontalAlignment(SwingConstants.LEFT);
60 c.gridx = 1; c.gridy = y;
61 c.insets = new Insets(10, 10, 10, 10);
62 c.anchor = GridBagConstraints.WEST;
63 c.fill = GridBagConstraints.WEST;
64 layout.setConstraints(label, c);
67 value = new JTextField(15);
68 value.setFont(value_font);
69 value.setHorizontalAlignment(SwingConstants.RIGHT);
70 c.gridx = 2; c.gridy = y;
71 c.anchor = GridBagConstraints.WEST;
72 layout.setConstraints(value, c);
78 public class LaunchValue {
81 void show(AltosState state, int crc_errors) {}
86 public LaunchValue (GridBagLayout layout, int y, String text) {
87 GridBagConstraints c = new GridBagConstraints();
89 label = new JLabel(text);
90 label.setFont(label_font);
91 label.setHorizontalAlignment(SwingConstants.LEFT);
92 c.gridx = 1; c.gridy = y;
93 c.insets = new Insets(10, 10, 10, 10);
94 c.anchor = GridBagConstraints.WEST;
95 layout.setConstraints(label, c);
98 value = new JTextField(30);
99 value.setFont(value_font);
100 value.setHorizontalAlignment(SwingConstants.RIGHT);
101 c.gridx = 2; c.gridy = y;
102 c.anchor = GridBagConstraints.EAST;
103 c.fill = GridBagConstraints.HORIZONTAL;
104 layout.setConstraints(value, c);
109 class Battery extends LaunchStatus {
110 void show (AltosState state, int crc_errors) {
111 value.setText(String.format("%4.2f V", state.battery));
112 lights.set(state.battery > 3.7);
114 public Battery (GridBagLayout layout, int y) {
115 super(layout, y, "Battery Voltage");
121 class Apogee extends LaunchStatus {
122 void show (AltosState state, int crc_errors) {
123 value.setText(String.format("%4.2f V", state.drogue_sense));
124 lights.set(state.drogue_sense > 3.2);
126 public Apogee (GridBagLayout layout, int y) {
127 super(layout, y, "Apogee Igniter Voltage");
133 class Main extends LaunchStatus {
134 void show (AltosState state, int crc_errors) {
135 value.setText(String.format("%4.2f V", state.main_sense));
136 lights.set(state.main_sense > 3.2);
138 public Main (GridBagLayout layout, int y) {
139 super(layout, y, "Main Igniter Voltage");
145 class GPS extends LaunchStatus {
146 void show (AltosState state, int crc_errors) {
147 value.setText(String.format("%4d sats", state.gps.nsat));
148 lights.set(state.gps_ready);
150 public GPS (GridBagLayout layout, int y) {
151 super (layout, y, "GPS Status");
157 String pos(double p, String pos, String neg) {
163 int deg = (int) Math.floor(p);
164 double min = (p - Math.floor(p)) * 60.0;
165 return String.format("%s %4d° %9.6f", h, deg, min);
168 class PadLat extends LaunchValue {
169 void show (AltosState state, int crc_errors) {
170 value.setText(pos(state.pad_lat,"N", "S"));
172 public PadLat (GridBagLayout layout, int y) {
173 super (layout, y, "Pad Latitude");
179 class PadLon extends LaunchValue {
180 void show (AltosState state, int crc_errors) {
181 value.setText(pos(state.pad_lon,"E", "W"));
183 public PadLon (GridBagLayout layout, int y) {
184 super (layout, y, "Pad Longitude");
190 class PadAlt extends LaunchValue {
191 void show (AltosState state, int crc_errors) {
192 value.setText(String.format("%4.0f m", state.pad_alt));
194 public PadAlt (GridBagLayout layout, int y) {
195 super (layout, y, "Pad Altitude");
201 public void reset() {
211 public void show(AltosState state, int crc_errors) {
212 battery.show(state, crc_errors);
213 apogee.show(state, crc_errors);
214 main.show(state, crc_errors);
215 gps.show(state, crc_errors);
216 pad_lat.show(state, crc_errors);
217 pad_lon.show(state, crc_errors);
218 pad_alt.show(state, crc_errors);
222 layout = new GridBagLayout();
224 GridBagConstraints c;
226 label_font = new Font("Dialog", Font.PLAIN, 24);
227 value_font = new Font("Monospaced", Font.PLAIN, 24);
230 c = new GridBagConstraints();
231 /* Elements in pad display:
235 * GPS lock status and location
239 battery = new Battery(layout, 0);
240 apogee = new Apogee(layout, 1);
241 main = new Main(layout, 2);
242 gps = new GPS(layout, 3);
243 pad_lat = new PadLat(layout, 4);
244 pad_lon = new PadLon(layout, 5);
245 pad_alt = new PadAlt(layout, 6);