diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2018-12-17 15:14:00 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-26 17:27:00 -0700 |
commit | 40f9e2fc0f2354e033553131fd63cfb9f755a2e2 (patch) | |
tree | 1498d7190aece44697f3bee0e797565391f99750 /test/motion_angle_tablet.c | |
parent | 4a48404aeea58bfe0c31d5fea554b5329a223131 (diff) | |
download | chrome-ec-40f9e2fc0f2354e033553131fd63cfb9f755a2e2.tar.gz |
motion_lid: Rewrite lid angle calculation based on chromium code
Use code from ash/wm/tablet_mode/tablet_mode_controller.cc, in
particular TabletModeController::HandleHingeRotation()
to calculate lid angle.
Add unit tests based on
ash/wm/tablet_mode/tablet_mode_controller_unittest.cc and the data file
accelerometer_test_data_literals.cc.
BUG=b:120346412
BRANCH=none
TEST=Check unit tests pass, check it compile on FPU based EC, EC without
FPU and no 64 bit support (ampton).
Check lid calculation is correct on eve:
- with "while true ; do ectool motionsense lid_angle ; sleep 1 ; done"
Check when hinge is almost vertical lid angle is close to constant or
marked are unrieliable.
Check when shaking device, lid angle is also unreliable
Check with evtest SW_TABLET_MODE event is trigger when lid angle is
available and cross 180 region.
Change-Id: I545f7333ed9b53accedb75f238f747f66bae1f5d
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1388844
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'test/motion_angle_tablet.c')
-rw-r--r-- | test/motion_angle_tablet.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/motion_angle_tablet.c b/test/motion_angle_tablet.c new file mode 100644 index 0000000000..ee241d3172 --- /dev/null +++ b/test/motion_angle_tablet.c @@ -0,0 +1,111 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Test motion sense code, when in tablet mode. + */ + +#include <math.h> +#include <stdio.h> + +#include "accelgyro.h" +#include "common.h" +#include "gpio.h" +#include "hooks.h" +#include "motion_common.h" +#include "motion_lid.h" +#include "motion_sense.h" +#include "tablet_mode.h" +#include "test_util.h" +#include "util.h" + + +/*****************************************************************************/ +/* Test utilities */ + +/* convert array value from g to m.s^2. */ +int filler(const struct motion_sensor_t *s, const float v) +{ + return FP_TO_INT( fp_div( + FLOAT_TO_FP(v) * MOTION_SCALING_FACTOR, + fp_mul(INT_TO_FP(s->drv->get_range(s)), MOTION_ONE_G))); +} + +static int test_lid_angle_less180(void) +{ + int index = 0, lid_angle; + struct motion_sensor_t *lid = &motion_sensors[ + CONFIG_LID_ANGLE_SENSOR_LID]; + struct motion_sensor_t *base = &motion_sensors[ + CONFIG_LID_ANGLE_SENSOR_BASE]; + + /* We don't have TASK_CHIP so simulate init ourselves */ + hook_notify(HOOK_CHIPSET_SHUTDOWN); + TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S5); + TEST_ASSERT(lid->drv->get_data_rate(lid) == 0); + TEST_ASSERT(motion_interval == 0); + + /* Go to S0 state */ + hook_notify(HOOK_CHIPSET_SUSPEND); + hook_notify(HOOK_CHIPSET_RESUME); + msleep(1000); + TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S0); + TEST_ASSERT(lid->drv->get_data_rate(lid) == TEST_LID_FREQUENCY); + TEST_ASSERT(motion_interval == TEST_LID_EC_RATE); + + /* Open lid, testing close to 180 degree. */ + gpio_set_level(GPIO_LID_OPEN, 1); + msleep(1000); + + cprints(CC_ACCEL, "start loop"); + /* Force clamshell mode, to be sure we go in tablet mode ASAP. */ + tablet_set_mode(0); + + /* Check we stay in tablet mode, even when hinge is vertical. */ + while (index < kAccelerometerVerticalHingeTestDataLength) { + feed_accel_data(kAccelerometerVerticalHingeTestData, + &index, filler); + wait_for_valid_sample(); + lid_angle = motion_lid_get_angle(); + cprints(CC_ACCEL, "%d : LID(%d, %d, %d)/BASE(%d, %d, %d): %d", + index / TEST_LID_SAMPLE_SIZE, + lid->xyz[X], lid->xyz[Y], lid->xyz[Z], + base->xyz[X], base->xyz[Y], base->xyz[Z], + lid_angle); + /* We need few sample to debounce and enter laptop mode. */ + TEST_ASSERT(index < 2 * TEST_LID_SAMPLE_SIZE * \ + (TABLET_MODE_DEBOUNCE_COUNT + 2) || + tablet_get_mode()); + } + /* + * Check we stay in tablet mode, even when hinge is vertical and + * shaked. + */ + tablet_set_mode(0); + while (index < kAccelerometerVerticalHingeUnstableTestDataLength) { + feed_accel_data(kAccelerometerVerticalHingeUnstableTestData, + &index, filler); + wait_for_valid_sample(); + lid_angle = motion_lid_get_angle(); + cprints(CC_ACCEL, "%d : LID(%d, %d, %d)/BASE(%d, %d, %d): %d", + index / TEST_LID_SAMPLE_SIZE, + lid->xyz[X], lid->xyz[Y], lid->xyz[Z], + base->xyz[X], base->xyz[Y], base->xyz[Z], + lid_angle); + /* We need few sample to debounce and enter laptop mode. */ + TEST_ASSERT(index < TEST_LID_SAMPLE_SIZE * + (TABLET_MODE_DEBOUNCE_COUNT + 2) || + tablet_get_mode()); + } + return EC_SUCCESS; +} + + +void run_test(void) +{ + test_reset(); + + RUN_TEST(test_lid_angle_less180); + + test_print_result(); +} |