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>
1 file changed