Charlie Mooney | 0866191 | 2015-04-16 09:20:34 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """ This is a module containing functions that allow the test suite to |
| 6 | determine the specifics of the gesture and execute them on the touchbot. |
| 7 | In essence, you use this class to go from a Test object to the robot |
| 8 | actually performing the correct gesture on the pad. |
| 9 | """ |
| 10 | |
| 11 | from threading import Thread |
| 12 | |
| 13 | import colorama as color |
| 14 | |
| 15 | import tests |
| 16 | from touchbot import Touchbot |
| 17 | |
| 18 | |
| 19 | BUFFER_SIZE = 0.1 |
| 20 | LEFT = BUFFER_SIZE |
| 21 | RIGHT = 1.0 - BUFFER_SIZE |
| 22 | TOP = BUFFER_SIZE |
| 23 | BOTTOM = 1.0 - BUFFER_SIZE |
| 24 | CENTER = 0.5 |
| 25 | |
| 26 | LOCATION_COORDINATES = { |
| 27 | tests.GV.TL: (LEFT, TOP), |
| 28 | tests.GV.TR: (RIGHT, TOP), |
| 29 | tests.GV.BL: (LEFT, BOTTOM), |
| 30 | tests.GV.BR: (RIGHT, BOTTOM), |
| 31 | tests.GV.TS: (CENTER, TOP), |
| 32 | tests.GV.BS: (CENTER, BOTTOM), |
| 33 | tests.GV.LS: (LEFT, CENTER), |
| 34 | tests.GV.RS: (RIGHT, CENTER), |
| 35 | tests.GV.CENTER: (CENTER, CENTER), |
| 36 | } |
| 37 | |
| 38 | |
| 39 | def PerformCorrespondingGesture(test, variation_number, robot, device_spec): |
| 40 | variation = test.variations[variation_number] |
| 41 | fn = None |
| 42 | if test.name == tests.NOISE_STATIONARY: |
| 43 | fn = lambda: _PerformStationaryNoiseTest(variation, robot, device_spec) |
| 44 | |
| 45 | if fn is None: |
| 46 | print color.Fore.RED + 'Error: Robot unable to perform gesture!' |
| 47 | return None |
| 48 | |
| 49 | return Thread(target=fn) |
| 50 | |
| 51 | def _PerformStationaryNoiseTest(variation, robot, device_spec): |
| 52 | frequency, amplitude, waveform, location = variation |
Charlie Mooney | c68f9c3 | 2015-04-16 15:23:22 -0700 | [diff] [blame] | 53 | robot.Tap(device_spec, LOCATION_COORDINATES[location], touch_time_s=4) |