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) {}
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 show("%4.2f V", state.battery);
172 lights.set(state.battery > 3.7);
174 public Battery (GridBagLayout layout, int y) {
175 super(layout, y, "Battery Voltage");
181 class Apogee extends LaunchStatus {
182 void show (AltosState state, int crc_errors) {
183 show("%4.2f V", state.drogue_sense);
184 lights.set(state.drogue_sense > 3.2);
186 public Apogee (GridBagLayout layout, int y) {
187 super(layout, y, "Apogee Igniter Voltage");
193 class Main extends LaunchStatus {
194 void show (AltosState state, int crc_errors) {
195 show("%4.2f V", state.main_sense);
196 lights.set(state.main_sense > 3.2);
198 public Main (GridBagLayout layout, int y) {
199 super(layout, y, "Main Igniter Voltage");
205 class LoggingReady extends LaunchStatus {
206 void show (AltosState state, int crc_errors) {
207 if (state.data.flight != 0) {
208 if (state.data.state <= Altos.ao_flight_pad)
209 show("Ready to record");
210 else if (state.data.state < Altos.ao_flight_landed)
211 show("Recording data");
213 show("Recorded data");
216 show("Storage full");
217 lights.set(state.data.flight != 0);
219 public LoggingReady (GridBagLayout layout, int y) {
220 super(layout, y, "On-board Data Logging");
224 LoggingReady logging_ready;
226 class GPSLocked extends LaunchStatus {
227 void show (AltosState state, int crc_errors) {
228 show("%4d sats", state.gps.nsat);
229 lights.set(state.gps.locked && state.gps.nsat >= 4);
231 public GPSLocked (GridBagLayout layout, int y) {
232 super (layout, y, "GPS Locked");
236 GPSLocked gps_locked;
238 class GPSReady extends LaunchStatus {
239 void show (AltosState state, int crc_errors) {
243 show("Waiting %d", state.gps_waiting);
244 lights.set(state.gps_ready);
246 public GPSReady (GridBagLayout layout, int y) {
247 super (layout, y, "GPS Ready");
253 String pos(double p, String pos, String neg) {
259 int deg = (int) Math.floor(p);
260 double min = (p - Math.floor(p)) * 60.0;
261 return String.format("%s %4d° %9.6f", h, deg, min);
264 class PadLat extends LaunchValue {
265 void show (AltosState state, int crc_errors) {
266 show(pos(state.pad_lat,"N", "S"));
268 public PadLat (GridBagLayout layout, int y) {
269 super (layout, y, "Pad Latitude");
275 class PadLon extends LaunchValue {
276 void show (AltosState state, int crc_errors) {
277 show(pos(state.pad_lon,"E", "W"));
279 public PadLon (GridBagLayout layout, int y) {
280 super (layout, y, "Pad Longitude");
286 class PadAlt extends LaunchValue {
287 void show (AltosState state, int crc_errors) {
288 show("%4.0f m", state.pad_alt);
290 public PadAlt (GridBagLayout layout, int y) {
291 super (layout, y, "Pad Altitude");
297 public void reset() {
301 logging_ready.reset();
309 public void set_font() {
313 logging_ready.set_font();
314 gps_locked.set_font();
315 gps_ready.set_font();
321 public void show(AltosState state, int crc_errors) {
322 battery.show(state, crc_errors);
323 if (state.drogue_sense == AltosRecord.MISSING)
326 apogee.show(state, crc_errors);
327 if (state.main_sense == AltosRecord.MISSING)
330 main.show(state, crc_errors);
331 logging_ready.show(state, crc_errors);
332 pad_alt.show(state, crc_errors);
333 if (state.gps != null && state.gps.connected) {
334 gps_locked.show(state, crc_errors);
335 gps_ready.show(state, crc_errors);
336 pad_lat.show(state, crc_errors);
337 pad_lon.show(state, crc_errors);
347 layout = new GridBagLayout();
351 /* Elements in pad display:
361 battery = new Battery(layout, 0);
362 apogee = new Apogee(layout, 1);
363 main = new Main(layout, 2);
364 logging_ready = new LoggingReady(layout, 3);
365 gps_locked = new GPSLocked(layout, 4);
366 gps_ready = new GPSReady(layout, 5);
367 pad_lat = new PadLat(layout, 6);
368 pad_lon = new PadLon(layout, 7);
369 pad_alt = new PadAlt(layout, 8);