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 15:05:42 +0000
commit5d857ed8c708b7aecd51cba9f0cbf337c6abc64e (patch)
tree3b950b1ff7a03b686024841b95c0b1a24790cb65
parent24514961d04696eaea2fc7bac74e374f545f672b (diff)
downloadchrome-ec-5d857ed8c708b7aecd51cba9f0cbf337c6abc64e.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/570338 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: 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 eaf657b736..98f7d49443 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.