altoslib: Delay accel cal value adjustment until data all read
authorKeith Packard <keithp@keithp.com>
Thu, 29 Oct 2020 18:40:25 +0000 (11:40 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 18 Nov 2020 05:40:21 +0000 (21:40 -0800)
Instead of trying to compute these values as soon as the necessary
data are available, delay until all data are available as which data
are necessary depends on the target device, and some target devices
don't have some of the data values at all.

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

index bb7f5bcc374a8ef725df606761dae2607a3b5d52..ea7b63fa5813e963eabc60786258135c785ae8e0 100644 (file)
@@ -321,6 +321,9 @@ public class AltosConfigData {
        /* Return + accel calibration relative to a specific pad orientation */
        public int accel_cal_plus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -338,6 +341,9 @@ public class AltosConfigData {
        /* Return - accel calibration relative to a specific pad orientation */
        public int accel_cal_minus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -357,6 +363,7 @@ public class AltosConfigData {
         */
        private void adjust_accel_cal() {
                if (!accel_cal_adjusted &&
+                   product != null &&
                    pad_orientation != AltosLib.MISSING &&
                    accel_cal_plus != AltosLib.MISSING &&
                    accel_cal_minus != AltosLib.MISSING)
@@ -538,9 +545,6 @@ public class AltosConfigData {
                                }
                        }
                } catch (Exception e) {}
-
-               /* Fix accel cal as soon as all of the necessary values appear */
-               adjust_accel_cal();
        }
 
        public AltosConfigData() {
@@ -914,5 +918,6 @@ public class AltosConfigData {
                        read_link(link, "done");
                        break;
                }
+               adjust_accel_cal();
        }
 }