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) {}
46 label.setVisible(true);
47 value.setVisible(true);
48 lights.setVisible(true);
52 label.setVisible(false);
53 value.setVisible(false);
54 lights.setVisible(false);
57 public LaunchStatus (GridBagLayout layout, int y, String text) {
58 GridBagConstraints c = new GridBagConstraints();
61 lights = new AltosLights();
62 c.gridx = 0; c.gridy = y;
63 c.anchor = GridBagConstraints.CENTER;
64 c.fill = GridBagConstraints.VERTICAL;
66 layout.setConstraints(lights, c);
69 label = new JLabel(text);
70 label.setFont(Altos.label_font);
71 label.setHorizontalAlignment(SwingConstants.LEFT);
72 c.gridx = 1; c.gridy = y;
73 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
74 c.anchor = GridBagConstraints.WEST;
75 c.fill = GridBagConstraints.VERTICAL;
77 layout.setConstraints(label, c);
80 value = new JTextField(Altos.text_width);
81 value.setFont(Altos.value_font);
82 value.setHorizontalAlignment(SwingConstants.RIGHT);
83 c.gridx = 2; c.gridy = y;
84 c.anchor = GridBagConstraints.WEST;
85 c.fill = GridBagConstraints.BOTH;
87 layout.setConstraints(value, c);
93 public class LaunchValue {
96 void show(AltosState state, int crc_errors) {}
99 label.setVisible(true);
100 value.setVisible(true);
104 label.setVisible(false);
105 value.setVisible(false);
111 public LaunchValue (GridBagLayout layout, int y, String text) {
112 GridBagConstraints c = new GridBagConstraints();
113 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
116 label = new JLabel(text);
117 label.setFont(Altos.label_font);
118 label.setHorizontalAlignment(SwingConstants.LEFT);
119 c.gridx = 1; c.gridy = y;
120 c.anchor = GridBagConstraints.WEST;
121 c.fill = GridBagConstraints.VERTICAL;
123 layout.setConstraints(label, c);
126 value = new JTextField(Altos.text_width);
127 value.setFont(Altos.value_font);
128 value.setHorizontalAlignment(SwingConstants.RIGHT);
129 c.gridx = 2; c.gridy = y;
130 c.anchor = GridBagConstraints.EAST;
131 c.fill = GridBagConstraints.BOTH;
133 layout.setConstraints(value, c);
138 class Battery extends LaunchStatus {
139 void show (AltosState state, int crc_errors) {
140 value.setText(String.format("%4.2f V", state.battery));
141 lights.set(state.battery > 3.7);
143 public Battery (GridBagLayout layout, int y) {
144 super(layout, y, "Battery Voltage");
150 class Apogee extends LaunchStatus {
151 void show (AltosState state, int crc_errors) {
152 value.setText(String.format("%4.2f V", state.drogue_sense));
153 lights.set(state.drogue_sense > 3.2);
155 public Apogee (GridBagLayout layout, int y) {
156 super(layout, y, "Apogee Igniter Voltage");
162 class Main extends LaunchStatus {
163 void show (AltosState state, int crc_errors) {
164 value.setText(String.format("%4.2f V", state.main_sense));
165 lights.set(state.main_sense > 3.2);
167 public Main (GridBagLayout layout, int y) {
168 super(layout, y, "Main Igniter Voltage");
174 class GPSLocked extends LaunchStatus {
175 void show (AltosState state, int crc_errors) {
177 value.setText(String.format("%4d sats", state.gps.nsat));
178 lights.set(state.gps.locked && state.gps.nsat >= 4);
180 public GPSLocked (GridBagLayout layout, int y) {
181 super (layout, y, "GPS Locked");
185 GPSLocked gps_locked;
187 class GPSReady extends LaunchStatus {
188 void show (AltosState state, int crc_errors) {
191 value.setText("Ready");
193 value.setText(String.format("Waiting %d", state.gps_waiting));
194 lights.set(state.gps_ready);
196 public GPSReady (GridBagLayout layout, int y) {
197 super (layout, y, "GPS Ready");
203 String pos(double p, String pos, String neg) {
209 int deg = (int) Math.floor(p);
210 double min = (p - Math.floor(p)) * 60.0;
211 return String.format("%s %4d° %9.6f", h, deg, min);
214 class PadLat extends LaunchValue {
215 void show (AltosState state, int crc_errors) {
217 value.setText(pos(state.pad_lat,"N", "S"));
219 public PadLat (GridBagLayout layout, int y) {
220 super (layout, y, "Pad Latitude");
226 class PadLon extends LaunchValue {
227 void show (AltosState state, int crc_errors) {
229 value.setText(pos(state.pad_lon,"E", "W"));
231 public PadLon (GridBagLayout layout, int y) {
232 super (layout, y, "Pad Longitude");
238 class PadAlt extends LaunchValue {
239 void show (AltosState state, int crc_errors) {
240 value.setText(String.format("%4.0f m", state.pad_alt));
242 public PadAlt (GridBagLayout layout, int y) {
243 super (layout, y, "Pad Altitude");
249 public void reset() {
260 public void show(AltosState state, int crc_errors) {
261 battery.show(state, crc_errors);
262 apogee.show(state, crc_errors);
263 main.show(state, crc_errors);
264 pad_alt.show(state, crc_errors);
265 if (state.gps != null) {
266 gps_locked.show(state, crc_errors);
267 gps_ready.show(state, crc_errors);
268 pad_lat.show(state, crc_errors);
269 pad_lon.show(state, crc_errors);
279 layout = new GridBagLayout();
283 /* Elements in pad display:
293 battery = new Battery(layout, 0);
294 apogee = new Apogee(layout, 1);
295 main = new Main(layout, 2);
296 gps_locked = new GPSLocked(layout, 3);
297 gps_ready = new GPSReady(layout, 4);
298 pad_lat = new PadLat(layout, 5);
299 pad_lon = new PadLon(layout, 6);
300 pad_alt = new PadAlt(layout, 7);