X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPSState.java;h=19fd369454ff9b4403486c5976485966b7ddc393;hp=b10e8e7056e7c1ca583e404255fc0f1022f2c643;hb=a61217f0a6d0ef48b6471f632c4600255867e831;hpb=3f7e885055f8a97f334e0cd3163b760b174114b6 diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java index b10e8e70..19fd3694 100644 --- a/telegps/TeleGPSState.java +++ b/telegps/TeleGPSState.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,15 +22,12 @@ import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; +import org.altusmetrum.altoslib_12.*; +import org.altusmetrum.altosuilib_12.*; -public class TeleGPSState extends JComponent implements AltosFlightDisplay, HierarchyListener { - GridBagLayout layout; - JLabel cur, max; +public class TeleGPSState extends AltosUIFlightTab { - private AltosState last_state; - private AltosListenerState last_listener_state; + JLabel cur, max; abstract class Value extends AltosUIUnitsIndicator { public Value (Container container, int y, AltosUnits units, String text) { @@ -44,10 +42,6 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier } abstract class ValueHold extends DualValue { - public void reset() { - super.reset(); - last_values[1] = AltosLib.MISSING; - } public ValueHold (Container container, int y, AltosUnits units, String text) { super(container, y, units, text); } @@ -103,12 +97,12 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class Bearing extends AltosUIIndicator { public void show (AltosState state, AltosListenerState listener_state) { - if (state.from_pad != null) { + if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) { show( String.format("%3.0f°", state.from_pad.bearing), state.from_pad.bearing_words( AltosGreatCircle.BEARING_LONG)); } else { - show("???", "???"); + show("Missing", "Missing"); } } public Bearing (Container container, int y) { @@ -118,7 +112,10 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class Elevation extends AltosUIIndicator { public void show (AltosState state, AltosListenerState listener_state) { - show("%3.0f°", state.elevation); + if (state.elevation == AltosLib.MISSING) + show("Missing"); + else + show("%3.0f°", state.elevation); } public Elevation (Container container, int y) { super (container, y, "Elevation", 1, false, 2); @@ -127,10 +124,10 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class FirmwareVersion extends AltosUIIndicator { public void show(AltosState state, AltosListenerState listener_state) { - if (state.firmware_version == null) + if (state.cal_data.firmware_version == null) show("Missing"); else - show(state.firmware_version); + show(state.cal_data.firmware_version); } public FirmwareVersion(Container container, int y) { @@ -140,10 +137,11 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class FlightLogMax extends AltosUIIndicator { public void show(AltosState state, AltosListenerState listener_state) { - if (state.flight_log_max == AltosLib.MISSING) + int storage = state.cal_data.flight_log_max; + if (storage == AltosLib.MISSING) show("Missing"); else - show(String.format("%dkB", state.flight_log_max)); + show(String.format("%dkB", storage)); } public FlightLogMax(Container container, int y) { @@ -165,7 +163,26 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier } } - LinkedList indicators = new LinkedList(); + class ReceiverBattery extends AltosUIVoltageIndicator { + + public double voltage(AltosState state) { return AltosLib.MISSING; } + + public double good() { return AltosLib.ao_battery_good; } + + public boolean hide(AltosState state, AltosListenerState listener_state, int i) { + return value(state, listener_state, i) == AltosLib.MISSING; + } + + public double value(AltosState state, AltosListenerState listener_state, int i) { + if (listener_state == null) + return AltosLib.MISSING; + return listener_state.battery; + } + + public ReceiverBattery (AltosUIFlightTab container, int y) { + super(container, y, "Receiver Battery", 2); + } + } public void labels(Container container, int y) { GridBagLayout layout = (GridBagLayout)(container.getLayout()); @@ -186,69 +203,28 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier add(max); } - public void reset() { - for (AltosUIIndicator i : indicators) - i.reset(); - } - public void font_size_changed(int font_size) { - for (AltosUIIndicator i : indicators) - i.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - for (AltosUIIndicator i : indicators) - i.units_changed(imperial_units); - } - - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; - } - - for (AltosUIIndicator i : indicators) - i.show(state, listener_state); + cur.setFont(AltosUILib.label_font); + max.setFont(AltosUILib.label_font); + super.font_size_changed(font_size); } public String getName() { return "Status"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public TeleGPSState() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in state display: - * - * config_version; - * lon - * height - */ int y = 0; labels(this, y++); - indicators.add(new Height(this, y++)); - indicators.add(new Speed(this, y++)); - indicators.add(new Distance(this, y++)); - indicators.add(new Range(this, y++)); - indicators.add(new Bearing(this, y++)); - indicators.add(new Elevation(this, y++)); - indicators.add(new FirmwareVersion(this, y++)); - indicators.add(new FlightLogMax(this, y++)); - indicators.add(new BatteryVoltage(this, y++)); - addHierarchyListener(this); + add(new Height(this, y++)); + add(new Speed(this, y++)); + add(new Distance(this, y++)); + add(new Range(this, y++)); + add(new Bearing(this, y++)); + add(new Elevation(this, y++)); + add(new FirmwareVersion(this, y++)); + add(new FlightLogMax(this, y++)); + add(new BatteryVoltage(this, y++)); + add(new ReceiverBattery(this, y++)); } }