IGN:Make detection of devices based on BCD optional

This commit is contained in:
Kovid Goyal 2009-01-08 10:08:26 -08:00
parent ed040cb7fe
commit cfb275598b
5 changed files with 28 additions and 11 deletions

View File

@ -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) :

View File

@ -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

View File

@ -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"]

View File

@ -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'

View File

@ -39,19 +39,34 @@ 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 self.test_bcd(bcdDevice, getattr(device, 'BCD', None))
return False