This adds a 'running' member to the AltosListenerState class, and when
the replay reader reaches EOF, marks the listener as no longer
running.
AltosUI and TeleGPS now display 'done' in the 'Age' field when this
occurs, to let the user know that the replay is over.
Also make sure that the display timers are stopped when this happens,
or when the window is closed.
Signed-off-by: Keith Packard <keithp@keithp.com>
public class AltosListenerState implements Serializable {
public int crc_errors;
public double battery;
public class AltosListenerState implements Serializable {
public int crc_errors;
public double battery;
+ public boolean running;
public AltosListenerState() {
crc_errors = 0;
battery = AltosLib.MISSING;
public AltosListenerState() {
crc_errors = 0;
battery = AltosLib.MISSING;
long last_secs = -1;
void show(AltosState state, AltosListenerState listener_state) {
long last_secs = -1;
void show(AltosState state, AltosListenerState listener_state) {
- long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
- if (secs != last_secs) {
- value.setText(String.format("%d", secs));
- last_secs = secs;
+ if (listener_state.running) {
+ long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
+ if (secs != last_secs) {
+ value.setText(String.format("%d", secs));
+ last_secs = secs;
+ }
+ } else {
+ value.setText("done");
flight_state.show(state, listener_state);
rssi.show(state, listener_state);
last_packet.show(state, listener_state);
flight_state.show(state, listener_state);
rssi.show(state, listener_state);
last_packet.show(state, listener_state);
+ if (!listener_state.running)
+ stop();
public String getName() { return "Flight Status"; }
public String getName() { return "Flight Status"; }
+ AltosFlightStatusUpdate status_update;
+ javax.swing.Timer timer;
+
+ public void start(AltosFlightStatusUpdate status_update) {
+ this.status_update = status_update;
+ timer = new javax.swing.Timer(100, status_update);
+ timer.start();
+ }
+
+ public void stop() {
+ if (timer != null) {
+ timer.stop();
+ timer = null;
+ }
+ }
+
public AltosFlightStatus() {
layout = new GridBagLayout();
public AltosFlightStatus() {
layout = new GridBagLayout();
public void show(AltosState state, AltosListenerState listener_state) {
status_update.saved_state = state;
public void show(AltosState state, AltosListenerState listener_state) {
status_update.saved_state = state;
+ status_update.saved_listener_state = listener_state;
if (state == null)
state = new AltosState();
if (state == null)
state = new AltosState();
AltosUIPreferences.register_font_listener(this);
AltosPreferences.register_units_listener(this);
AltosUIPreferences.register_font_listener(this);
AltosPreferences.register_units_listener(this);
+ status_update = new AltosFlightStatusUpdate(flightStatus);
+
+ flightStatus.start(status_update);
+
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
disconnect();
setVisible(false);
dispose();
disconnect();
setVisible(false);
dispose();
thread = new AltosDisplayThread(this, voice, this, reader);
thread = new AltosDisplayThread(this, voice, this, reader);
- status_update = new AltosFlightStatusUpdate(flightStatus);
-
- new javax.swing.Timer(100, status_update).start();
-
for (;;) {
try {
state = reader.read();
for (;;) {
try {
state = reader.read();
+ if (state == null) {
+ listener_state.running = false;
reader.update(state);
show_safely();
told = tell();
reader.update(state);
show_safely();
told = tell();
TeleGPSStatus telegps_status;
TeleGPSStatusUpdate status_update;
TeleGPSStatus telegps_status;
TeleGPSStatusUpdate status_update;
- javax.swing.Timer status_timer;
public void show(AltosState state, AltosListenerState listener_state) {
try {
status_update.saved_state = state;
public void show(AltosState state, AltosListenerState listener_state) {
try {
status_update.saved_state = state;
+ status_update.saved_listener_state = listener_state;
if (state == null)
state = new AltosState();
if (state == null)
state = new AltosState();
void disconnect() {
setTitle("TeleGPS");
stop_display();
void disconnect() {
setTitle("TeleGPS");
stop_display();
- if (status_timer != null) {
- status_timer.stop();
- status_timer = null;
- status_update = null;
- }
telegps_status.disable_receive();
disable_frequency_menu();
telegps_status.disable_receive();
disable_frequency_menu();
public void set_reader(AltosFlightReader reader, AltosDevice device) {
status_update = new TeleGPSStatusUpdate(telegps_status);
public void set_reader(AltosFlightReader reader, AltosDevice device) {
status_update = new TeleGPSStatusUpdate(telegps_status);
- status_timer = new javax.swing.Timer(100, status_update);
- status_timer.start();
+ telegps_status.start(status_update);
setTitle(String.format("TeleGPS %s", reader.name));
thread = new TeleGPSDisplayThread(this, voice(), this, reader);
setTitle(String.format("TeleGPS %s", reader.name));
thread = new TeleGPSDisplayThread(this, voice(), this, reader);
for (;;) {
try {
state = reader.read();
for (;;) {
try {
state = reader.read();
+ if (state == null) {
+ listener_state.running = false;
reader.update(state);
show_safely();
told = tell();
reader.update(state);
show_safely();
told = tell();
long last_secs = -1;
void show(AltosState state, AltosListenerState listener_state) {
long last_secs = -1;
void show(AltosState state, AltosListenerState listener_state) {
- long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
-
- if (secs != last_secs) {
- value.setText(String.format("%d", secs));
- last_secs = secs;
+ if (listener_state.running) {
+ long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
+
+ if (secs != last_secs) {
+ value.setText(String.format("%d", secs));
+ last_secs = secs;
+ }
+ } else {
+ value.setText("done");
flight.show(state, listener_state);
rssi.show(state, listener_state);
last_packet.show(state, listener_state);
flight.show(state, listener_state);
rssi.show(state, listener_state);
last_packet.show(state, listener_state);
+ if (!listener_state.running)
+ stop();
+ TeleGPSStatusUpdate status_update;
+ javax.swing.Timer timer;
+
+ public void start(TeleGPSStatusUpdate status_update) {
+ this.status_update = status_update;
+ timer = new javax.swing.Timer(100, status_update);
+ timer.start();
+ }
+
+ public void stop() {
+ if (timer != null) {
+ timer.stop();
+ timer = null;
+ }
+ }
+
public TeleGPSStatus() {
layout = new GridBagLayout();
public TeleGPSStatus() {
layout = new GridBagLayout();