From 94878756d0b7d42dbed56230ace01f917c14b72a Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Wed, 15 Feb 2017 20:31:16 +0100 Subject: [PATCH 01/15] instructions for windows are simpler now that we use pkgconfig. --- README.md | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) 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 ============= From a7f2e81ddffe8991d215a00b1d019227d7d778e1 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Thu, 16 Feb 2017 23:41:52 +0800 Subject: [PATCH 02/15] detach before claim --- usb/device.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usb/device.go b/usb/device.go index 6100a79..b396a88 100644 --- a/usb/device.go +++ b/usb/device.go @@ -174,6 +174,11 @@ found: } } + // Detach the interface + if errno := C.libusb_detach_kernel_driver(d.handle, C.int(iface)); errno < 0 { + fmt.Errorf("usb: detach: %s", usbError(errno)) + } + // Claim the interface if errno := C.libusb_claim_interface(d.handle, C.int(iface)); errno < 0 { return nil, fmt.Errorf("usb: claim: %s", usbError(errno)) From c84750a9d7c3a8dd72e862e13719dcdda8d13332 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:05:34 +0800 Subject: [PATCH 03/15] remove systematic detach, add SetAutoDetach method --- usb/device.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/usb/device.go b/usb/device.go index b396a88..7d8bbb2 100644 --- a/usb/device.go +++ b/usb/device.go @@ -174,11 +174,6 @@ found: } } - // Detach the interface - if errno := C.libusb_detach_kernel_driver(d.handle, C.int(iface)); errno < 0 { - fmt.Errorf("usb: detach: %s", usbError(errno)) - } - // Claim the interface if errno := C.libusb_claim_interface(d.handle, C.int(iface)); errno < 0 { return nil, fmt.Errorf("usb: claim: %s", usbError(errno)) @@ -222,3 +217,21 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { return stringDescriptor, nil } + +// SetAutoDetach Enable/disable libusb's automatic kernel driver detachment. +// When this is enabled libusb will automatically detach the kernel driver +// on an interface when claiming the interface, and attach it when releasing the interface. +// Automatic kernel driver detachment is disabled on newly opened device handles by default. +func (d *Device) SetAutoDetach(autodetach int) error { + errno := C.libusb_set_auto_detach_kernel_driver( + d.handle, + C.int(autodetach), + ) + + // TODO LIBUSB_ERROR_NOT_SUPPORTED (-12) handling + // if any errors occur + if errno < 0 { + return fmt.Errorf("usb: setautodetach: %s", usbError(errno)) + } + return nil +} From 16dcc9999731c3dafa3227b78cb18cedb465d13e Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:19:33 +0800 Subject: [PATCH 04/15] add bool handling --- usb/device.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/usb/device.go b/usb/device.go index 7d8bbb2..b707e4e 100644 --- a/usb/device.go +++ b/usb/device.go @@ -222,7 +222,12 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { // When this is enabled libusb will automatically detach the kernel driver // on an interface when claiming the interface, and attach it when releasing the interface. // Automatic kernel driver detachment is disabled on newly opened device handles by default. -func (d *Device) SetAutoDetach(autodetach int) error { +func (d *Device) SetAutoDetach(autodetach bool) error { + autodetachInt := 0 + if autodetach { + autodetachInt = 1 + } + errno := C.libusb_set_auto_detach_kernel_driver( d.handle, C.int(autodetach), From b13a99c292eb30f4271e734a174512803d885dcf Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:24:57 +0800 Subject: [PATCH 05/15] improve comment --- usb/device.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usb/device.go b/usb/device.go index b707e4e..e588c85 100644 --- a/usb/device.go +++ b/usb/device.go @@ -219,8 +219,8 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { } // SetAutoDetach Enable/disable libusb's automatic kernel driver detachment. -// When this is enabled libusb will automatically detach the kernel driver -// on an interface when claiming the interface, and attach it when releasing the interface. +// 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 From a6b5026fe989c4763176e600ffeb72cdac5966e4 Mon Sep 17 00:00:00 2001 From: Kyle Lemons Date: Thu, 16 Feb 2017 09:33:10 -0800 Subject: [PATCH 06/15] Bump the Ubuntu and Go versions for Travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) 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' ./... From 56fd0d1199e17b7eabde11c4d41ab4b70c9f1d69 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:33:51 +0800 Subject: [PATCH 07/15] error handling and bool handling --- usb/device.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usb/device.go b/usb/device.go index e588c85..b5c3d3e 100644 --- a/usb/device.go +++ b/usb/device.go @@ -228,15 +228,15 @@ func (d *Device) SetAutoDetach(autodetach bool) error { autodetachInt = 1 } - errno := C.libusb_set_auto_detach_kernel_driver( + err := C.libusb_set_auto_detach_kernel_driver( d.handle, - C.int(autodetach), + C.int(autodetachInt), ) // TODO LIBUSB_ERROR_NOT_SUPPORTED (-12) handling // if any errors occur - if errno < 0 { - return fmt.Errorf("usb: setautodetach: %s", usbError(errno)) + if err != C.int(SUCCESS) { + return fmt.Errorf("usb: setautodetach: %s", usbError(err)) } return nil } From 7c2897852dee3f183912f2ea029ac2ed602e0ae7 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Thu, 16 Feb 2017 23:41:52 +0800 Subject: [PATCH 08/15] detach before claim --- usb/device.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usb/device.go b/usb/device.go index 6100a79..b396a88 100644 --- a/usb/device.go +++ b/usb/device.go @@ -174,6 +174,11 @@ found: } } + // Detach the interface + if errno := C.libusb_detach_kernel_driver(d.handle, C.int(iface)); errno < 0 { + fmt.Errorf("usb: detach: %s", usbError(errno)) + } + // Claim the interface if errno := C.libusb_claim_interface(d.handle, C.int(iface)); errno < 0 { return nil, fmt.Errorf("usb: claim: %s", usbError(errno)) From 6586e027a612e8cd1c03b7d3b4291a67a15c7420 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:05:34 +0800 Subject: [PATCH 09/15] remove systematic detach, add SetAutoDetach method --- usb/device.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/usb/device.go b/usb/device.go index b396a88..7d8bbb2 100644 --- a/usb/device.go +++ b/usb/device.go @@ -174,11 +174,6 @@ found: } } - // Detach the interface - if errno := C.libusb_detach_kernel_driver(d.handle, C.int(iface)); errno < 0 { - fmt.Errorf("usb: detach: %s", usbError(errno)) - } - // Claim the interface if errno := C.libusb_claim_interface(d.handle, C.int(iface)); errno < 0 { return nil, fmt.Errorf("usb: claim: %s", usbError(errno)) @@ -222,3 +217,21 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { return stringDescriptor, nil } + +// SetAutoDetach Enable/disable libusb's automatic kernel driver detachment. +// When this is enabled libusb will automatically detach the kernel driver +// on an interface when claiming the interface, and attach it when releasing the interface. +// Automatic kernel driver detachment is disabled on newly opened device handles by default. +func (d *Device) SetAutoDetach(autodetach int) error { + errno := C.libusb_set_auto_detach_kernel_driver( + d.handle, + C.int(autodetach), + ) + + // TODO LIBUSB_ERROR_NOT_SUPPORTED (-12) handling + // if any errors occur + if errno < 0 { + return fmt.Errorf("usb: setautodetach: %s", usbError(errno)) + } + return nil +} From 09dcccd0ddd0590aa7144b46c79f2438f9753e33 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:19:33 +0800 Subject: [PATCH 10/15] add bool handling --- usb/device.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/usb/device.go b/usb/device.go index 7d8bbb2..b707e4e 100644 --- a/usb/device.go +++ b/usb/device.go @@ -222,7 +222,12 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { // When this is enabled libusb will automatically detach the kernel driver // on an interface when claiming the interface, and attach it when releasing the interface. // Automatic kernel driver detachment is disabled on newly opened device handles by default. -func (d *Device) SetAutoDetach(autodetach int) error { +func (d *Device) SetAutoDetach(autodetach bool) error { + autodetachInt := 0 + if autodetach { + autodetachInt = 1 + } + errno := C.libusb_set_auto_detach_kernel_driver( d.handle, C.int(autodetach), From d8e3995f7ceea931b3c6cc4aee68bbcdcf9337bb Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:24:57 +0800 Subject: [PATCH 11/15] improve comment --- usb/device.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usb/device.go b/usb/device.go index b707e4e..e588c85 100644 --- a/usb/device.go +++ b/usb/device.go @@ -219,8 +219,8 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { } // SetAutoDetach Enable/disable libusb's automatic kernel driver detachment. -// When this is enabled libusb will automatically detach the kernel driver -// on an interface when claiming the interface, and attach it when releasing the interface. +// 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 From 0a1a8e43cd56fb9a779bc5f56fccf91a80be3e5c Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 01:33:51 +0800 Subject: [PATCH 12/15] error handling and bool handling --- usb/device.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usb/device.go b/usb/device.go index e588c85..b5c3d3e 100644 --- a/usb/device.go +++ b/usb/device.go @@ -228,15 +228,15 @@ func (d *Device) SetAutoDetach(autodetach bool) error { autodetachInt = 1 } - errno := C.libusb_set_auto_detach_kernel_driver( + err := C.libusb_set_auto_detach_kernel_driver( d.handle, - C.int(autodetach), + C.int(autodetachInt), ) // TODO LIBUSB_ERROR_NOT_SUPPORTED (-12) handling // if any errors occur - if errno < 0 { - return fmt.Errorf("usb: setautodetach: %s", usbError(errno)) + if err != C.int(SUCCESS) { + return fmt.Errorf("usb: setautodetach: %s", usbError(err)) } return nil } From a431f86bcbbd45ae8b46dac37aea678134212c71 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 02:28:24 +0800 Subject: [PATCH 13/15] comment grammar --- usb/device.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/device.go b/usb/device.go index b5c3d3e..22efa62 100644 --- a/usb/device.go +++ b/usb/device.go @@ -218,7 +218,7 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { return stringDescriptor, nil } -// SetAutoDetach Enable/disable libusb's automatic kernel driver detachment. +// 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. From 303eb08f985098669c716a7c9bc5525d41720943 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 02:48:05 +0800 Subject: [PATCH 14/15] comment nitpicking :) --- usb/device.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/device.go b/usb/device.go index 22efa62..ae5f3b5 100644 --- a/usb/device.go +++ b/usb/device.go @@ -218,7 +218,7 @@ func (d *Device) GetStringDescriptor(desc_index int) (string, error) { return stringDescriptor, nil } -// SetAutoDetach Enables/disables libusb's automatic kernel driver detachment. +// 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. From c95e06b5d4deea33232987db9af0ea402d3f0207 Mon Sep 17 00:00:00 2001 From: vincentserpoul Date: Fri, 17 Feb 2017 02:48:47 +0800 Subject: [PATCH 15/15] authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) 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