mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added set_configuration method in libusb
This commit is contained in:
parent
8c566b877e
commit
94387a023f
@ -138,14 +138,6 @@ class Bus(Structure):
|
|||||||
return ans
|
return ans
|
||||||
return property(doc=doc, fget=fget)
|
return property(doc=doc, fget=fget)
|
||||||
|
|
||||||
class NTStatus(Structure):
|
|
||||||
_fields_ = [\
|
|
||||||
('code', c_uint, 16),
|
|
||||||
('facility', c_uint, 13),
|
|
||||||
('c', c_uint, 1),
|
|
||||||
('sev', c_uint, 2)
|
|
||||||
]
|
|
||||||
|
|
||||||
class DeviceHandle(Structure):
|
class DeviceHandle(Structure):
|
||||||
_fields_ = [\
|
_fields_ = [\
|
||||||
('fd', c_int), \
|
('fd', c_int), \
|
||||||
@ -161,14 +153,18 @@ class DeviceHandle(Structure):
|
|||||||
""" Close this DeviceHandle """
|
""" Close this DeviceHandle """
|
||||||
_libusb.usb_close(byref(self))
|
_libusb.usb_close(byref(self))
|
||||||
|
|
||||||
|
def set_configuration(self, num):
|
||||||
|
ret = _libusb.usb_set_configuration(byref(self), num)
|
||||||
|
if ret < 0:
|
||||||
|
raise Error('Failed to set device configuration to: ' + num)
|
||||||
|
|
||||||
def claim_interface(self, num):
|
def claim_interface(self, num):
|
||||||
"""
|
"""
|
||||||
Claim interface C{num} on device.
|
Claim interface C{num} on device.
|
||||||
Must be called before doing anything witht the device.
|
Must be called before doing anything witht the device.
|
||||||
"""
|
"""
|
||||||
ret = _libusb.usb_claim_interface(byref(self), num)
|
ret = _libusb.usb_claim_interface(byref(self), num)
|
||||||
if _iswindows:
|
|
||||||
return
|
|
||||||
if -ret == ENOMEM:
|
if -ret == ENOMEM:
|
||||||
raise Error("Insufficient memory to claim interface")
|
raise Error("Insufficient memory to claim interface")
|
||||||
elif -ret == EBUSY:
|
elif -ret == EBUSY:
|
||||||
@ -203,7 +199,7 @@ class DeviceHandle(Structure):
|
|||||||
rsize = _libusb.usb_control_msg(byref(self), rtype, request, \
|
rsize = _libusb.usb_control_msg(byref(self), rtype, request, \
|
||||||
value, index, byref(arr), \
|
value, index, byref(arr), \
|
||||||
size, timeout)
|
size, timeout)
|
||||||
if rsize < size:
|
if rsize < size:
|
||||||
raise Error('Could not read ' + str(size) + ' bytes on the '\
|
raise Error('Could not read ' + str(size) + ' bytes on the '\
|
||||||
'control bus. Read: ' + str(rsize) + ' bytes.')
|
'control bus. Read: ' + str(rsize) + ' bytes.')
|
||||||
return arr
|
return arr
|
||||||
@ -296,8 +292,8 @@ _libusb.usb_reset.restype = c_int
|
|||||||
_libusb.usb_control_msg.restype = c_int
|
_libusb.usb_control_msg.restype = c_int
|
||||||
_libusb.usb_bulk_read.restype = c_int
|
_libusb.usb_bulk_read.restype = c_int
|
||||||
_libusb.usb_bulk_write.restype = c_int
|
_libusb.usb_bulk_write.restype = c_int
|
||||||
if _iswindows:
|
_libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int]
|
||||||
_libusb.usb_claim_interface.restype = NTStatus
|
_libusb.usb_set_configuration.restype = c_int
|
||||||
_libusb.usb_init()
|
_libusb.usb_init()
|
||||||
|
|
||||||
def busses():
|
def busses():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user