summaryrefslogtreecommitdiff
path: root/telegps
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-06-12 14:12:08 -0700
committerKeith Packard <keithp@keithp.com>2014-06-12 14:12:08 -0700
commit8044eb8e23366e91c741060939baff5137f841c7 (patch)
tree82d8676369d840051b91a462859a3883bb678a80 /telegps
parente00ffe6ab6197ab48ba8ce3cf71a197f7215649f (diff)
altosui/telegps: Reduce CPU time needed for flight displays
Don't update displays which aren't shown; track hierarchy changes to trigger display from most recent state data. Don't update values which haven't changed; remember previous values and compare with new before updating widget contents. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'telegps')
-rw-r--r--telegps/TeleGPSInfo.java46
-rw-r--r--telegps/TeleGPSStatus.java46
2 files changed, 70 insertions, 22 deletions
diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java
index 2765f5ab..15eb9b75 100644
--- a/telegps/TeleGPSInfo.java
+++ b/telegps/TeleGPSInfo.java
@@ -18,14 +18,18 @@
package org.altusmetrum.telegps;
import java.awt.*;
+import java.awt.event.*;
import javax.swing.*;
import org.altusmetrum.altoslib_4.*;
import org.altusmetrum.altosuilib_2.*;
-public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
+public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener {
GridBagLayout layout;
JLabel cur, max;
+ private AltosState last_state;
+ private AltosListenerState last_listener_state;
+
public abstract class Info implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
@@ -280,6 +284,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
value1 = new JTextField(AltosUILib.text_width);
value1.setFont(AltosUILib.value_font);
value1.setHorizontalAlignment(SwingConstants.RIGHT);
+ value1.setEditable(false);
c.gridx = 2; c.gridy = y;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
@@ -290,6 +295,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
value2 = new JTextField(AltosUILib.text_width);
value2.setFont(AltosUILib.value_font);
value2.setHorizontalAlignment(SwingConstants.RIGHT);
+ value1.setEditable(false);
c.gridx = 3; c.gridy = y;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
@@ -323,18 +329,16 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
}
public void units_changed(boolean imperial_units) {
- show(v);
+ show(v, max);
}
- void show(double v) {
+ void show(double v, double max) {
this.v = v;
- if (v == AltosLib.MISSING) {
+ this.max = max;
+ if (v == AltosLib.MISSING)
value.setText("Missing");
- } else {
+ else
value.setText(units.show(8, v));
- if (v > max || max == AltosLib.MISSING)
- max = v;
- }
if (max == AltosLib.MISSING)
max_value.setText("Missing");
else
@@ -364,6 +368,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
add(label);
value = new JTextField(AltosUILib.text_width);
+ value.setEditable(false);
value.setFont(AltosUILib.value_font);
value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 2; c.gridy = y;
@@ -374,6 +379,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
add(value);
max_value = new JTextField(AltosUILib.text_width);
+ max_value.setEditable(false);
max_value.setFont(AltosUILib.value_font);
max_value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 3; c.gridy = y;
@@ -388,7 +394,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
class Altitude extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(state.altitude());
+ show(state.altitude(), state.max_altitude());
}
public Altitude (GridBagLayout layout, int y) {
super (layout, y, AltosConvert.height, "Altitude");
@@ -399,7 +405,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
class AscentRate extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(state.gps_ascent_rate());
+ show(state.gps_ascent_rate(), state.max_gps_ascent_rate());
}
public AscentRate (GridBagLayout layout, int y) {
super (layout, y, AltosConvert.speed, "Ascent Rate");
@@ -410,7 +416,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
class GroundSpeed extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(state.gps_ground_speed());
+ show(state.gps_ground_speed(), state.max_gps_ground_speed());
}
public GroundSpeed (GridBagLayout layout, int y) {
super (layout, y, AltosConvert.speed, "Ground Speed");
@@ -526,6 +532,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
}
public void show(AltosState state, AltosListenerState listener_state) {
+ if (!isShowing()) {
+ last_state = state;
+ last_listener_state = listener_state;
+ return;
+ }
+
if (state.gps != null && state.gps.connected) {
lat.show(state, listener_state);
lon.show(state, listener_state);
@@ -562,6 +574,17 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
return "Info";
}
+ 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 TeleGPSInfo() {
layout = new GridBagLayout();
@@ -582,5 +605,6 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
lat = new Lat(layout, y++);
lon = new Lon(layout, y++);
gps_locked = new GPSLocked(layout, y++);
+ addHierarchyListener(this);
}
}
diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java
index 37cfae37..e6bb1ea5 100644
--- a/telegps/TeleGPSStatus.java
+++ b/telegps/TeleGPSStatus.java
@@ -61,6 +61,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
add(label);
value = new JTextField("");
+ value.setEditable(false);
value.setFont(AltosUILib.status_font);
value.setHorizontalAlignment(SwingConstants.CENTER);
c.gridx = x; c.gridy = 1;
@@ -70,8 +71,13 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
}
class Call extends Value {
+ String call;
+
void show(AltosState state, AltosListenerState listener_state) {
- value.setText(state.callsign);
+ if (state.callsign != call) {
+ value.setText(state.callsign);
+ call = state.callsign;
+ }
if (state.callsign == null)
setVisible(false);
else
@@ -85,11 +91,15 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
Call call;
class Serial extends Value {
+ int serial = -1;
void show(AltosState state, AltosListenerState listener_state) {
- if (state.serial == AltosLib.MISSING)
- value.setText("none");
- else
- value.setText(String.format("%d", state.serial));
+ if (state.serial != serial) {
+ if (state.serial == AltosLib.MISSING)
+ value.setText("none");
+ else
+ value.setText(String.format("%d", state.serial));
+ serial = state.serial;
+ }
}
public Serial (GridBagLayout layout, int x) {
super (layout, x, "Serial");
@@ -99,12 +109,19 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
Serial serial;
class RSSI extends Value {
+ int rssi = 10000;
+
void show(AltosState state, AltosListenerState listener_state) {
- value.setText(String.format("%d", state.rssi()));
- if (state.rssi == AltosLib.MISSING)
- setVisible(false);
- else
- setVisible(true);
+ int new_rssi = state.rssi();
+
+ if (new_rssi != rssi) {
+ value.setText(String.format("%d", new_rssi));
+ if (state.rssi == AltosLib.MISSING)
+ setVisible(false);
+ else
+ setVisible(true);
+ rssi = new_rssi;
+ }
}
public RSSI (GridBagLayout layout, int x) {
super (layout, x, "RSSI");
@@ -114,9 +131,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
RSSI rssi;
class LastPacket extends Value {
+
+ long last_secs = -1;
+
void show(AltosState state, AltosListenerState listener_state) {
long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
- value.setText(String.format("%d", secs));
+
+ if (secs != last_secs) {
+ value.setText(String.format("%d", secs));
+ last_secs = secs;
+ }
}
public LastPacket(GridBagLayout layout, int x) {
super (layout, x, "Age");