diff --git a/.travis.yml b/.travis.yml index 75784ca..a78f196 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ language: go +dist: trusty go: - 1.6 + - 1.7 + - 1.8 - tip script: go test -v -test.run='BCD|Parse' ./... diff --git a/AUTHORS b/AUTHORS index d32b768..6406cf0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ Pieter Joost van de Sande Ivan Krasin Jirawat I. Thordur Bjornsson +Vincent Serpoul \ No newline at end of file diff --git a/README.md b/README.md index afb94b8..fc65fa7 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ so that I can verify that it is on file before I can accept pull requests. [cla]: https://cla.developers.google.com/ -Installation on Linux -===================== +Installation +============ Dependencies ------------ @@ -54,42 +54,20 @@ There is also a `usbid` package that will not be installed by default by this co go get -v github.com/kylelemons/gousb/usb{,id} -Installation on Windows -======================= +Notes for installation on Windows +--------------------------------- -Dependencies ------------- -- Gcc (only tested on [Win-Builds](http://win-builds.org/), but any MSYS, CYGWIN, MINGW should be worked -- [libusb-1.0](http://sourceforge.net/projects/libusb/files/libusb-1.0/) +You'll need: -Build ------ +- Gcc - tested on [Win-Builds](http://win-builds.org/) and MSYS/MINGW +- pkg-config - see http://www.mingw.org/wiki/FAQ, "How do I get pkg-config installed?" +- [libusb-1.0](http://sourceforge.net/projects/libusb/files/libusb-1.0/). -- After downloaded, extract them to some directory; such as D:\lib\libusb-1.0.xx\ -- Remember two path which "libusb.h" file and "libusb-1.0.a" inside +Make sure the `libusb-1.0.pc` pkg-config file from libusb was installed +and that the result of the `pkg-config --cflags libusb-1.0` command shows the +correct include path for installed libusb. -*Note* For MinGW32, use **MinGW32/static/libusb-1.0.a** while MinGW64 use **MinGW64/static/libusb-1.0.a** for linker - -- Open `$(GOPATH)/src/github.com/kylelemons/gousb/usb/usb.go`. - -Then edit `#cgo` directive, such as - - // #cgo CFLAGS: -ID:/lib/libusbx-1.0.xx/include - // #cgo LDFLAGS: D:/lib/libusbx-1.0.xx/MinGW64/static/libusb-1.0.a - - -to your `libusb-1.0` installed path before the line: - - // #include - -This flag will tell the linker the exact path of static library. -Then install `gousb`: - -- Go to `$(GOPATH)/src/github.com/kylelemons/gousb/`. Run: - - $ go install ./... - - `lsusb` can run under `$GOBIN/lsusb` +After that you can continue with instructions for lsusb/gousb above. Documentation ============= diff --git a/usb/device.go b/usb/device.go index 6100a79..ae5f3b5 100644 --- a/usb/device.go +++ b/usb/device.go @@ -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 +}