2 * Copyright © 2014 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.
18 package org.altusmetrum.telegps;
22 import java.awt.event.*;
24 import org.altusmetrum.altoslib_11.*;
25 import org.altusmetrum.altosuilib_11.*;
27 public class TeleGPSState extends AltosUIFlightTab {
31 abstract class Value extends AltosUIUnitsIndicator {
32 public Value (Container container, int y, AltosUnits units, String text) {
33 super(container, y, units, text, 1, false, 2);
37 abstract class DualValue extends AltosUIUnitsIndicator {
38 public DualValue (Container container, int y, AltosUnits units, String text) {
39 super(container, y, units, text, 2, false, 1);
43 abstract class ValueHold extends DualValue {
44 public ValueHold (Container container, int y, AltosUnits units, String text) {
45 super(container, y, units, text);
49 class Height extends ValueHold {
50 public double value(AltosState state, int i) {
52 return state.height();
54 return state.max_height();
57 public Height(Container container, int y) {
58 super(container, y, AltosConvert.height, "Height");
62 class Speed extends ValueHold {
63 public double value(AltosState state, int i) {
65 return state.gps_speed();
67 return state.max_gps_speed();
70 public Speed(Container container, int y) {
71 super(container, y, AltosConvert.speed, "Speed");
75 class Distance extends Value {
76 public double value(AltosState state, int i) {
77 if (state.from_pad != null)
78 return state.from_pad.distance;
80 return AltosLib.MISSING;
83 public Distance(Container container, int y) {
84 super(container, y, AltosConvert.distance, "Distance");
88 class Range extends Value {
89 public double value(AltosState state, int i) {
92 public Range (Container container, int y) {
93 super (container, y, AltosConvert.distance, "Range");
97 class Bearing extends AltosUIIndicator {
98 public void show (AltosState state, AltosListenerState listener_state) {
99 if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
100 show( String.format("%3.0f°", state.from_pad.bearing),
101 state.from_pad.bearing_words(
102 AltosGreatCircle.BEARING_LONG));
104 show("Missing", "Missing");
107 public Bearing (Container container, int y) {
108 super (container, y, "Bearing", 2, false, 1);
112 class Elevation extends AltosUIIndicator {
113 public void show (AltosState state, AltosListenerState listener_state) {
114 if (state.elevation == AltosLib.MISSING)
117 show("%3.0f°", state.elevation);
119 public Elevation (Container container, int y) {
120 super (container, y, "Elevation", 1, false, 2);
124 class FirmwareVersion extends AltosUIIndicator {
125 public void show(AltosState state, AltosListenerState listener_state) {
126 if (state.firmware_version == null)
129 show(state.firmware_version);
132 public FirmwareVersion(Container container, int y) {
133 super(container, y, "Firmware Version", 1, false, 2);
137 class FlightLogMax extends AltosUIIndicator {
138 public void show(AltosState state, AltosListenerState listener_state) {
139 int storage = state.flight_log_max;
140 if (storage == AltosLib.MISSING)
141 storage = state.log_space >> 10;
142 if (storage == AltosLib.MISSING)
145 show(String.format("%dkB", storage));
148 public FlightLogMax(Container container, int y) {
149 super(container, y, "Flight Log Storage", 1, false, 2);
153 class BatteryVoltage extends AltosUIVoltageIndicator {
154 public double voltage(AltosState state) {
155 return state.battery_voltage;
158 public double good() {
159 return AltosLib.ao_battery_good;
162 public BatteryVoltage(Container container, int y) {
163 super(container, y, "Battery Voltage", 2);
167 class ReceiverBattery extends AltosUIVoltageIndicator {
169 public double voltage(AltosState state) { return AltosLib.MISSING; }
171 public double good() { return AltosLib.ao_battery_good; }
173 public boolean hide(AltosState state, AltosListenerState listener_state, int i) {
174 return value(state, listener_state, i) == AltosLib.MISSING;
177 public double value(AltosState state, AltosListenerState listener_state, int i) {
178 if (listener_state == null)
179 return AltosLib.MISSING;
180 return listener_state.battery;
183 public ReceiverBattery (AltosUIFlightTab container, int y) {
184 super(container, y, "Receiver Battery", 2);
188 public void labels(Container container, int y) {
189 GridBagLayout layout = (GridBagLayout)(container.getLayout());
190 GridBagConstraints c;
192 cur = new JLabel("Current");
193 cur.setFont(AltosUILib.label_font);
194 c = new GridBagConstraints();
195 c.gridx = 2; c.gridy = y;
196 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
197 layout.setConstraints(cur, c);
200 max = new JLabel("Maximum");
201 max.setFont(AltosUILib.label_font);
202 c.gridx = 3; c.gridy = y;
203 layout.setConstraints(max, c);
207 public void font_size_changed(int font_size) {
208 cur.setFont(AltosUILib.label_font);
209 max.setFont(AltosUILib.label_font);
210 super.font_size_changed(font_size);
213 public String getName() {
217 public TeleGPSState() {
220 add(new Height(this, y++));
221 add(new Speed(this, y++));
222 add(new Distance(this, y++));
223 add(new Range(this, y++));
224 add(new Bearing(this, y++));
225 add(new Elevation(this, y++));
226 add(new FirmwareVersion(this, y++));
227 add(new FlightLogMax(this, y++));
228 add(new BatteryVoltage(this, y++));
229 add(new ReceiverBattery(this, y++));