summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}