X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPSDisplayThread.java;h=defd588e722d931a13b0d675529fc377203f006f;hp=18b8d9fcd7fe29d0bd086756da27b8277286b07c;hb=refs%2Fheads%2Fbranch-1.9;hpb=c8078d352a7f54a4a97d25af080155d3f875536a diff --git a/telegps/TeleGPSDisplayThread.java b/telegps/TeleGPSDisplayThread.java index 18b8d9fc..873092a5 100644 --- a/telegps/TeleGPSDisplayThread.java +++ b/telegps/TeleGPSDisplayThread.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,8 +22,8 @@ import java.awt.*; import javax.swing.*; import java.io.*; import java.text.*; -import org.altusmetrum.altoslib_5.*; -import org.altusmetrum.altosuilib_3.*; +import org.altusmetrum.altoslib_14.*; +import org.altusmetrum.altosuilib_14.*; public class TeleGPSDisplayThread extends Thread { @@ -30,7 +31,9 @@ public class TeleGPSDisplayThread extends Thread { IdleThread idle_thread; AltosVoice voice; AltosFlightReader reader; - AltosState old_state, state; + AltosState state; + int old_state = AltosLib.ao_flight_invalid; + boolean old_gps_ready = false; AltosListenerState listener_state; AltosFlightDisplay display; @@ -129,11 +132,12 @@ public class TeleGPSDisplayThread extends Thread { } public synchronized void notice(boolean spoken) { - if (old_state != null && old_state.state != state.state) { + if (old_state != state.state()) { report_time = now(); this.notify(); } else if (spoken) set_report_time(); + old_state = state.state(); } public IdleThread() { @@ -143,17 +147,17 @@ public class TeleGPSDisplayThread extends Thread { synchronized boolean tell() { boolean ret = false; - if (old_state == null || old_state.gps_ready != state.gps_ready) { + if (old_gps_ready != state.gps_ready) { if (state.gps_ready) { voice.speak("GPS ready"); ret = true; } - else if (old_state != null) { + else if (old_gps_ready) { voice.speak("GPS lost"); ret = true; } + old_gps_ready = state.gps_ready; } - old_state = state; return ret; } @@ -168,9 +172,10 @@ public class TeleGPSDisplayThread extends Thread { for (;;) { try { state = reader.read(); - if (state == null) + if (state == null) { + listener_state.running = false; break; - reader.update(state); + } show_safely(); told = tell(); idle_thread.notice(told);