diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index e2959cd49f..85d25d82a4 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -20,7 +20,9 @@ class Device(object): FORMATS = ["lrf", "rtf", "pdf", "txt"] VENDOR_ID = 0x0000 PRODUCT_ID = 0x0000 - BCD = 0x0000 + # BCD can be either None to not distinguish between devices based on BCD, or + # it can be a list of the BCD numbers of all devices supported by this driver. + BCD = None THUMBNAIL_HEIGHT = 68 # Height for thumbnails on device def __init__(self, key='-1', log_packets=False, report_progress=None) : diff --git a/src/calibre/devices/prs500/driver.py b/src/calibre/devices/prs500/driver.py index 177f57b15f..232d2c758c 100755 --- a/src/calibre/devices/prs500/driver.py +++ b/src/calibre/devices/prs500/driver.py @@ -85,7 +85,7 @@ class PRS500(Device): VENDOR_ID = 0x054c #: SONY Vendor Id PRODUCT_ID = 0x029b #: Product Id for the PRS-500 - BCD = 0x100 + BCD = [0x100] PRODUCT_NAME = 'PRS-500' VENDOR_NAME = 'SONY' INTERFACE_ID = 0 #: The interface we use to talk to the device diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index 0f60d7238b..61004ca005 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -29,7 +29,7 @@ class File(object): class PRS505(Device): VENDOR_ID = 0x054c #: SONY Vendor Id PRODUCT_ID = 0x031e #: Product Id for the PRS-505 - BCD = 0x229 #: Needed to disambiguate 505 and 700 on linux + BCD = [0x229] #: Needed to disambiguate 505 and 700 on linux PRODUCT_NAME = 'PRS-505' VENDOR_NAME = 'SONY' FORMATS = ['lrf', 'epub', "rtf", "pdf", "txt"] diff --git a/src/calibre/devices/prs700/driver.py b/src/calibre/devices/prs700/driver.py index 812ac0f911..5db60ef506 100644 --- a/src/calibre/devices/prs700/driver.py +++ b/src/calibre/devices/prs700/driver.py @@ -9,7 +9,7 @@ from calibre.devices.prs505.driver import PRS505 class PRS700(PRS505): - BCD = 0x31a + BCD = [0x31a] PRODUCT_NAME = 'PRS-700' OSX_NAME = 'Sony PRS-700' diff --git a/src/calibre/devices/scanner.py b/src/calibre/devices/scanner.py index 40573114a7..3487987d67 100644 --- a/src/calibre/devices/scanner.py +++ b/src/calibre/devices/scanner.py @@ -39,20 +39,35 @@ class DeviceScanner(object): '''Fetch list of connected USB devices from operating system''' self.devices = self.scanner() + def test_bcd_windows(self, device_id, bcd): + if bcd is None or len(bcd) == 0: + return True + for c in bcd: + # Bug in winutil.get_usb_devices converts a to : + rev = ('rev_%4.4x'%c).replace(':', 'a') + if rev in device_id: + return True + return False + + def test_bcd(self, bcdDevice, bcd): + if bcd is None or len(bcd) == 0: + return True + for c in bcd: + if c == bcdDevice: + return True + return False + def is_device_connected(self, device): if iswindows: for device_id in self.devices: vid, pid = 'vid_%4.4x'%device.VENDOR_ID, 'pid_%4.4x'%device.PRODUCT_ID - rev = ('rev_%4.4x'%device.BCD).replace('a', ':') # Bug in winutil.get_usb_devices converts a to : - if vid in device_id and pid in device_id and rev in device_id: - return True - return False + if vid in device_id and pid in device_id: + return self.test_bcd_windows(device_id, getattr(device, 'BCD', None)) else: for vendor, product, bcdDevice in self.devices: if device.VENDOR_ID == vendor and device.PRODUCT_ID == product: - if hasattr(device, 'BCD') and device.BCD == bcdDevice: - return True - return False + return self.test_bcd(bcdDevice, getattr(device, 'BCD', None)) + return False def main(args=sys.argv):