summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-07-11 14:44:24 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-07-13 16:15:11 +0000
commit2cf816e4e22f10d1af7f64e845e808f622f29301 (patch)
treec884eceb1b31a02b75b71783a50a59070eab200f
parenta5d1b7169f7ca04cbac7c5bab33602b9eb6f49b4 (diff)
downloadchrome-ec-2cf816e4e22f10d1af7f64e845e808f622f29301.tar.gz
motion_lid: Increase precision in noisy mag check.
This commit increases the precision used in the noisy magnitude deviation check by multiplying the scaled sensor data by 8 in the intermediate calculations. Prior to this, due to some bits being lost, certain devices would determine the lid angle as unreliable in specific angles, even though the device was at rest. BUG=b:63148973 BRANCH=eve,gru,reef TEST=Flash bob, set DUT on desk, run `while true; do ectool motionsense lid_angle; sleep 0.1; done`, slowly move the lid from 15 degrees until ~350. Verify that no particular angle results in a unreliable lid angle reading. TEST=Run `evtest` and examing cros-ec-buttons, fold screen all the way back to make tablet mode, shake device for at least 30s. Verify that there are no spurious transitions of the tablet mode switch. TEST=Repeat above tests on kevin. Change-Id: Iff06c1df2dd33c60e26a59183f62f29b71548729 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/567050 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org> (cherry picked from commit df09bc2c83c70716afcfd73e4eadf8cda0195848) Reviewed-on: https://chromium-review.googlesource.com/570340 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Trybot-Ready: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--common/motion_lid.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/common/motion_lid.c b/common/motion_lid.c
index c1b41e7720..4a89bcd605 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -256,16 +256,28 @@ static int calculate_lid_angle(const vector_3_t base, const vector_3_t lid,
lid_range = accel_lid->drv->get_range(accel_lid);
for (i = X; i <= Z; i++) {
- scaled_base[i] = base[i] * base_range * 10 / (1 << 15);
- scaled_lid[i] = lid[i] * lid_range * 10 / (1 << 15);
+ /*
+ * To increase precision, we'll use 8x the sensor data in the
+ * intermediate calculation. We would normally divide by 2^15.
+ *
+ * This is safe because even at a range of 8g, calculating the
+ * magnitude squared should still be less than the max of a
+ * 32-bit signed integer.
+ *
+ * The max that base[i] could be is 32768, resulting in a max
+ * value for scaled_base[i] of 640 @ 8g range and force.
+ * Typically our range is set to 2g.
+ */
+ scaled_base[i] = base[i] * base_range * 10 >> 12;
+ scaled_lid[i] = lid[i] * lid_range * 10 >> 12;
}
- base_magnitude2 = scaled_base[X] * scaled_base[X] +
- scaled_base[Y] * scaled_base[Y] +
- scaled_base[Z] * scaled_base[Z];
- lid_magnitude2 = scaled_lid[X] * scaled_lid[X] +
- scaled_lid[Y] * scaled_lid[Y] +
- scaled_lid[Z] * scaled_lid[Z];
+ base_magnitude2 = (scaled_base[X] * scaled_base[X] +
+ scaled_base[Y] * scaled_base[Y] +
+ scaled_base[Z] * scaled_base[Z]) >> 6;
+ lid_magnitude2 = (scaled_lid[X] * scaled_lid[X] +
+ scaled_lid[Y] * scaled_lid[Y] +
+ scaled_lid[Z] * scaled_lid[Z]) >> 6;
/*
* Check to see if they differ than more than NOISY_MAGNITUDE_DEVIATION.