diff options
author | Keith Packard <keithp@keithp.com> | 2014-06-12 14:12:08 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-06-12 14:12:08 -0700 |
commit | 8044eb8e23366e91c741060939baff5137f841c7 (patch) | |
tree | 82d8676369d840051b91a462859a3883bb678a80 /altosui/AltosPad.java | |
parent | e00ffe6ab6197ab48ba8ce3cf71a197f7215649f (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 'altosui/AltosPad.java')
-rw-r--r-- | altosui/AltosPad.java | 116 |
1 files changed, 71 insertions, 45 deletions
diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index ce1f2ab7..3294949c 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -98,6 +98,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -178,6 +179,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -193,50 +195,56 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } } - class Battery extends LaunchStatus { + class Voltage extends LaunchStatus { + + double voltage(AltosState state) { return AltosLib.MISSING; }; + double good() { return 0; }; + + double last_voltage = -1; + void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.battery_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.battery_voltage); - lights.set(state.battery_voltage >= AltosLib.ao_battery_good); + double voltage = AltosLib.MISSING; + if (state != null) + voltage = voltage(state); + + if (voltage != last_voltage) { + if (voltage == AltosLib.MISSING) + hide(); + else { + show("%4.2f V", voltage); + lights.set(voltage >= good()); + } + last_voltage = voltage; } } + public Voltage (GridBagLayout layout, int y, String name) { super(layout, y, name); } + } + + + class Battery extends Voltage { + double voltage(AltosState state) { return state.battery_voltage; } + double good() { return AltosLib.ao_battery_good; } + public Battery (GridBagLayout layout, int y) { super(layout, y, "Battery Voltage"); } + } Battery battery; - class Apogee extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.apogee_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.apogee_voltage); - lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); - } - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); - } + class Apogee extends Voltage { + double voltage(AltosState state) { return state.apogee_voltage; } + double good() { return AltosLib.ao_igniter_good; } + public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); } } Apogee apogee; - class Main extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.main_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.main_voltage); - lights.set(state.main_voltage >= AltosLib.ao_igniter_good); - } - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } + class Main extends Voltage { + double voltage(AltosState state) { return state.main_voltage; } + double good() { return AltosLib.ao_igniter_good; } + public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); } } Main main; @@ -328,6 +336,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } class PadLat extends LaunchValue { + + double last_lat = 1000; + void show (AltosState state, AltosListenerState listener_state) { double lat = AltosLib.MISSING; String label = null; @@ -341,11 +352,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Latitude"; } } - if (lat != AltosLib.MISSING) { - show(pos(lat,"N", "S")); - set_label(label); - } else - hide(); + if (lat != last_lat) { + if (lat != AltosLib.MISSING) { + show(pos(lat,"N", "S")); + set_label(label); + } else + hide(); + last_lat = lat; + } } public PadLat (GridBagLayout layout, int y) { super (layout, y, "Pad Latitude"); @@ -355,6 +369,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { PadLat pad_lat; class PadLon extends LaunchValue { + + double last_lon = 1000; + void show (AltosState state, AltosListenerState listener_state) { double lon = AltosLib.MISSING; String label = null; @@ -368,11 +385,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Longitude"; } } - if (lon != AltosLib.MISSING) { - show(pos(lon,"E", "W")); - set_label(label); - } else - hide(); + if (lon != last_lon) { + if (lon != AltosLib.MISSING) { + show(pos(lon,"E", "W")); + set_label(label); + } else + hide(); + last_lon = lon; + } } public PadLon (GridBagLayout layout, int y) { super (layout, y, "Pad Longitude"); @@ -382,6 +402,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { PadLon pad_lon; class PadAlt extends LaunchValue { + + double last_alt = -1000000; + void show (AltosState state, AltosListenerState listener_state) { double alt = AltosLib.MISSING; String label = null; @@ -395,11 +418,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Altitude"; } } - if (alt != AltosLib.MISSING) { - show(alt); - set_label(label); - } else - hide(); + if (alt != last_alt) { + if (alt != AltosLib.MISSING) { + show(alt); + set_label(label); + } else + hide(); + last_alt = alt; + } } public PadAlt (GridBagLayout layout, int y) { super (layout, y, AltosConvert.height, "Pad Altitude"); |