summaryrefslogtreecommitdiff
path: root/altoslib
diff options
context:
space:
mode:
Diffstat (limited to 'altoslib')
-rw-r--r--altoslib/AltosPreferences.java21
-rw-r--r--altoslib/AltosRecord.java12
-rw-r--r--altoslib/AltosRecordMM.java10
-rw-r--r--altoslib/AltosRecordNone.java4
-rw-r--r--altoslib/AltosRecordTM.java8
-rw-r--r--altoslib/AltosSpeed.java6
-rw-r--r--altoslib/AltosState.java8
-rw-r--r--altoslib/AltosUnitsListener.java22
-rw-r--r--altoslib/Makefile.am1
9 files changed, 69 insertions, 23 deletions
diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java
index 47196d6e..e50b9b5c 100644
--- a/altoslib/AltosPreferences.java
+++ b/altoslib/AltosPreferences.java
@@ -367,6 +367,8 @@ public class AltosPreferences {
set_common_frequencies(new_frequencies);
}
+ static LinkedList<AltosUnitsListener> units_listeners;
+
public static boolean imperial_units() {
synchronized(backend) {
return AltosConvert.imperial_units;
@@ -379,5 +381,24 @@ public class AltosPreferences {
backend.putBoolean(unitsPreference, imperial_units);
flush_preferences();
}
+ if (units_listeners != null) {
+ for (AltosUnitsListener l : units_listeners) {
+ l.units_changed(imperial_units);
+ }
+ }
+ }
+
+ public static void register_units_listener(AltosUnitsListener l) {
+ synchronized(backend) {
+ if (units_listeners == null)
+ units_listeners = new LinkedList<AltosUnitsListener>();
+ units_listeners.add(l);
+ }
+ }
+
+ public static void unregister_units_listener(AltosUnitsListener l) {
+ synchronized(backend) {
+ units_listeners.remove(l);
+ }
}
}
diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java
index 09169515..2c4b6fa5 100644
--- a/altoslib/AltosRecord.java
+++ b/altoslib/AltosRecord.java
@@ -126,6 +126,8 @@ public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable
return tick - o.tick;
}
+ abstract public AltosRecord clone();
+
public void copy(AltosRecord old) {
seen = old.seen;
version = old.version;
@@ -144,16 +146,6 @@ public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable
kalman_height = old.kalman_height;
}
- public AltosRecord clone() {
- try {
- AltosRecord n = (AltosRecord) super.clone();
- n.copy(this);
- return n;
- } catch (CloneNotSupportedException e) {
- return null;
- }
- }
-
public AltosRecord() {
seen = 0;
version = 0;
diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java
index 9f529234..546f3055 100644
--- a/altoslib/AltosRecordMM.java
+++ b/altoslib/AltosRecordMM.java
@@ -131,10 +131,10 @@ public class AltosRecordMM extends AltosRecord {
mag = old.mag;
}
+
+
public AltosRecordMM clone() {
- AltosRecordMM n = (AltosRecordMM) super.clone();
- n.copy(this);
- return n;
+ return new AltosRecordMM(this);
}
void make_missing() {
@@ -167,6 +167,10 @@ public class AltosRecordMM extends AltosRecord {
make_missing();
}
+ public AltosRecordMM(AltosRecordMM old) {
+ copy(old);
+ }
+
public AltosRecordMM() {
super();
make_missing();
diff --git a/altoslib/AltosRecordNone.java b/altoslib/AltosRecordNone.java
index ca0a5fe3..d4ea305f 100644
--- a/altoslib/AltosRecordNone.java
+++ b/altoslib/AltosRecordNone.java
@@ -28,6 +28,10 @@ public class AltosRecordNone extends AltosRecord {
super.copy(old);
}
+ public AltosRecordNone clone() {
+ return new AltosRecordNone(this);
+ }
+
public AltosRecordNone() {
super();
}
diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java
index 9530be31..f6ed4966 100644
--- a/altoslib/AltosRecordTM.java
+++ b/altoslib/AltosRecordTM.java
@@ -149,9 +149,7 @@ public class AltosRecordTM extends AltosRecord {
}
public AltosRecordTM clone() {
- AltosRecordTM n = (AltosRecordTM) super.clone();
- n.copy(this);
- return n;
+ return new AltosRecordTM(this);
}
void make_missing() {
@@ -177,6 +175,10 @@ public class AltosRecordTM extends AltosRecord {
make_missing();
}
+ public AltosRecordTM(AltosRecordTM old) {
+ copy(old);
+ }
+
public AltosRecordTM() {
super();
make_missing();
diff --git a/altoslib/AltosSpeed.java b/altoslib/AltosSpeed.java
index af63ed17..4e2daf5a 100644
--- a/altoslib/AltosSpeed.java
+++ b/altoslib/AltosSpeed.java
@@ -21,19 +21,19 @@ public class AltosSpeed extends AltosUnits {
public double value(double v) {
if (AltosConvert.imperial_units)
- return AltosConvert.meters_to_feet(v);
+ return AltosConvert.meters_to_mph(v);
return v;
}
public String show_units() {
if (AltosConvert.imperial_units)
- return "ft/s";
+ return "mph";
return "m/s";
}
public String say_units() {
if (AltosConvert.imperial_units)
- return "feet per second";
+ return "miles per hour";
return "meters per second";
}
diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java
index 218c598a..4f59c840 100644
--- a/altoslib/AltosState.java
+++ b/altoslib/AltosState.java
@@ -200,10 +200,10 @@ public class AltosState {
}
ngps++;
}
- } else
- pad_alt = ground_altitude;
-
- data.new_gps = false;
+ } else {
+ if (ngps == 0)
+ pad_alt = ground_altitude;
+ }
gps_waiting = MIN_PAD_SAMPLES - npad;
if (gps_waiting < 0)
diff --git a/altoslib/AltosUnitsListener.java b/altoslib/AltosUnitsListener.java
new file mode 100644
index 00000000..50a00cdf
--- /dev/null
+++ b/altoslib/AltosUnitsListener.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+public interface AltosUnitsListener {
+ public void units_changed(boolean imperial_units);
+}
diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am
index 0086bc65..1b03c925 100644
--- a/altoslib/Makefile.am
+++ b/altoslib/Makefile.am
@@ -69,6 +69,7 @@ AltosLib_JAVA = \
$(SRC)/AltosTelemetryRecordSensor.java \
$(SRC)/AltosTelemetryRecordMegaSensor.java \
$(SRC)/AltosTelemetryRecordMegaData.java \
+ $(SRC)/AltosUnitsListener.java \
$(SRC)/AltosMs5607.java \
$(SRC)/AltosIMU.java \
$(SRC)/AltosMag.java \