altoslib: Ignore invalid accel cal values
authorKeith Packard <keithp@keithp.com>
Sun, 28 May 2017 22:21:53 +0000 (15:21 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 28 May 2017 22:22:30 +0000 (15:22 -0700)
When both are the same, something is wrong.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosCalData.java
altoslib/AltosConvert.java

index 54b7581..408d8d7 100644 (file)
@@ -98,6 +98,8 @@ public class AltosCalData {
 
        public void set_accel_plus_minus(double plus, double minus) {
                if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
+                       if (plus == minus)
+                               return;
                        accel_plus_g = plus;
                        accel_minus_g = minus;
                }
index 5b3ff39..a252abd 100644 (file)
@@ -403,6 +403,10 @@ public class AltosConvert {
 
                double counts_per_g = (plus_g - minus_g) / 2.0;
                double counts_per_mss = counts_per_g / gravity;
+
+               if (counts_per_mss == 0)
+                       return AltosLib.MISSING;
+
                return (sensor - ground) / counts_per_mss;
        }