summaryrefslogtreecommitdiff
path: root/test/motion_lid.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2016-12-01 14:33:01 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-20 22:40:32 -0800
commit2b54aa9a9b061117021eff22385c9de474ab090b (patch)
treee3c3b6c9605ea16d1cf79c513bca3c6e4198ae44 /test/motion_lid.c
parent36093bee5f12f83500798d8beb2b3e6a3bd25972 (diff)
downloadchrome-ec-2b54aa9a9b061117021eff22385c9de474ab090b.tar.gz
CHERRY-PICK: motion_lid: Add more reliability measurements.
Previously in motion lid, we only considered the lid angle as unreliable when the hinge is too closely aligned with the direction of gravity. However, there are other cases where the lid angle can be unreliable. For example, when the device is being shaken and is under acceleration that's not solely due to gravity. This commit adds some more checks for a reliable lid angle measurement. - Checking if the device is significant motion by checking the deviation of the magnitudes of the base and lid vectors. - Making sure that the calculated angles agree with the current state of the lid switch. BUG=chrome-os-partner:59480 BUG=chrome-os-partner:59203 BRANCH=gru,cyan,glados,oak TEST=Flash kevin; use ectool motionsense lid_angle and monitor the instantaneous lid angle. Verify that unreliable is reported for cases where the device is under significant motion. TEST=Flash kevin; use evtest to monitor the tablet mode switch. Verify that tablet mode switch is much more robust. Change-Id: I4bd9e818e617b056364cce2e46385e743a7522d4 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/430344 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'test/motion_lid.c')
-rw-r--r--test/motion_lid.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/test/motion_lid.c b/test/motion_lid.c
index f610250e9c..dfea3ecf91 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -10,6 +10,7 @@
#include "accelgyro.h"
#include "common.h"
+#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "motion_lid.h"
@@ -206,6 +207,7 @@ static int test_lid_angle(void)
lid->xyz[X] = 0;
lid->xyz[Y] = 0;
lid->xyz[Z] = -1000;
+ gpio_set_level(GPIO_LID_OPEN, 0);
/* Initial wake up, like init does */
task_wake(TASK_ID_MOTIONSENSE);
@@ -220,7 +222,10 @@ static int test_lid_angle(void)
lid->xyz[X] = 0;
lid->xyz[Y] = 1000;
lid->xyz[Z] = 0;
+ gpio_set_level(GPIO_LID_OPEN, 1);
+ msleep(100);
wait_for_valid_sample();
+
TEST_ASSERT(motion_lid_get_angle() == 90);
/* Set lid open to 225. */
@@ -237,12 +242,15 @@ static int test_lid_angle(void)
wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 350);
- /* Set lid open to 10, check rotation did not change. */
+ /*
+ * Set lid open to 10. Since the lid switch still indicates that it's
+ * open, we should be getting an unreliable reading.
+ */
lid->xyz[X] = 0;
lid->xyz[Y] = 173;
lid->xyz[Z] = -984;
wait_for_valid_sample();
- TEST_ASSERT(motion_lid_get_angle() == 350);
+ TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE);
/* Rotate back to 180 and then 10 */
lid->xyz[X] = 0;
@@ -251,11 +259,15 @@ static int test_lid_angle(void)
wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 180);
+ /*
+ * Again, since the lid isn't closed, the angle should be unreliable.
+ * See SMALL_LID_ANGLE_RANGE.
+ */
lid->xyz[X] = 0;
lid->xyz[Y] = 173;
lid->xyz[Z] = -984;
wait_for_valid_sample();
- TEST_ASSERT(motion_lid_get_angle() == 10);
+ TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE);
/*
* Align base with hinge and make sure it returns unreliable for angle.
@@ -280,6 +292,30 @@ static int test_lid_angle(void)
wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 180);
+ /*
+ * Close the lid and set the angle to 0.
+ */
+ base->xyz[X] = 0;
+ base->xyz[Y] = 0;
+ base->xyz[Z] = 1000;
+ lid->xyz[X] = 0;
+ lid->xyz[Y] = 0;
+ lid->xyz[Z] = -1000;
+ gpio_set_level(GPIO_LID_OPEN, 0);
+ msleep(100);
+ wait_for_valid_sample();
+ TEST_ASSERT(motion_lid_get_angle() == 0);
+
+ /*
+ * Make the angle large, but since the lid is closed, the angle should
+ * be regarded as unreliable.
+ */
+ lid->xyz[X] = 0;
+ lid->xyz[Y] = -173;
+ lid->xyz[Z] = -984;
+ wait_for_valid_sample();
+ TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE);
+
return EC_SUCCESS;
}