summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphilipchen <philipchen@google.com>2017-03-14 17:40:49 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-03-17 20:12:23 -0700
commit7814f3319e7331ae9f3313d2a04e14b0bc1f1a90 (patch)
treef4b703508cee133a111c0620763af54db1615b1e
parent80cb93f45d396d797a47ab478dd62f9d29be7b3b (diff)
downloadchrome-ec-7814f3319e7331ae9f3313d2a04e14b0bc1f1a90.tar.gz
motion_lid: no angle correction when lid close
BUG=b:36107214 BRANCH=gru TEST=manually on kevin: (1) make DUT in tablet mode (2) swiftly close the lid (3) check ec log and confirm DUT can read small angle and turn into clamshell mode when lid is closed. TEST=make runtests Change-Id: I7ebf10d38a8b300960ebf46be717d48522c6fd0b Reviewed-on: https://chromium-review.googlesource.com/455458 Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 75ba9147c392367037c21e79899f463c32c1f92f) Reviewed-on: https://chromium-review.googlesource.com/457137 Commit-Ready: Philip Chen <philipchen@chromium.org>
-rw-r--r--common/motion_lid.c7
-rw-r--r--test/motion_lid.c14
2 files changed, 19 insertions, 2 deletions
diff --git a/common/motion_lid.c b/common/motion_lid.c
index 8572db928c..d36ecc5e64 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -323,11 +323,14 @@ static int calculate_lid_angle(const vector_3_t base, const vector_3_t lid,
/*
* If the angle was last seen as really large and now it's quite
* small, we may be rotating around from 360->0 so correct it to
- * be large.
+ * be large. But in case that the lid switch is closed, we can
+ * prove the small angle we see is correct so we take the angle
+ * as is.
*/
if ((last_lid_angle_fp >=
FLOAT_TO_FP(360) - DEBOUNCE_ANGLE_DELTA) &&
- (lid_to_base_fp <= DEBOUNCE_ANGLE_DELTA))
+ (lid_to_base_fp <= DEBOUNCE_ANGLE_DELTA) &&
+ (lid_is_open()))
last_lid_angle_fp = FLOAT_TO_FP(360) - lid_to_base_fp;
else
last_lid_angle_fp = lid_to_base_fp;
diff --git a/test/motion_lid.c b/test/motion_lid.c
index dfea3ecf91..bed03379ff 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -316,6 +316,20 @@ static int test_lid_angle(void)
wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE);
+ /*
+ * Open the lid to 350, and then close the lid and set the angle
+ * to 10. The reading of small angle shouldn't be corrected.
+ */
+ gpio_set_level(GPIO_LID_OPEN, 1);
+ msleep(100);
+ gpio_set_level(GPIO_LID_OPEN, 0);
+ msleep(100);
+ lid->xyz[X] = 0;
+ lid->xyz[Y] = 173;
+ lid->xyz[Z] = -984;
+ wait_for_valid_sample();
+ TEST_ASSERT(motion_lid_get_angle() == 10);
+
return EC_SUCCESS;
}