mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 01:50:53 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
1b9a553ece
commit
df09bc2c83
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user