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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.telegps;
23 import java.awt.event.*;
25 import org.altusmetrum.altoslib_11.*;
26 import org.altusmetrum.altosuilib_11.*;
28 public class TeleGPSState extends AltosUIFlightTab {
32 abstract class Value extends AltosUIUnitsIndicator {
33 public Value (Container container, int y, AltosUnits units, String text) {
34 super(container, y, units, text, 1, false, 2);
38 abstract class DualValue extends AltosUIUnitsIndicator {
39 public DualValue (Container container, int y, AltosUnits units, String text) {
40 super(container, y, units, text, 2, false, 1);
44 abstract class ValueHold extends DualValue {
45 public ValueHold (Container container, int y, AltosUnits units, String text) {
46 super(container, y, units, text);
50 class Height extends ValueHold {
51 public double value(AltosState state, int i) {
53 return state.height();
55 return state.max_height();
58 public Height(Container container, int y) {
59 super(container, y, AltosConvert.height, "Height");
63 class Speed extends ValueHold {
64 public double value(AltosState state, int i) {
66 return state.gps_speed();
68 return state.max_gps_speed();
71 public Speed(Container container, int y) {
72 super(container, y, AltosConvert.speed, "Speed");
76 class Distance extends Value {
77 public double value(AltosState state, int i) {
78 if (state.from_pad != null)
79 return state.from_pad.distance;
81 return AltosLib.MISSING;
84 public Distance(Container container, int y) {
85 super(container, y, AltosConvert.distance, "Distance");
89 class Range extends Value {
90 public double value(AltosState state, int i) {
93 public Range (Container container, int y) {
94 super (container, y, AltosConvert.distance, "Range");
98 class Bearing extends AltosUIIndicator {
99 public void show (AltosState state, AltosListenerState listener_state) {
100 if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
101 show( String.format("%3.0f°", state.from_pad.bearing),
102 state.from_pad.bearing_words(
103 AltosGreatCircle.BEARING_LONG));
105 show("Missing", "Missing");
108 public Bearing (Container container, int y) {
109 super (container, y, "Bearing", 2, false, 1);
113 class Elevation extends AltosUIIndicator {
114 public void show (AltosState state, AltosListenerState listener_state) {
115 if (state.elevation == AltosLib.MISSING)
118 show("%3.0f°", state.elevation);
120 public Elevation (Container container, int y) {
121 super (container, y, "Elevation", 1, false, 2);
125 class FirmwareVersion extends AltosUIIndicator {
126 public void show(AltosState state, AltosListenerState listener_state) {
127 if (state.firmware_version == null)
130 show(state.firmware_version);
133 public FirmwareVersion(Container container, int y) {
134 super(container, y, "Firmware Version", 1, false, 2);
138 class FlightLogMax extends AltosUIIndicator {
139 public void show(AltosState state, AltosListenerState listener_state) {
140 int storage = state.flight_log_max;
141 if (storage == AltosLib.MISSING)
142 storage = state.log_space >> 10;
143 if (storage == AltosLib.MISSING)
146 show(String.format("%dkB", storage));
149 public FlightLogMax(Container container, int y) {
150 super(container, y, "Flight Log Storage", 1, false, 2);
154 class BatteryVoltage extends AltosUIVoltageIndicator {
155 public double voltage(AltosState state) {
156 return state.battery_voltage;
159 public double good() {
160 return AltosLib.ao_battery_good;
163 public BatteryVoltage(Container container, int y) {
164 super(container, y, "Battery Voltage", 2);
168 class ReceiverBattery extends AltosUIVoltageIndicator {
170 public double voltage(AltosState state) { return AltosLib.MISSING; }
172 public double good() { return AltosLib.ao_battery_good; }
174 public boolean hide(AltosState state, AltosListenerState listener_state, int i) {
175 return value(state, listener_state, i) == AltosLib.MISSING;
178 public double value(AltosState state, AltosListenerState listener_state, int i) {
179 if (listener_state == null)
180 return AltosLib.MISSING;
181 return listener_state.battery;
184 public ReceiverBattery (AltosUIFlightTab container, int y) {
185 super(container, y, "Receiver Battery", 2);
189 public void labels(Container container, int y) {
190 GridBagLayout layout = (GridBagLayout)(container.getLayout());
191 GridBagConstraints c;
193 cur = new JLabel("Current");
194 cur.setFont(AltosUILib.label_font);
195 c = new GridBagConstraints();
196 c.gridx = 2; c.gridy = y;
197 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
198 layout.setConstraints(cur, c);
201 max = new JLabel("Maximum");
202 max.setFont(AltosUILib.label_font);
203 c.gridx = 3; c.gridy = y;
204 layout.setConstraints(max, c);
208 public void font_size_changed(int font_size) {
209 cur.setFont(AltosUILib.label_font);
210 max.setFont(AltosUILib.label_font);
211 super.font_size_changed(font_size);
214 public String getName() {
218 public TeleGPSState() {
221 add(new Height(this, y++));
222 add(new Speed(this, y++));
223 add(new Distance(this, y++));
224 add(new Range(this, y++));
225 add(new Bearing(this, y++));
226 add(new Elevation(this, y++));
227 add(new FirmwareVersion(this, y++));
228 add(new FlightLogMax(this, y++));
229 add(new BatteryVoltage(this, y++));
230 add(new ReceiverBattery(this, y++));