diff options
Diffstat (limited to 'plugins/wedo_plugin/usb/legacy.py')
-rw-r--r-- | plugins/wedo_plugin/usb/legacy.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/plugins/wedo_plugin/usb/legacy.py b/plugins/wedo_plugin/usb/legacy.py index 0c9c52c..ebe9f4d 100644 --- a/plugins/wedo_plugin/usb/legacy.py +++ b/plugins/wedo_plugin/usb/legacy.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2011 Wander Lairson Costa +# Copyright (C) 2009-2013 Wander Lairson Costa # # The following terms apply to all files associated # with the software unless explicitly disclaimed in individual files. @@ -222,8 +222,10 @@ class DeviceHandle(object): Arguments: interface: interface number or an Interface object. """ - if_num = interface.interfaceNumber \ - if isinstance(interface, Interface) else interface + if isinstance(interface, Interface): + if_num = interface.interfaceNumber + else: + if_num = interface util.claim_interface(self.dev, if_num) self.__claimed_interface = if_num @@ -301,7 +303,11 @@ class Device(object): self.deviceClass = dev.bDeviceClass self.deviceSubClass = dev.bDeviceSubClass self.deviceProtocol = dev.bDeviceProtocol - self.deviceVersion = dev.bcdDevice + self.deviceVersion = str((dev.bcdDevice >> 12) & 0xf) + \ + str((dev.bcdDevice >> 8) & 0xf) + \ + '.' + \ + str((dev.bcdDevice >> 4) & 0xf) + \ + str(dev.bcdDevice & 0xf) self.devnum = None self.filename = '' self.iManufacturer = dev.iManufacturer @@ -310,7 +316,11 @@ class Device(object): self.idProduct = dev.idProduct self.idVendor = dev.idVendor self.maxPacketSize = dev.bMaxPacketSize0 - self.usbVersion = dev.bcdUSB + self.usbVersion = str((dev.bcdUSB >> 12) & 0xf) + \ + str((dev.bcdUSB >> 8) & 0xf) + \ + '.' + \ + str((dev.bcdUSB >> 4) & 0xf) + \ + str(dev.bcdUSB & 0xf) self.configurations = [Configuration(c) for c in dev] self.dev = dev @@ -323,12 +333,14 @@ class Device(object): class Bus(object): r"""Bus object.""" - def __init__(self): + def __init__(self, devices): self.dirname = '' - self.localtion = 0 - self.devices = [Device(d) for d in core.find(find_all=True)] + self.location = 0 + self.devices = [Device(d) for d in devices] def busses(): r"""Return a tuple with the usb busses.""" - return (Bus(),) + return (Bus(g) for k, g in _interop._groupby( + _interop._sorted(core.find(find_all=True), key=lambda d: d.bus), + lambda d: d.bus)) |