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_common.h | |
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_common.h')
-rw-r--r-- | test/motion_common.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/motion_common.h b/test/motion_common.h new file mode 100644 index 0000000000..3adb9f24e5 --- /dev/null +++ b/test/motion_common.h @@ -0,0 +1,69 @@ +/* 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. + * + * Common test code to test lid angle calculation. + */ +#ifndef __CROS_EC_MOTION_COMMON_H +#define __CROS_EC_MOTION_COMMON_H + +#include "motion_sense.h" +/* + * Period in us for the motion task period. + * The task will read the vectors at that interval + */ +#define TEST_LID_EC_RATE (1 * MSEC) +#define TEST_LID_FREQUENCY (1e9 / TEST_LID_EC_RATE) /* mHz */ + +/* + * Time in ms to wait for the task to read the vectors. + */ +#define TEST_LID_SLEEP_RATE (TEST_LID_EC_RATE / 5) + +/* We gather 6 elements [2 vectors of 3 axis] per sample. */ +#define TEST_LID_SAMPLE_SIZE (2 * 3) + +extern enum chipset_state_mask sensor_active; +extern unsigned int motion_interval; + +extern struct motion_sensor_t motion_sensors[]; +extern const unsigned int motion_sensor_count; + +void wait_for_valid_sample(void); +void feed_accel_data(const float *array, int *idx, + int (filler)(const struct motion_sensor_t *s, const float f)); + +/* + * External data - from + * chromium/src/ash/wm/tablet_mode/tablet_mode_controller_unittest.cc + * + * Test accelerometer data taken with the lid at less than 180 degrees while + * shaking the device around. The data is to be interpreted in groups of 6 where + * each 6 values corresponds to the base accelerometer (-y / g, -x / g, -z / g) + * followed by the lid accelerometer (-y / g , x / g, z / g). + * [ CONFIG_ACCEL_STD_REF_FRAME_OLD must be defined to used this array. ] + */ +extern const float kAccelerometerLaptopModeTestData[]; +extern const size_t kAccelerometerLaptopModeTestDataLength; + +/* + * Test accelerometer data taken with the lid open 360 degrees while + * shaking the device around. The data is to be interpreted in groups of 6 where + * each 6 values corresponds to the base accelerometer (-y / g, -x / g, -z / g) + * followed by the lid accelerometer (-y / g , x / g, z / g). + * [ CONFIG_ACCEL_STD_REF_FRAME_OLD must be defined to used this array. ] + */ +extern const float kAccelerometerFullyOpenTestData[]; +extern const size_t kAccelerometerFullyOpenTestDataLength; + +/* + * Test accelerometer data taken with the lid open 360 degrees while the device + * hinge was nearly vertical, while shaking the device around. The data is to be + * interpreted in groups of 6 where each 6 values corresponds to the X, Y, and Z + * readings from the base and lid accelerometers in this order. + */ +extern const float kAccelerometerVerticalHingeTestData[]; +extern const size_t kAccelerometerVerticalHingeTestDataLength; +extern const float kAccelerometerVerticalHingeUnstableTestData[]; +extern const size_t kAccelerometerVerticalHingeUnstableTestDataLength; +#endif /* __CROS_EC_MOTION_COMMON_H */ |