summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2016-11-10 19:22:13 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-11-15 03:09:02 -0800
commit1d093deb54a2713295add2ebae41f6c2abb78e62 (patch)
tree4df60c09380dacab8e981a8ac2c7e161c8a6d743
parentcfe12b90bc4af5ad8ea7527ff227c7a2de3800ef (diff)
downloadchrome-ec-1d093deb54a2713295add2ebae41f6c2abb78e62.tar.gz
motion_lid: Make tablet mode great (again).
Chrome seems to pay attention to the tablet mode switch reported by the EC. However, for some devices that don't actually have a switch and use the lid angle as a "virtual" switch, it's possible for invalid tablet mode change events to be reported. This is because a single reading could flip the switch. This commit adds some debouncing to the tablet mode event changes. Instead of having a single event be able to change the tablet mode switch, we will now perform TABLET_MODE_DEBOUNCE_COUNT number of calculations of the new tablet mode value. If those calculations all agree, then we'll flip the switch. This should help mitigate false tablet mode change events caused by spurious forces. BUG=chrome-os-partner:59203 BUG=chrome-os-partner:59480 BRANCH=gru TEST=flash kevin; open lid to pi/2 rad; rotate device counter-clockwise pi/2 rad; shake device and verify that tablet mode doesn't change easily. TEST=verify that tablet mode still works. Change-Id: Id020f7db28e93e53b276b3f0d28a40251f035f0b Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/410942 Commit-Ready: Gwendal Grignou <gwendal@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
-rw-r--r--common/motion_lid.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/common/motion_lid.c b/common/motion_lid.c
index 3209492a65..f2c6863b80 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -58,6 +58,16 @@
#define TABLET_ZONE_LID_ANGLE FLOAT_TO_FP(300)
#define LAPTOP_ZONE_LID_ANGLE FLOAT_TO_FP(240)
+/*
+ * We will change our tablet mode status when we are "convinced" that it has
+ * changed. This means we will have to consecutively calculate our new tablet
+ * mode while the angle is stable and come to the same conclusion. The number
+ * of consecutive calculations is the debounce count with an interval between
+ * readings set by the motion_sense task. This should avoid spurious forces
+ * that may trigger false transitions of the tablet mode switch.
+ */
+#define TABLET_MODE_DEBOUNCE_COUNT 3
+static int tablet_mode_debounce_cnt = TABLET_MODE_DEBOUNCE_COUNT;
#endif
#ifdef CONFIG_LID_ANGLE_INVALID_CHECK
@@ -230,13 +240,31 @@ static int calculate_lid_angle(const vector_3_t base, const vector_3_t lid,
*lid_angle = FP_TO_INT(last_lid_angle_fp + FLOAT_TO_FP(0.5));
#ifdef CONFIG_LID_ANGLE_TABLET_MODE
- if (last_lid_angle_fp > TABLET_ZONE_LID_ANGLE)
- new_tablet_mode = 1;
- else if (last_lid_angle_fp < LAPTOP_ZONE_LID_ANGLE)
- new_tablet_mode = 0;
- if (tablet_get_mode() != new_tablet_mode) {
- tablet_set_mode(new_tablet_mode);
- hook_notify(HOOK_TABLET_MODE_CHANGE);
+ if (reliable) {
+ if (last_lid_angle_fp > TABLET_ZONE_LID_ANGLE)
+ new_tablet_mode = 1;
+ else if (last_lid_angle_fp < LAPTOP_ZONE_LID_ANGLE)
+ new_tablet_mode = 0;
+
+ /* Only change tablet mode if we're sure. */
+ if (tablet_get_mode() != new_tablet_mode) {
+ if (tablet_mode_debounce_cnt == 0) {
+ /* Alright, we're convinced. */
+ tablet_mode_debounce_cnt =
+ TABLET_MODE_DEBOUNCE_COUNT;
+ tablet_set_mode(new_tablet_mode);
+ hook_notify(HOOK_TABLET_MODE_CHANGE);
+ return reliable;
+ }
+ tablet_mode_debounce_cnt--;
+ return reliable;
+ }
+
+ /*
+ * Since it hasn't changed, clear any pending tablet mode
+ * change.
+ */
+ tablet_mode_debounce_cnt = TABLET_MODE_DEBOUNCE_COUNT;
}
#endif /* CONFIG_LID_ANGLE_TABLET_MODE */
#else /* CONFIG_LID_ANGLE_INVALID_CHECK */