mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added a set configuration call to device initialization as this is needed in windows and doesn't seem to matter in linux. Fixed BBeBook.
This commit is contained in:
parent
94387a023f
commit
d789b6d627
@ -233,6 +233,17 @@ class PRS500Device(Device):
|
|||||||
raise DeviceError()
|
raise DeviceError()
|
||||||
try:
|
try:
|
||||||
self.handle = self.device.open()
|
self.handle = self.device.open()
|
||||||
|
configs = self.device.configurations
|
||||||
|
cfg = configs[0]
|
||||||
|
for config in configs:
|
||||||
|
if config.MaxPower > cfg.MaxPower:
|
||||||
|
cfg = config
|
||||||
|
try:
|
||||||
|
self.handle.set_configuration(cfg)
|
||||||
|
except USBError:
|
||||||
|
for config in configs:
|
||||||
|
if config.Value != cfg.Value:
|
||||||
|
self.handle.set_configuration(config)
|
||||||
self.handle.claim_interface(self.INTERFACE_ID)
|
self.handle.claim_interface(self.INTERFACE_ID)
|
||||||
except USBError, err:
|
except USBError, err:
|
||||||
raise DeviceBusy(str(err))
|
raise DeviceBusy(str(err))
|
||||||
|
@ -97,7 +97,7 @@ class ConfigDescriptor(Structure):
|
|||||||
('DescriptorType', c_ubyte), \
|
('DescriptorType', c_ubyte), \
|
||||||
('TotalLength', c_ushort), \
|
('TotalLength', c_ushort), \
|
||||||
('NumInterfaces', c_ubyte), \
|
('NumInterfaces', c_ubyte), \
|
||||||
('ConfigurationValue', c_ubyte), \
|
('Value', c_ubyte), \
|
||||||
('Configuration', c_ubyte), \
|
('Configuration', c_ubyte), \
|
||||||
('Attributes', c_ubyte), \
|
('Attributes', c_ubyte), \
|
||||||
('MaxPower', c_ubyte), \
|
('MaxPower', c_ubyte), \
|
||||||
@ -106,6 +106,14 @@ class ConfigDescriptor(Structure):
|
|||||||
('extralen', c_int) \
|
('extralen', c_int) \
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
ans = ""
|
||||||
|
for field in self._fields_:
|
||||||
|
ans += field[0] + ": " + str(eval('self.'+field[0])) + '\n'
|
||||||
|
return ans.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -118,6 +126,17 @@ class Device(Structure):
|
|||||||
raise Error("Cannot open device")
|
raise Error("Cannot open device")
|
||||||
return handle.contents
|
return handle.contents
|
||||||
|
|
||||||
|
@apply
|
||||||
|
def configurations():
|
||||||
|
doc = """ List of device configurations. See L{ConfigDescriptor} """
|
||||||
|
def fget(self):
|
||||||
|
ans = []
|
||||||
|
ans.append(self.config_descriptor.contents)
|
||||||
|
for config in range(self.device_descriptor.NumConfigurations):
|
||||||
|
ans.append(self.config_descriptor[config])
|
||||||
|
return tuple(ans)
|
||||||
|
return property(doc=doc, fget=fget)
|
||||||
|
|
||||||
class Bus(Structure):
|
class Bus(Structure):
|
||||||
@apply
|
@apply
|
||||||
def device_list():
|
def device_list():
|
||||||
@ -153,10 +172,20 @@ class DeviceHandle(Structure):
|
|||||||
""" Close this DeviceHandle """
|
""" Close this DeviceHandle """
|
||||||
_libusb.usb_close(byref(self))
|
_libusb.usb_close(byref(self))
|
||||||
|
|
||||||
def set_configuration(self, num):
|
def set_configuration(self, config):
|
||||||
|
"""
|
||||||
|
Set device configuration. This has to be called on windows before
|
||||||
|
trying to claim an interface.
|
||||||
|
@param config: A L{ConfigDescriptor} or a integer (the ConfigurationValue)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
num = config.Value
|
||||||
|
except AttributeError:
|
||||||
|
num = config
|
||||||
ret = _libusb.usb_set_configuration(byref(self), num)
|
ret = _libusb.usb_set_configuration(byref(self), num)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
raise Error('Failed to set device configuration to: ' + num)
|
raise Error('Failed to set device configuration to: ' + str(num) + \
|
||||||
|
'. Error code: ' + str(ret))
|
||||||
|
|
||||||
def claim_interface(self, num):
|
def claim_interface(self, num):
|
||||||
"""
|
"""
|
||||||
@ -313,6 +342,7 @@ def busses():
|
|||||||
|
|
||||||
def get_device_by_id(idVendor, idProduct):
|
def get_device_by_id(idVendor, idProduct):
|
||||||
""" Return a L{Device} by vendor and prduct ids """
|
""" Return a L{Device} by vendor and prduct ids """
|
||||||
|
ans = []
|
||||||
buslist = busses()
|
buslist = busses()
|
||||||
for bus in buslist:
|
for bus in buslist:
|
||||||
devices = bus.device_list
|
devices = bus.device_list
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user