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_1.*;
24 public class AltosPad extends JComponent implements AltosFlightDisplay {
27 public class LaunchStatus {
32 void show(AltosState state, int crc_errors) {}
40 label.setVisible(true);
41 value.setVisible(true);
42 lights.setVisible(true);
50 void show(String format, double value) {
51 show(String.format(format, value));
54 void show(String format, int value) {
55 show(String.format(format, value));
59 label.setVisible(false);
60 value.setVisible(false);
61 lights.setVisible(false);
64 public void set_font() {
65 label.setFont(Altos.label_font);
66 value.setFont(Altos.value_font);
69 public LaunchStatus (GridBagLayout layout, int y, String text) {
70 GridBagConstraints c = new GridBagConstraints();
73 lights = new AltosLights();
74 c.gridx = 0; c.gridy = y;
75 c.anchor = GridBagConstraints.CENTER;
76 c.fill = GridBagConstraints.VERTICAL;
78 layout.setConstraints(lights, c);
81 label = new JLabel(text);
82 label.setFont(Altos.label_font);
83 label.setHorizontalAlignment(SwingConstants.LEFT);
84 c.gridx = 1; c.gridy = y;
85 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
86 c.anchor = GridBagConstraints.WEST;
87 c.fill = GridBagConstraints.VERTICAL;
89 layout.setConstraints(label, c);
92 value = new JTextField(Altos.text_width);
93 value.setFont(Altos.value_font);
94 value.setHorizontalAlignment(SwingConstants.RIGHT);
95 c.gridx = 2; c.gridy = y;
96 c.anchor = GridBagConstraints.WEST;
97 c.fill = GridBagConstraints.BOTH;
99 layout.setConstraints(value, c);
105 public class LaunchValue {
108 void show(AltosState state, int crc_errors) {}
111 label.setVisible(true);
112 value.setVisible(true);
116 label.setVisible(false);
117 value.setVisible(false);
120 public void set_font() {
121 label.setFont(Altos.label_font);
122 value.setFont(Altos.value_font);
125 void show(String s) {
130 void show(AltosUnits units, double v) {
131 show(units.show(8, v));
134 void show(String format, double v) {
135 show(String.format(format, v));
142 public LaunchValue (GridBagLayout layout, int y, String text) {
143 GridBagConstraints c = new GridBagConstraints();
144 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
147 label = new JLabel(text);
148 label.setFont(Altos.label_font);
149 label.setHorizontalAlignment(SwingConstants.LEFT);
150 c.gridx = 1; c.gridy = y;
151 c.anchor = GridBagConstraints.WEST;
152 c.fill = GridBagConstraints.VERTICAL;
154 layout.setConstraints(label, c);
157 value = new JTextField(Altos.text_width);
158 value.setFont(Altos.value_font);
159 value.setHorizontalAlignment(SwingConstants.RIGHT);
160 c.gridx = 2; c.gridy = y;
161 c.anchor = GridBagConstraints.EAST;
162 c.fill = GridBagConstraints.BOTH;
164 layout.setConstraints(value, c);
169 class Battery extends LaunchStatus {
170 void show (AltosState state, int crc_errors) {
171 if (state.battery == AltosRecord.MISSING)
174 show("%4.2f V", state.battery);
175 lights.set(state.battery > 3.7);
178 public Battery (GridBagLayout layout, int y) {
179 super(layout, y, "Battery Voltage");
185 class Apogee extends LaunchStatus {
186 void show (AltosState state, int crc_errors) {
187 show("%4.2f V", state.drogue_sense);
188 lights.set(state.drogue_sense > 3.2);
190 public Apogee (GridBagLayout layout, int y) {
191 super(layout, y, "Apogee Igniter Voltage");
197 class Main extends LaunchStatus {
198 void show (AltosState state, int crc_errors) {
199 show("%4.2f V", state.main_sense);
200 lights.set(state.main_sense > 3.2);
202 public Main (GridBagLayout layout, int y) {
203 super(layout, y, "Main Igniter Voltage");
209 class LoggingReady extends LaunchStatus {
210 void show (AltosState state, int crc_errors) {
211 if (state.data.flight != 0) {
212 if (state.data.state <= Altos.ao_flight_pad)
213 show("Ready to record");
214 else if (state.data.state < Altos.ao_flight_landed)
215 show("Recording data");
217 show("Recorded data");
220 show("Storage full");
221 lights.set(state.data.flight != 0);
223 public LoggingReady (GridBagLayout layout, int y) {
224 super(layout, y, "On-board Data Logging");
228 LoggingReady logging_ready;
230 class GPSLocked extends LaunchStatus {
231 void show (AltosState state, int crc_errors) {
232 show("%4d sats", state.gps.nsat);
233 lights.set(state.gps.locked && state.gps.nsat >= 4);
235 public GPSLocked (GridBagLayout layout, int y) {
236 super (layout, y, "GPS Locked");
240 GPSLocked gps_locked;
242 class GPSReady extends LaunchStatus {
243 void show (AltosState state, int crc_errors) {
247 show("Waiting %d", state.gps_waiting);
248 lights.set(state.gps_ready);
250 public GPSReady (GridBagLayout layout, int y) {
251 super (layout, y, "GPS Ready");
257 String pos(double p, String pos, String neg) {
263 int deg = (int) Math.floor(p);
264 double min = (p - Math.floor(p)) * 60.0;
265 return String.format("%s %4d° %9.6f", h, deg, min);
268 class PadLat extends LaunchValue {
269 void show (AltosState state, int crc_errors) {
270 show(pos(state.pad_lat,"N", "S"));
272 public PadLat (GridBagLayout layout, int y) {
273 super (layout, y, "Pad Latitude");
279 class PadLon extends LaunchValue {
280 void show (AltosState state, int crc_errors) {
281 show(pos(state.pad_lon,"E", "W"));
283 public PadLon (GridBagLayout layout, int y) {
284 super (layout, y, "Pad Longitude");
290 class PadAlt extends LaunchValue {
291 void show (AltosState state, int crc_errors) {
292 if (state.pad_alt == AltosRecord.MISSING)
295 show("%4.0f m", state.pad_alt);
297 public PadAlt (GridBagLayout layout, int y) {
298 super (layout, y, "Pad Altitude");
304 public void reset() {
308 logging_ready.reset();
316 public void set_font() {
320 logging_ready.set_font();
321 gps_locked.set_font();
322 gps_ready.set_font();
328 public void show(AltosState state, int crc_errors) {
329 battery.show(state, crc_errors);
330 if (state.drogue_sense == AltosRecord.MISSING)
333 apogee.show(state, crc_errors);
334 if (state.main_sense == AltosRecord.MISSING)
337 main.show(state, crc_errors);
338 logging_ready.show(state, crc_errors);
339 pad_alt.show(state, crc_errors);
340 if (state.gps != null && state.gps.connected) {
341 gps_locked.show(state, crc_errors);
342 gps_ready.show(state, crc_errors);
343 pad_lat.show(state, crc_errors);
344 pad_lon.show(state, crc_errors);
354 layout = new GridBagLayout();
358 /* Elements in pad display:
368 battery = new Battery(layout, 0);
369 apogee = new Apogee(layout, 1);
370 main = new Main(layout, 2);
371 logging_ready = new LoggingReady(layout, 3);
372 gps_locked = new GPSLocked(layout, 4);
373 gps_ready = new GPSReady(layout, 5);
374 pad_lat = new PadLat(layout, 6);
375 pad_lon = new PadLon(layout, 7);
376 pad_alt = new PadAlt(layout, 8);