Skip to content

Commit

Permalink
libusb: Only find Sony devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ma1co committed Apr 2, 2016
1 parent cd09e60 commit 5c396e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pmca.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def installCommand(host=None, driverName=None, apkFile=None, outFile=None):

print 'Looking for Sony devices'
# Scan for devices
devices = [dev for dev in driver.listDevices() if dev.idVendor == SONY_ID_VENDOR]
devices = list(driver.listDevices(SONY_ID_VENDOR))

if not devices:
print 'No devices found. Ensure your camera is connected.'
Expand Down
9 changes: 5 additions & 4 deletions pmca/usb/driver/libusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
('status', Struct.INT8),
])

def listDevices():
def listDevices(vendor):
"""Lists all detected USB devices"""
for dev in usb.core.find(find_all=True):
interface = dev.get_active_configuration()[(0, 0)]
yield UsbDevice(dev, dev.idVendor, dev.idProduct, interface.bInterfaceClass)
for dev in usb.core.find(find_all=True, idVendor=vendor):
interface = next((interface for config in dev for interface in config), None)
if interface:
yield UsbDevice(dev, dev.idVendor, dev.idProduct, interface.bInterfaceClass)


class UsbDriver:
Expand Down
4 changes: 2 additions & 2 deletions pmca/usb/driver/windows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def parseDeviceId(id):
import wpd
from wpd import MtpDriver

def listDevices():
def listDevices(vendor=None):
"""Lists all mass storage and MTP devices"""
return itertools.chain(msc.listDevices(), wpd.listDevices())
return (dev for dev in itertools.chain(msc.listDevices(), wpd.listDevices()) if dev.idVendor == vendor)

0 comments on commit 5c396e5

Please sign in to comment.