1 # Copyright 2014 The Chromium 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.
5 """Package entry-point."""
10 from tornado
import ioloop
13 import hid_echo_gadget
14 import keyboard_gadget
21 """Parse application arguments."""
22 parser
= argparse
.ArgumentParser(description
='USB gadget server.')
24 '-i', '--interface', default
='lo',
25 help='Listen for HTTP connections on this interface.')
27 '-p', '--port', default
=8080,
28 help='Listen for HTTP connections on this port.')
30 '--hardware', default
='beaglebone-black',
31 help='Hardware configuration.')
34 help='Start with the device claimed by this client.')
35 return parser
.parse_args()
41 server
.interface
= args
.interface
42 server
.port
= args
.port
43 server
.hardware
= args
.hardware
44 server
.claimed_by
= args
.start_claimed
46 addrs
= netifaces
.ifaddresses(server
.interface
)
47 ip_address
= addrs
[netifaces
.AF_INET
][0]['addr']
48 server
.address
= '{}:{}'.format(ip_address
, server
.port
)
50 server
.chip
= linux_gadgetfs
.LinuxGadgetfs(server
.hardware
)
51 server
.SwitchGadget(server
.default
)
53 echo_gadget
.RegisterHandlers()
54 hid_echo_gadget
.RegisterHandlers()
55 keyboard_gadget
.RegisterHandlers()
56 mouse_gadget
.RegisterHandlers()
58 server
.http_server
.listen(server
.port
)
60 ioloop
.IOLoop
.instance().start()
64 if __name__
== '__main__':