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 JLabel("4.00");
68 value.setFont(label_font);
69 value.setHorizontalAlignment(SwingConstants.RIGHT);
70 c.gridx = 2; c.gridy = y;
71 c.anchor = GridBagConstraints.EAST;
72 c.fill = GridBagConstraints.EAST;
73 layout.setConstraints(value, c);
79 public class LaunchValue {
82 void show(AltosState state, int crc_errors) {}
87 public LaunchValue (GridBagLayout layout, int y, String text) {
88 GridBagConstraints c = new GridBagConstraints();
90 label = new JLabel(text);
91 label.setFont(label_font);
92 label.setHorizontalAlignment(SwingConstants.LEFT);
93 c.gridx = 1; c.gridy = y;
94 c.insets = new Insets(10, 10, 10, 10);
95 c.anchor = GridBagConstraints.WEST;
96 c.fill = GridBagConstraints.WEST;
97 layout.setConstraints(label, c);
100 value = new JLabel("4.00");
101 value.setFont(label_font);
102 value.setHorizontalAlignment(SwingConstants.RIGHT);
103 c.gridx = 2; c.gridy = y;
104 c.anchor = GridBagConstraints.EAST;
105 c.fill = GridBagConstraints.EAST;
106 layout.setConstraints(value, c);
111 class Battery extends LaunchStatus {
112 void show (AltosState state, int crc_errors) {
113 value.setText(String.format("%4.2f V", state.battery));
114 lights.set(state.battery > 3.7);
116 public Battery (GridBagLayout layout, int y) {
117 super(layout, y, "Battery Voltage");
123 class Apogee extends LaunchStatus {
124 void show (AltosState state, int crc_errors) {
125 value.setText(String.format("%4.2f V", state.drogue_sense));
126 lights.set(state.drogue_sense > 3.2);
128 public Apogee (GridBagLayout layout, int y) {
129 super(layout, y, "Apogee Igniter Voltage");
135 class Main extends LaunchStatus {
136 void show (AltosState state, int crc_errors) {
137 value.setText(String.format("%4.2f V", state.main_sense));
138 lights.set(state.main_sense > 3.2);
140 public Main (GridBagLayout layout, int y) {
141 super(layout, y, "Main Igniter Voltage");
147 class GPS extends LaunchStatus {
148 void show (AltosState state, int crc_errors) {
149 value.setText(String.format("%4d sats", state.gps.nsat));
150 lights.set(state.gps_ready);
152 public GPS (GridBagLayout layout, int y) {
153 super (layout, y, "GPS Status");
159 String pos(double p, String pos, String neg) {
165 int deg = (int) Math.floor(p);
166 double min = (p - Math.floor(p)) * 60.0;
167 return String.format("%s %4d° %9.6f", h, deg, min);
170 class PadLat extends LaunchValue {
171 void show (AltosState state, int crc_errors) {
172 value.setText(pos(state.pad_lat,"N", "S"));
174 public PadLat (GridBagLayout layout, int y) {
175 super (layout, y, "Pad Latitude");
181 class PadLon extends LaunchValue {
182 void show (AltosState state, int crc_errors) {
183 value.setText(pos(state.pad_lon,"E", "W"));
185 public PadLon (GridBagLayout layout, int y) {
186 super (layout, y, "Pad Longitude");
192 class PadAlt extends LaunchValue {
193 void show (AltosState state, int crc_errors) {
194 value.setText(String.format("%4.0f m", state.pad_alt));
196 public PadAlt (GridBagLayout layout, int y) {
197 super (layout, y, "Pad Altitude");
203 public void reset() {
213 public void show(AltosState state, int crc_errors) {
214 battery.show(state, crc_errors);
215 apogee.show(state, crc_errors);
216 main.show(state, crc_errors);
217 gps.show(state, crc_errors);
218 pad_lat.show(state, crc_errors);
219 pad_lon.show(state, crc_errors);
220 pad_alt.show(state, crc_errors);
224 layout = new GridBagLayout();
226 GridBagConstraints c;
228 label_font = new Font("Dialog", Font.PLAIN, 24);
229 value_font = new Font("Monospaced", Font.PLAIN, 24);
232 c = new GridBagConstraints();
233 /* Elements in pad display:
237 * GPS lock status and location
241 battery = new Battery(layout, 0);
242 apogee = new Apogee(layout, 1);
243 main = new Main(layout, 2);
244 gps = new GPS(layout, 3);
245 pad_lat = new PadLat(layout, 4);
246 pad_lon = new PadLon(layout, 5);
247 pad_alt = new PadAlt(layout, 6);