summaryrefslogtreecommitdiff
path: root/common/body_detection.c
diff options
context:
space:
mode:
authorChing-Kang Yen <chingkang@chromium.org>2020-10-14 15:57:21 +0800
committerCommit Bot <commit-bot@chromium.org>2020-11-13 06:29:13 +0000
commitb0f1017dd711f095efdac3db4c743e128c499056 (patch)
treef9c4218183062a4f37ddaf64b0ac6c4cd4ba2c83 /common/body_detection.c
parent412ace563010211981c83f9063fb2e0ed9c6df3b (diff)
downloadchrome-ec-b0f1017dd711f095efdac3db4c743e128c499056.tar.gz
common: motion_sense: Add spoofing activity
make spoof command able to spoof activity state: ectool motionsense spoof -- NUM activity ACT [EN] [0/1] This commit also remove unused parameter |sensor_num| from list_activities, set_activity, get_activity in ectool. BRANCH=None BUG=b:123434029 TEST=buildall TEST=ectool motionsense spoof 4 activity 4 1 0 ectool motionsense spoof 4 activity 4 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 1 1 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 0 ectool motionsense get_activity 4 ectool motionsense spoof 4 activity 4 1 ectool motionsense get_activity 4 Signed-off-by: Ching-Kang Yen <chingkang@chromium.org> Change-Id: I819c156ae7fe50c5cf6216d0f44012d192fb528e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2477393 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'common/body_detection.c')
-rw-r--r--common/body_detection.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/common/body_detection.c b/common/body_detection.c
index c15e1bc6bb..ed74a2545d 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -29,6 +29,7 @@ static enum body_detect_states motion_state = BODY_DETECTION_OFF_BODY;
static bool history_initialized;
static bool body_detect_enable;
+STATIC_IF(CONFIG_ACCEL_SPOOF_MODE) bool spoof_enable;
static struct body_detect_motion_data
{
@@ -90,8 +91,10 @@ static int calculate_motion_confidence(uint64_t var)
}
/* Change the motion state and commit the change to AP. */
-void body_detect_change_state(enum body_detect_states state)
+void body_detect_change_state(enum body_detect_states state, bool spoof)
{
+ if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && spoof_enable && !spoof)
+ return;
if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
struct ec_response_motion_sensor_data vector = {
.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP,
@@ -172,7 +175,7 @@ void body_detect_reset(void)
int resolution = body_sensor->drv->get_resolution(body_sensor);
int rms_noise = body_sensor->drv->get_rms_noise(body_sensor);
- body_detect_change_state(BODY_DETECTION_ON_BODY);
+ body_detect_change_state(BODY_DETECTION_ON_BODY, false);
/*
* The sensor is suspended since its ODR is 0,
* there is no need to reset until sensor is up again
@@ -208,7 +211,7 @@ void body_detect(void)
switch (motion_state) {
case BODY_DETECTION_OFF_BODY:
if (motion_confidence > CONFIG_BODY_DETECTION_ON_BODY_CON)
- body_detect_change_state(BODY_DETECTION_ON_BODY);
+ body_detect_change_state(BODY_DETECTION_ON_BODY, false);
break;
case BODY_DETECTION_ON_BODY:
stationary_timeframe += 1;
@@ -218,7 +221,8 @@ void body_detect(void)
/* if no motion for enough time, change state to off_body */
if (stationary_timeframe >=
CONFIG_BODY_DETECTION_STATIONARY_DURATION * window_size)
- body_detect_change_state(BODY_DETECTION_OFF_BODY);
+ body_detect_change_state(BODY_DETECTION_OFF_BODY,
+ false);
break;
}
}
@@ -226,10 +230,25 @@ void body_detect(void)
void body_detect_set_enable(int enable)
{
body_detect_enable = enable;
- body_detect_change_state(BODY_DETECTION_ON_BODY);
+ body_detect_change_state(BODY_DETECTION_ON_BODY, false);
}
int body_detect_get_enable(void)
{
return body_detect_enable;
}
+
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+void body_detect_set_spoof(int enable)
+{
+ spoof_enable = enable;
+ /* After disabling spoof mode, commit current state. */
+ if (!enable)
+ body_detect_change_state(motion_state, false);
+}
+
+bool body_detect_get_spoof(void)
+{
+ return spoof_enable;
+}
+#endif