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