blob: c09e47629efa829a497557b5648ed7e072d5951e [file] [log] [blame]
Charlie Mooney48d2b4e2015-08-18 09:02:50 -07001# 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
5import optparse
6import os
7import sys
8from touchbot import Touchbot, DeviceSpec
9
10REPORT_LOCATION = 'report.html'
11
12def parse_arguments():
13 parser = optparse.OptionParser()
14 parser.add_option('-n', '--name', dest='name', default='unknown_device',
15 help='The name of this DUT. This is used by the robot to '
16 'store calibration info')
17 parser.add_option('--num_passes', dest='num_passes', default=32, type=int,
18 help='How many passes to make over the laser')
19 parser.add_option('-s', '--speed', dest='speed', default=30,
20 type=int, help='How fast to move the finger (0-100)')
21
22 (options, args) = parser.parse_args()
23
24 if options.speed > 100 or options.speed <= 0:
25 print 'ERROR: Speed (%d) must be between 0 and 100!' % options.speed
26 sys.exit(1)
27 if options.num_passes <= 0:
28 print ('ERROR: Meaningful test must use a positive number of passes, '
29 'not %d.' % options.num_passes)
30 sys.exit(1)
31
32 return options, args
33
34
35def main():
36 # Parse and validate the command line arguments
37 options, args = parse_arguments()
38
39 # Connect to the robot
40 robot = Touchbot()
41 if not robot.comm:
42 print 'Error: Unable to connect to the robot.'
43 sys.exit(1)
44
45 # Load the device spec (or calibrate a new spec if none is found)
46 device_spec_filename = './%s.p' % options.name
47 if os.path.isfile(device_spec_filename):
48 print 'Precalibrated spec found at "%s".' % device_spec_filename
49 print 'If this was unintended, delete that file or choose a new name.'
50 device_spec = DeviceSpec.LoadFromDisk(device_spec_filename)
51 else:
52 print 'No spec found (%s)' % device_spec_filename
53 print 'Please calibrate for %s, as instructed below.' % options.name
54 device_spec = robot.CalibrateDevice(device_spec_filename)
55
56 # Tell the robot to perform a Quickstep gesture
57 fingertips = [robot.fingertips[Touchbot.CALIBRATION_FINGERTIP1]]
58 robot.Quickstep(device_spec, fingertips, options.num_passes, options.speed)
59
60 return 0
61
62
63if __name__ == "__main__":
64 sys.exit(main())