Merge pull request #32 from vincentserpoul/master

detach before claim
This commit is contained in:
zagrodzki
2017-02-17 09:21:31 +01:00
committed by GitHub
2 changed files with 24 additions and 0 deletions

View File

@@ -10,3 +10,4 @@ Pieter Joost van de Sande <pj@born2code.net>
Ivan Krasin <imkrasin@gmail.com>
Jirawat I. <nodtem66@gmail.com>
Thordur Bjornsson <thorduri@secnorth.net>
Vincent Serpoul <vincent@serpoul.com>

View File

@@ -217,3 +217,26 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) {
return stringDescriptor, nil
}
// SetAutoDetach enables/disables libusb's automatic kernel driver detachment.
// When autodetach is enabled libusb will automatically detach the kernel driver
// on the interface and reattach it when releasing the interface.
// Automatic kernel driver detachment is disabled on newly opened device handles by default.
func (d *Device) SetAutoDetach(autodetach bool) error {
autodetachInt := 0
if autodetach {
autodetachInt = 1
}
err := C.libusb_set_auto_detach_kernel_driver(
d.handle,
C.int(autodetachInt),
)
// TODO LIBUSB_ERROR_NOT_SUPPORTED (-12) handling
// if any errors occur
if err != C.int(SUCCESS) {
return fmt.Errorf("usb: setautodetach: %s", usbError(err))
}
return nil
}