Drag thumb support for touchbot

This CL adds support for the first 2-finger probes -- the
thumb fingertips.  This adds in robot support for the thumb
edge drag test where it uses a "thumb" probe to draw several
lines on the pad.

BUG=chromium:474709
TEST=manual testing

Change-Id: I9f42863595c23ab3ea554ac826fb0a07979d6dec
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/270003
diff --git a/gesture_interpreter.py b/gesture_interpreter.py
index e18039b..96e851a 100644
--- a/gesture_interpreter.py
+++ b/gesture_interpreter.py
@@ -82,6 +82,31 @@
 ]
 
 
+def _ComputePerpendicularAngle(start, end):
+  """ Compute the fingertip angle to be perpendicular to the
+  movement direction.
+
+  The robot's X/Y axes are not in the same direction as the touch device's,
+  they are flipped.
+
+  DUT  x ---->      Robot  y ---->
+      y                   x
+      |                   |
+      |                   |
+      \/                  \/
+
+  As a result the angle is computed in the DUT space, but then must have
+  its sign flipped before being used in any commands to the robot or
+  everything will be wrong since it's a clockwise angle instead of counter-
+  clockwise.
+  """
+  x1, y1 = start
+  x2, y2 = end
+  dy = y2 - y1
+  dx = x2 - x1
+  return -1 * (math.degrees(math.atan2(y2 - y1, x2 - x1)) + 90)
+
+
 def PerformCorrespondingGesture(test, variation_number, robot, device_spec):
   variation = test.variations[variation_number]
   fn = None
@@ -100,6 +125,8 @@
     fn = lambda: _PerformRestingFingerTest(variation, robot, device_spec)
   elif test.name == tests.PINCH_TO_ZOOM:
     fn = lambda: _PerformPinchTest(variation, robot, device_spec)
+  elif test.name == tests.DRAG_THUMB_EDGE:
+    fn = lambda: _PerformThumbEdgeTest(variation, robot, device_spec)
 
   if fn is None:
     print color.Fore.RED + 'Error: Robot unable to perform gesture!'
@@ -145,14 +172,7 @@
 def _PerformTwoFingerLineTest(variation, robot, device_spec):
   direction, speed = variation
   start, end = LINE_DIRECTION_COORDINATES[direction]
-
-  # Compute the fingertip angle to be perpendicular to the
-  # movement direction
-  x1, y1 = start
-  x2, y2 = end
-  dy = y2 - y1
-  dx = x2 - x1
-  angle = -1 * (math.degrees(math.atan2(y2 - y1, x2 - x1)) + 90)
+  angle = _ComputePerpendicularAngle(start, end)
 
   fingertips = [robot.fingertips[STANDARD_FINGERTIP],
                 robot.fingertips[STANDARD_SECONDARY_FINGERTIP]]
@@ -194,3 +214,14 @@
   robot.Pinch(device_spec, fingertips, (CENTER, CENTER), ANGLES[angle],
               start_distance, end_distance)
   robot.PopSpeed()
+
+def _PerformThumbEdgeTest(variation, robot, device_spec):
+  fingertip_type, direction = variation
+  start, end = LINE_DIRECTION_COORDINATES[direction]
+  angle = _ComputePerpendicularAngle(start, end)
+
+  fingertip = robot.fingertips[fingertip_type]
+
+  robot.PushSpeed(SPEEDS[tests.GV.NORMAL])
+  robot.Line(device_spec, [fingertip], start, end, fingertip_angle=angle)
+  robot.PopSpeed()