telegps: use new eeprom reading code
[fw/altos] / altosuilib / AltosScanUI.java
index 7b5f2c7e64b88a7730b1db46d5a85757695f2f6a..8843429a6113b6be45d2cc8f1a974f11fec82561 100644 (file)
@@ -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
@@ -15,7 +16,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_3;
+package org.altusmetrum.altosuilib_11;
 
 import java.awt.*;
 import java.awt.event.*;
@@ -25,7 +26,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_5.*;
+import org.altusmetrum.altoslib_11.*;
 
 class AltosScanResult {
        String          callsign;
@@ -62,9 +63,18 @@ class AltosScanResult {
                rate = in_rate;
        }
 
-       public boolean equals(AltosScanResult other) {
+       public int hashCode() {
+               return serial ^ frequency.hashCode() ^ telemetry ^ rate;
+       }
+
+       public boolean equals(Object o) {
+               if (o == null)
+                       return false;
+               if (!(o instanceof AltosScanResult))
+                       return false;
+               AltosScanResult other = (AltosScanResult) o;
                return (serial == other.serial &&
-                       frequency.frequency == other.frequency.frequency &&
+                       frequency.equals(other.frequency) &&
                        telemetry == other.telemetry &&
                        rate == other.rate);
        }
@@ -159,6 +169,8 @@ public class AltosScanUI
        Thread                          thread;
        AltosFrequency[]                frequencies;
        int                             frequency_index;
+       int                             packet_count;
+       int                             tick_count;
 
        void scan_exception(Exception e) {
                if (e instanceof FileNotFoundException) {
@@ -200,6 +212,7 @@ public class AltosScanUI
                                                AltosState      state = reader.read();
                                                if (state == null)
                                                        continue;
+                                               packet_count++;
                                                if (state.flight != AltosLib.MISSING) {
                                                        final AltosScanResult   result = new AltosScanResult(state.callsign,
                                                                                                             state.serial,
@@ -251,9 +264,6 @@ public class AltosScanUI
        void next() throws InterruptedException, TimeoutException {
                reader.set_monitor(false);
 
-               /* Let any pending input from the last configuration drain out */
-               Thread.sleep(100);
-
                if (select_rate) {
                        boolean wrapped = false;
                        do {
@@ -284,6 +294,8 @@ public class AltosScanUI
                                return;
                        }
                }
+               packet_count = 0;
+               tick_count = 0;
                ++frequency_index;
                if (frequency_index >= frequencies.length)
                        frequency_index = 0;
@@ -308,7 +320,9 @@ public class AltosScanUI
        }
 
        void tick_timer() throws InterruptedException, TimeoutException {
-               next();
+               ++tick_count;
+               if (packet_count == 0 || tick_count > 5)
+                       next();
        }
 
        public void actionPerformed(ActionEvent e) {
@@ -360,6 +374,8 @@ public class AltosScanUI
                                                        reader.set_telemetry_rate(r.rate);
                                                        reader.set_frequency(r.frequency.frequency);
                                                        reader.save_frequency();
+                                                       reader.save_telemetry();
+                                                       reader.save_telemetry_rate();
                                                        owner.scan_device_selected(device);
                                                }
                                        }
@@ -438,6 +454,7 @@ public class AltosScanUI
        }
 
        public AltosScanUI(AltosUIFrame in_owner, boolean in_select_telemetry) {
+               super(in_owner, "Scan Telemetry", false);
 
                owner = in_owner;
                select_telemetry = in_select_telemetry;
@@ -519,7 +536,7 @@ public class AltosScanUI
                                rate_boxes[k].addActionListener(this);
                                rate_boxes[k].setSelected((scanning_rate & (1 << k)) != 0);
                        }
-                       y_offset_rate += AltosLib.ao_telemetry_rate_max;
+                       y_offset_rate += AltosLib.ao_telemetry_rate_max + 1;
                }
 
                if (select_telemetry) {