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(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
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(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
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 GPSLocked 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.locked);
159 public GPSLocked (GridBagLayout layout, int y) {
160 super (layout, y, "GPS Locked");
164 GPSLocked gps_locked;
166 class GPSReady extends LaunchStatus {
167 void show (AltosState state, int crc_errors) {
169 value.setText("Ready");
171 value.setText(String.format("Waiting %d", state.gps_waiting));
172 lights.set(state.gps_ready);
174 public GPSReady (GridBagLayout layout, int y) {
175 super (layout, y, "GPS Ready");
181 String pos(double p, String pos, String neg) {
187 int deg = (int) Math.floor(p);
188 double min = (p - Math.floor(p)) * 60.0;
189 return String.format("%s %4d° %9.6f", h, deg, min);
192 class PadLat extends LaunchValue {
193 void show (AltosState state, int crc_errors) {
194 value.setText(pos(state.pad_lat,"N", "S"));
196 public PadLat (GridBagLayout layout, int y) {
197 super (layout, y, "Pad Latitude");
203 class PadLon extends LaunchValue {
204 void show (AltosState state, int crc_errors) {
205 value.setText(pos(state.pad_lon,"E", "W"));
207 public PadLon (GridBagLayout layout, int y) {
208 super (layout, y, "Pad Longitude");
214 class PadAlt extends LaunchValue {
215 void show (AltosState state, int crc_errors) {
216 value.setText(String.format("%4.0f m", state.pad_alt));
218 public PadAlt (GridBagLayout layout, int y) {
219 super (layout, y, "Pad Altitude");
225 public void reset() {
236 public void show(AltosState state, int crc_errors) {
237 battery.show(state, crc_errors);
238 apogee.show(state, crc_errors);
239 main.show(state, crc_errors);
240 gps_locked.show(state, crc_errors);
241 gps_ready.show(state, crc_errors);
242 pad_lat.show(state, crc_errors);
243 pad_lon.show(state, crc_errors);
244 pad_alt.show(state, crc_errors);
248 layout = new GridBagLayout();
250 label_font = new Font("Dialog", Font.PLAIN, 22);
251 value_font = new Font("Monospaced", Font.PLAIN, 22);
254 /* Elements in pad display:
264 battery = new Battery(layout, 0);
265 apogee = new Apogee(layout, 1);
266 main = new Main(layout, 2);
267 gps_locked = new GPSLocked(layout, 3);
268 gps_ready = new GPSReady(layout, 4);
269 pad_lat = new PadLat(layout, 5);
270 pad_lon = new PadLon(layout, 6);
271 pad_alt = new PadAlt(layout, 7);