X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosAscent.java;h=fb05fe112438d85dc6ff24b2641be71b40dbc4d7;hp=0fbc5de26f837d3da4fc2ebaf2b856ef3905e8a7;hb=f80075be4ebb9c5fe00c24b8c7638fad23267424;hpb=f3e68341f6f5daaf26dd162e4f9a06c29988986a diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 0fbc5de2..fb05fe11 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -18,31 +18,66 @@ package altosui; import java.awt.*; -import java.awt.event.*; import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; + JLabel cur, max; - public class AscentStatus { + public class AscentStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; + double v; + AltosUnits units; + + void show() { + value.setVisible(true); + lights.setVisible(true); + label.setVisible(true); + } + + void hide() { + value.setVisible(false); + lights.setVisible(false); + label.setVisible(false); + } + + void show(AltosState state, AltosListenerState listener_state) {} + + void show(String s) { + show(); + value.setText(s); + } + + void show(double v) { + this.v = v; + show(units.show(8, v)); + } + + void show(String format, double v) { + show(String.format(format, v)); + } - void show(AltosState state, int crc_errors) {} void reset() { value.setText(""); lights.set(false); } - public AscentStatus (GridBagLayout layout, int y, String text) { + public void font_size_changed(int font_size) { + label.setFont(Altos.label_font); + value.setFont(Altos.value_font); + } + + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public AscentStatus (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -79,25 +114,53 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } } - public class AscentValue { + public abstract class AscentValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; - void show(AltosState state, int crc_errors) {} + double v; + AltosUnits units; + + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); } void show() { - label.show(); - value.show(); + label.setVisible(true); + value.setVisible(true); + } + + void show(String s) { + show(); + value.setText(s); + } + + void show(double v) { + this.v = v; + show(units.show(8, v)); + } + + void show(String format, double v) { + show(String.format(format, v)); } void hide() { - label.hide(); - value.hide(); + label.setVisible(false); + value.setVisible(false); } - public AscentValue (GridBagLayout layout, int y, String text) { + + public void font_size_changed(int font_size) { + label.setFont(Altos.label_font); + value.setFont(Altos.value_font); + } + + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -123,30 +186,61 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); } + + public AscentValue (GridBagLayout layout, int y, String text) { + this(layout, y, null, text); + } } - public class AscentValueHold { + public class AscentValueHold implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; JTextField max_value; double max; + AltosUnits units; + double v; - void show(AltosState state, int crc_errors) {} + void show(AltosState state, AltosListenerState listener_state) {} void reset() { value.setText(""); max_value.setText(""); - max = 0; + max = AltosLib.MISSING; } - void show(String format, double v) { - value.setText(String.format(format, v)); - if (v > max) { - max_value.setText(String.format(format, v)); - max = v; + public void font_size_changed(int font_size) { + label.setFont(Altos.label_font); + value.setFont(Altos.value_font); + max_value.setFont(Altos.value_font); + } + + public void units_changed(boolean imperial_units) { + show(v); + } + + void show(double v) { + this.v = v; + if (v == AltosLib.MISSING) { + value.setText("Missing"); + } else { + value.setText(units.show(8, v)); + if (v > max || max == AltosLib.MISSING) + max = v; } + if (max == AltosLib.MISSING) + max_value.setText("Missing"); + else + max_value.setText(units.show(8, v)); + } + + void hide() { + label.setVisible(false); + value.setVisible(false); + max_value.setVisible(false); } - public AscentValueHold (GridBagLayout layout, int y, String text) { + + public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -183,43 +277,50 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } } - class Height extends AscentValueHold { - void show (AltosState state, int crc_errors) { - show("%6.0f m", state.height); + void show (AltosState state, AltosListenerState listener_state) { + show(state.height()); } public Height (GridBagLayout layout, int y) { - super (layout, y, "Height"); + super (layout, y, AltosConvert.height, "Height"); } } Height height; class Speed extends AscentValueHold { - void show (AltosState state, int crc_errors) { - double speed = state.speed; - if (!state.ascent) - speed = state.baro_speed; - show("%6.0f m/s", speed); + void show (AltosState state, AltosListenerState listener_state) { + show(state.speed()); } public Speed (GridBagLayout layout, int y) { - super (layout, y, "Speed"); + super (layout, y, AltosConvert.speed, "Speed"); } } Speed speed; class Accel extends AscentValueHold { - void show (AltosState state, int crc_errors) { - show("%6.0f m/s²", state.acceleration); + void show (AltosState state, AltosListenerState listener_state) { + show(state.acceleration()); } public Accel (GridBagLayout layout, int y) { - super (layout, y, "Acceleration"); + super (layout, y, AltosConvert.accel, "Acceleration"); } } Accel accel; + class Orient extends AscentValueHold { + void show (AltosState state, AltosListenerState listener_state) { + show(state.orient()); + } + public Orient (GridBagLayout layout, int y) { + super (layout, y, AltosConvert.orient, "Tilt Angle"); + } + } + + Orient orient; + String pos(double p, String pos, String neg) { String h = pos; if (p < 0) { @@ -232,36 +333,35 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } class Apogee extends AscentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.drogue_sense)); - lights.set(state.drogue_sense > 3.2); + void show (AltosState state, AltosListenerState listener_state) { + 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"); + super(layout, y, null, "Apogee Igniter Voltage"); } } Apogee apogee; class Main extends AscentStatus { - void show (AltosState state, int crc_errors) { - value.setText(String.format("%4.2f V", state.main_sense)); - lights.set(state.main_sense > 3.2); + void show (AltosState state, AltosListenerState listener_state) { + 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"); + super(layout, y, null, "Main Igniter Voltage"); } } Main main; class Lat extends AscentValue { - void show (AltosState state, int crc_errors) { - show(); - if (state.gps != null) - value.setText(pos(state.gps.lat,"N", "S")); + void show (AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) + show(pos(state.gps.lat,"N", "S")); else - value.setText("???"); + show("???"); } public Lat (GridBagLayout layout, int y) { super (layout, y, "Latitude"); @@ -271,12 +371,11 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { Lat lat; class Lon extends AscentValue { - void show (AltosState state, int crc_errors) { - show(); - if (state.gps != null) - value.setText(pos(state.gps.lon,"E", "W")); + void show (AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) + show(pos(state.gps.lon,"E", "W")); else - value.setText("???"); + show("???"); } public Lon (GridBagLayout layout, int y) { super (layout, y, "Longitude"); @@ -293,26 +392,60 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { height.reset(); speed.reset(); accel.reset(); + orient.reset(); } - public void show(AltosState state, int crc_errors) { - if (state.gps != null) { - lat.show(state, crc_errors); - lon.show(state, crc_errors); + public void font_size_changed(int font_size) { + cur.setFont(Altos.label_font); + max.setFont(Altos.label_font); + lat.font_size_changed(font_size); + lon.font_size_changed(font_size); + main.font_size_changed(font_size); + apogee.font_size_changed(font_size); + height.font_size_changed(font_size); + speed.font_size_changed(font_size); + accel.font_size_changed(font_size); + orient.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + lat.units_changed(imperial_units); + lon.units_changed(imperial_units); + main.units_changed(imperial_units); + apogee.units_changed(imperial_units); + height.units_changed(imperial_units); + speed.units_changed(imperial_units); + accel.units_changed(imperial_units); + orient.units_changed(imperial_units); + } + + public void show(AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected) { + lat.show(state, listener_state); + lon.show(state, listener_state); } else { lat.hide(); lon.hide(); } - height.show(state, crc_errors); - main.show(state, crc_errors); - apogee.show(state, crc_errors); - speed.show(state, crc_errors); - accel.show(state, crc_errors); + height.show(state, listener_state); + if (state.main_voltage != AltosLib.MISSING) + main.show(state, listener_state); + else + main.hide(); + if (state.apogee_voltage != AltosLib.MISSING) + apogee.show(state, listener_state); + else + apogee.hide(); + speed.show(state, listener_state); + accel.show(state, listener_state); + if (state.orient() != AltosLib.MISSING) + orient.show(state, listener_state); + else + orient.hide(); } public void labels(GridBagLayout layout, int y) { GridBagConstraints c; - JLabel cur, max; cur = new JLabel("Current"); cur.setFont(Altos.label_font); @@ -329,6 +462,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(max); } + public String getName() { + return "Ascent"; + } + public AltosAscent() { layout = new GridBagLayout(); @@ -340,13 +477,15 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { * lon * height */ - labels(layout, 0); - height = new Height(layout, 1); - speed = new Speed(layout, 2); - accel = new Accel(layout, 3); - lat = new Lat(layout, 4); - lon = new Lon(layout, 5); - apogee = new Apogee(layout, 6); - main = new Main(layout, 7); + int y = 0; + labels(layout, y++); + height = new Height(layout, y++); + speed = new Speed(layout, y++); + accel = new Accel(layout, y++); + orient = new Orient(layout, y++); + lat = new Lat(layout, y++); + lon = new Lon(layout, y++); + apogee = new Apogee(layout, y++); + main = new Main(layout, y++); } }