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.
22 import org.altusmetrum.AltosLib.*;
24 public class AltosPad extends JComponent implements AltosFlightDisplay {
27 public class LaunchStatus {
32 void show(AltosState state, int crc_errors) {}
39 label.setVisible(true);
40 value.setVisible(true);
41 lights.setVisible(true);
45 label.setVisible(false);
46 value.setVisible(false);
47 lights.setVisible(false);
50 public void set_font() {
51 label.setFont(Altos.label_font);
52 value.setFont(Altos.value_font);
55 public LaunchStatus (GridBagLayout layout, int y, String text) {
56 GridBagConstraints c = new GridBagConstraints();
59 lights = new AltosLights();
60 c.gridx = 0; c.gridy = y;
61 c.anchor = GridBagConstraints.CENTER;
62 c.fill = GridBagConstraints.VERTICAL;
64 layout.setConstraints(lights, c);
67 label = new JLabel(text);
68 label.setFont(Altos.label_font);
69 label.setHorizontalAlignment(SwingConstants.LEFT);
70 c.gridx = 1; c.gridy = y;
71 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
72 c.anchor = GridBagConstraints.WEST;
73 c.fill = GridBagConstraints.VERTICAL;
75 layout.setConstraints(label, c);
78 value = new JTextField(Altos.text_width);
79 value.setFont(Altos.value_font);
80 value.setHorizontalAlignment(SwingConstants.RIGHT);
81 c.gridx = 2; c.gridy = y;
82 c.anchor = GridBagConstraints.WEST;
83 c.fill = GridBagConstraints.BOTH;
85 layout.setConstraints(value, c);
91 public class LaunchValue {
94 void show(AltosState state, int crc_errors) {}
97 label.setVisible(true);
98 value.setVisible(true);
102 label.setVisible(false);
103 value.setVisible(false);
106 public void set_font() {
107 label.setFont(Altos.label_font);
108 value.setFont(Altos.value_font);
114 public LaunchValue (GridBagLayout layout, int y, String text) {
115 GridBagConstraints c = new GridBagConstraints();
116 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
119 label = new JLabel(text);
120 label.setFont(Altos.label_font);
121 label.setHorizontalAlignment(SwingConstants.LEFT);
122 c.gridx = 1; c.gridy = y;
123 c.anchor = GridBagConstraints.WEST;
124 c.fill = GridBagConstraints.VERTICAL;
126 layout.setConstraints(label, c);
129 value = new JTextField(Altos.text_width);
130 value.setFont(Altos.value_font);
131 value.setHorizontalAlignment(SwingConstants.RIGHT);
132 c.gridx = 2; c.gridy = y;
133 c.anchor = GridBagConstraints.EAST;
134 c.fill = GridBagConstraints.BOTH;
136 layout.setConstraints(value, c);
141 class Battery extends LaunchStatus {
142 void show (AltosState state, int crc_errors) {
143 value.setText(String.format("%4.2f V", state.battery));
144 lights.set(state.battery > 3.7);
146 public Battery (GridBagLayout layout, int y) {
147 super(layout, y, "Battery Voltage");
153 class Apogee extends LaunchStatus {
154 void show (AltosState state, int crc_errors) {
156 value.setText(String.format("%4.2f V", state.drogue_sense));
157 lights.set(state.drogue_sense > 3.2);
159 public Apogee (GridBagLayout layout, int y) {
160 super(layout, y, "Apogee Igniter Voltage");
166 class Main extends LaunchStatus {
167 void show (AltosState state, int crc_errors) {
169 value.setText(String.format("%4.2f V", state.main_sense));
170 lights.set(state.main_sense > 3.2);
172 public Main (GridBagLayout layout, int y) {
173 super(layout, y, "Main Igniter Voltage");
179 class LoggingReady extends LaunchStatus {
180 void show (AltosState state, int crc_errors) {
182 if (state.data.flight != 0) {
183 if (state.data.state <= Altos.ao_flight_pad)
184 value.setText("Ready to record");
185 else if (state.data.state < Altos.ao_flight_landed)
186 value.setText("Recording data");
188 value.setText("Recorded data");
191 value.setText("Storage full");
192 lights.set(state.data.flight != 0);
194 public LoggingReady (GridBagLayout layout, int y) {
195 super(layout, y, "On-board Data Logging");
199 LoggingReady logging_ready;
201 class GPSLocked extends LaunchStatus {
202 void show (AltosState state, int crc_errors) {
204 value.setText(String.format("%4d sats", state.gps.nsat));
205 lights.set(state.gps.locked && state.gps.nsat >= 4);
207 public GPSLocked (GridBagLayout layout, int y) {
208 super (layout, y, "GPS Locked");
212 GPSLocked gps_locked;
214 class GPSReady extends LaunchStatus {
215 void show (AltosState state, int crc_errors) {
218 value.setText("Ready");
220 value.setText(String.format("Waiting %d", state.gps_waiting));
221 lights.set(state.gps_ready);
223 public GPSReady (GridBagLayout layout, int y) {
224 super (layout, y, "GPS Ready");
230 String pos(double p, String pos, String neg) {
236 int deg = (int) Math.floor(p);
237 double min = (p - Math.floor(p)) * 60.0;
238 return String.format("%s %4d° %9.6f", h, deg, min);
241 class PadLat extends LaunchValue {
242 void show (AltosState state, int crc_errors) {
244 value.setText(pos(state.pad_lat,"N", "S"));
246 public PadLat (GridBagLayout layout, int y) {
247 super (layout, y, "Pad Latitude");
253 class PadLon extends LaunchValue {
254 void show (AltosState state, int crc_errors) {
256 value.setText(pos(state.pad_lon,"E", "W"));
258 public PadLon (GridBagLayout layout, int y) {
259 super (layout, y, "Pad Longitude");
265 class PadAlt extends LaunchValue {
266 void show (AltosState state, int crc_errors) {
267 value.setText(String.format("%4.0f m", state.pad_alt));
269 public PadAlt (GridBagLayout layout, int y) {
270 super (layout, y, "Pad Altitude");
276 public void reset() {
280 logging_ready.reset();
288 public void set_font() {
292 logging_ready.set_font();
293 gps_locked.set_font();
294 gps_ready.set_font();
300 public void show(AltosState state, int crc_errors) {
301 battery.show(state, crc_errors);
302 if (state.drogue_sense == AltosRecord.MISSING)
305 apogee.show(state, crc_errors);
306 if (state.main_sense == AltosRecord.MISSING)
309 main.show(state, crc_errors);
310 logging_ready.show(state, crc_errors);
311 pad_alt.show(state, crc_errors);
312 if (state.gps != null && state.gps.connected) {
313 gps_locked.show(state, crc_errors);
314 gps_ready.show(state, crc_errors);
315 pad_lat.show(state, crc_errors);
316 pad_lon.show(state, crc_errors);
326 layout = new GridBagLayout();
330 /* Elements in pad display:
340 battery = new Battery(layout, 0);
341 apogee = new Apogee(layout, 1);
342 main = new Main(layout, 2);
343 logging_ready = new LoggingReady(layout, 3);
344 gps_locked = new GPSLocked(layout, 4);
345 gps_ready = new GPSReady(layout, 5);
346 pad_lat = new PadLat(layout, 6);
347 pad_lon = new PadLon(layout, 7);
348 pad_alt = new PadAlt(layout, 8);