Add option to start service on a specific device identified by bus number and device address.
This commit is contained in:
parent
22d2027469
commit
04fa59ce1d
3 changed files with 33 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.mainloop.glib
|
import dbus.mainloop.glib
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
|
@ -150,15 +151,22 @@ class Device(dbus.service.Object):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser('Open fprintd DBus service')
|
parser = argparse.ArgumentParser('Open fprintd DBus service')
|
||||||
parser.add_argument('--debug', help='Enable tracing', action='store_true')
|
parser.add_argument('--debug', help='Enable tracing', action='store_true')
|
||||||
|
parser.add_argument('--devpath', help='USB device path: usb-<busnum>-<address>')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
usb.trace_enabled = True
|
||||||
|
tls.trace_enabled = True
|
||||||
|
|
||||||
init.open()
|
if args.devpath is None:
|
||||||
|
init.open()
|
||||||
|
else:
|
||||||
|
z = re.match('^usb-(\d+)-(\d+)$', args.devpath)
|
||||||
|
if not z:
|
||||||
|
parser.error('Option --devpath should look like this: usb-<busnum>-<address>')
|
||||||
|
|
||||||
usb.trace_enabled = True
|
init.open_devpath(*map(int, z.groups()))
|
||||||
tls.trace_enabled = True
|
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@ def close():
|
||||||
finally:
|
finally:
|
||||||
usb.close()
|
usb.close()
|
||||||
|
|
||||||
def open():
|
def open_common():
|
||||||
usb.open()
|
|
||||||
usb.send_init()
|
usb.send_init()
|
||||||
# We must register atexit only after we opened usb device,
|
# We must register atexit only after we opened usb device,
|
||||||
# so that our handler is called before pyusb's one and we can still talk to the device
|
# so that our handler is called before pyusb's one and we can still talk to the device
|
||||||
|
|
@ -29,5 +28,10 @@ def open():
|
||||||
|
|
||||||
sensor.open()
|
sensor.open()
|
||||||
|
|
||||||
|
def open():
|
||||||
|
usb.open()
|
||||||
|
open_common()
|
||||||
|
|
||||||
|
def open_devpath(busnum, address):
|
||||||
|
usb.open_devpath(busnum, address)
|
||||||
|
open_common()
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@ supported_devices=[
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def custom_match(d):
|
|
||||||
return (d.idVendor, d.idProduct) in supported_devices
|
|
||||||
|
|
||||||
class Usb():
|
class Usb():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.interrupt_cb = None
|
self.interrupt_cb = None
|
||||||
|
|
@ -29,11 +26,25 @@ class Usb():
|
||||||
if vendor is not None and product is not None:
|
if vendor is not None and product is not None:
|
||||||
dev = ucore.find(idVendor=vendor, idProduct=product)
|
dev = ucore.find(idVendor=vendor, idProduct=product)
|
||||||
else:
|
else:
|
||||||
dev = ucore.find(custom_match=custom_match)
|
def match(d):
|
||||||
|
return (d.idVendor, d.idProduct) in supported_devices
|
||||||
|
|
||||||
|
dev = ucore.find(custom_match=match)
|
||||||
|
|
||||||
|
self.open_dev(dev)
|
||||||
|
|
||||||
|
def open_devpath(self, busnum, address):
|
||||||
|
def match(d):
|
||||||
|
return d.bus == busnum and d.address == address
|
||||||
|
|
||||||
|
dev = ucore.find(custom_match=match)
|
||||||
|
|
||||||
self.open_dev(dev)
|
self.open_dev(dev)
|
||||||
|
|
||||||
def open_dev(self, dev):
|
def open_dev(self, dev):
|
||||||
|
if dev is None:
|
||||||
|
raise Exception('No matching devices found')
|
||||||
|
|
||||||
self.dev = dev
|
self.dev = dev
|
||||||
self.dev.default_timeout = 15000
|
self.dev.default_timeout = 15000
|
||||||
self.thread = Thread(target=lambda: self.int_thread())
|
self.thread = Thread(target=lambda: self.int_thread())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue