diff --git a/.travis.yml b/.travis.yml index 2a80889..9b82ddf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,4 @@ script: - |- echo 'mode: count' > coverage.merged && go list ./... | xargs -n1 -I{} sh -c ': > coverage.tmp; go test -v -covermode=count -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.merged' && rm coverage.tmp - |- - $HOME/gopath/bin/goveralls -coverprofile=coverage.merged -service=travis-ci -ignore usb/libusb.go,usb/error.go || true + $HOME/gopath/bin/goveralls -coverprofile=coverage.merged -service=travis-ci -ignore libusb.go,error.go || true diff --git a/README.md b/README.md index 9c18375..e0dd8a0 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,11 @@ If you installed the lsusb example, both libraries below are already installed. Installing the primary gousb package is really easy: - go get -v github.com/google/gousb/usb + go get -v github.com/google/gousb -There is also a `usbid` package that will not be installed by default by this command, but which provides useful information including the human-readable vendor and product codes for detected hardware. It's not installed by default and not linked into the `usb` package by default because it adds ~400kb to the resulting binary. If you want both, they can be installed thus: +There is also a `usbid` package that will not be installed by default by this command, but which provides useful information including the human-readable vendor and product codes for detected hardware. It's not installed by default and not linked into the `gousb` package by default because it adds ~400kb to the resulting binary. If you want both, they can be installed thus: - go get -v github.com/google/gousb/usb{,id} + go get -v github.com/google/gousb{,/usbid} Notes for installation on Windows --------------------------------- @@ -78,5 +78,5 @@ Documentation ============= The documentation can be viewed via local godoc or via the excellent [godoc.org](http://godoc.org/): -- [usb](http://godoc.org/github.com/google/gousb/usb) +- [usb](http://godoc.org/github.com/google/gousb) - [usbid](http://godoc.org/pkg/github.com/google/gousb/usbid) diff --git a/usb/config.go b/config.go similarity index 99% rename from usb/config.go rename to config.go index c781772..35d9a04 100644 --- a/usb/config.go +++ b/config.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/constants.go b/constants.go similarity index 99% rename from usb/constants.go rename to constants.go index 23a7792..7b16213 100644 --- a/usb/constants.go +++ b/constants.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb // #include import "C" diff --git a/usb/debug.go b/debug.go similarity index 98% rename from usb/debug.go rename to debug.go index d3d21ee..1716713 100644 --- a/usb/debug.go +++ b/debug.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb // To enable internal debugging, set the GOUSB_DEBUG environment variable. diff --git a/usb/device.go b/device.go similarity index 99% rename from usb/device.go rename to device.go index 9daf14a..203371c 100644 --- a/usb/device.go +++ b/device.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/device_test.go b/device_test.go similarity index 99% rename from usb/device_test.go rename to device_test.go index 2d8e390..a157dfd 100644 --- a/usb/device_test.go +++ b/device_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "reflect" diff --git a/usb/endpoint.go b/endpoint.go similarity index 99% rename from usb/endpoint.go rename to endpoint.go index 05aa5f3..67f32f6 100644 --- a/usb/endpoint.go +++ b/endpoint.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/endpoint_stream.go b/endpoint_stream.go similarity index 99% rename from usb/endpoint_stream.go rename to endpoint_stream.go index 93be2a5..7b93a24 100644 --- a/usb/endpoint_stream.go +++ b/endpoint_stream.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb func (e *endpoint) newStream(size, count int, submit bool) (*stream, error) { var ts []transferIntf diff --git a/usb/endpoint_stream_test.go b/endpoint_stream_test.go similarity index 99% rename from usb/endpoint_stream_test.go rename to endpoint_stream_test.go index ba9aee1..acf7aeb 100644 --- a/usb/endpoint_stream_test.go +++ b/endpoint_stream_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import "testing" diff --git a/usb/endpoint_test.go b/endpoint_test.go similarity index 99% rename from usb/endpoint_test.go rename to endpoint_test.go index 8b42244..26f9255 100644 --- a/usb/endpoint_test.go +++ b/endpoint_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "testing" diff --git a/usb/error.go b/error.go similarity index 99% rename from usb/error.go rename to error.go index f5577d3..9331673 100644 --- a/usb/error.go +++ b/error.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/fakelibusb_devices.go b/fakelibusb_devices.go similarity index 99% rename from usb/fakelibusb_devices.go rename to fakelibusb_devices.go index c09bb2b..4302716 100644 --- a/usb/fakelibusb_devices.go +++ b/fakelibusb_devices.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb // fake devices connected through the fakeLibusb stack. var fakeDevices = []*Descriptor{ diff --git a/usb/fakelibusb_test.go b/fakelibusb_test.go similarity index 99% rename from usb/fakelibusb_test.go rename to fakelibusb_test.go index 7d7d1bb..4aaddea 100644 --- a/usb/fakelibusb_test.go +++ b/fakelibusb_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "errors" diff --git a/usb/interface.go b/interface.go similarity index 99% rename from usb/interface.go rename to interface.go index a4643fc..11b4ec2 100644 --- a/usb/interface.go +++ b/interface.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/libusb.go b/libusb.go similarity index 99% rename from usb/libusb.go rename to libusb.go index 9f73873..5c4b52a 100644 --- a/usb/libusb.go +++ b/libusb.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/libusb_cgo_benchmark_test.go b/libusb_cgo_benchmark_test.go similarity index 98% rename from usb/libusb_cgo_benchmark_test.go rename to libusb_cgo_benchmark_test.go index c40e7b8..816de59 100644 --- a/usb/libusb_cgo_benchmark_test.go +++ b/libusb_cgo_benchmark_test.go @@ -1,4 +1,4 @@ -package usb +package gousb import "testing" diff --git a/lsusb/main.go b/lsusb/main.go index 06e9e92..cbfd14e 100644 --- a/lsusb/main.go +++ b/lsusb/main.go @@ -21,7 +21,7 @@ import ( "fmt" "log" - "github.com/google/gousb/usb" + "github.com/google/gousb" "github.com/google/gousb/usbid" ) @@ -33,14 +33,14 @@ func main() { flag.Parse() // Only one context should be needed for an application. It should always be closed. - ctx := usb.NewContext() + ctx := gousb.NewContext() defer ctx.Close() // Debugging can be turned on; this shows some of the inner workings of the libusb package. ctx.Debug(*debug) // ListDevices is used to find the devices to open. - devs, err := ctx.ListDevices(func(desc *usb.Descriptor) bool { + devs, err := ctx.ListDevices(func(desc *gousb.Descriptor) bool { // The usbid package can be used to print out human readable information. fmt.Printf("%03d.%03d %s:%s %s\n", desc.Bus, desc.Address, desc.Vendor, desc.Product, usbid.Describe(desc)) fmt.Printf(" Protocol: %s\n", usbid.Classify(desc)) diff --git a/usb/misc.go b/misc.go similarity index 99% rename from usb/misc.go rename to misc.go index f3f80bc..72cf997 100644 --- a/usb/misc.go +++ b/misc.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "fmt" diff --git a/usb/misc_test.go b/misc_test.go similarity index 98% rename from usb/misc_test.go rename to misc_test.go index 95b5c6e..a85d176 100644 --- a/usb/misc_test.go +++ b/misc_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "testing" diff --git a/rawread/main.go b/rawread/main.go index 6a9cd22..8e67e1d 100644 --- a/rawread/main.go +++ b/rawread/main.go @@ -25,7 +25,7 @@ import ( "strconv" "strings" - "github.com/google/gousb/usb" + "github.com/google/gousb" ) var ( @@ -41,7 +41,7 @@ var ( num = flag.Int("read_num", 0, "Number of read transactions to perform. 0 means infinite.") ) -func parseVIDPID(vidPid string) (usb.ID, usb.ID, error) { +func parseVIDPID(vidPid string) (gousb.ID, gousb.ID, error) { s := strings.Split(vidPid, ":") if len(s) != 2 { return 0, 0, fmt.Errorf("want VID:PID, two 32-bit hex numbers separated by colon, e.g. 1d6b:0002") @@ -54,7 +54,7 @@ func parseVIDPID(vidPid string) (usb.ID, usb.ID, error) { if err != nil { return 0, 0, fmt.Errorf("PID must be a hexadecimal 32-bit number, e.g. 1d6b") } - return usb.ID(vid), usb.ID(pid), nil + return gousb.ID(vid), gousb.ID(pid), nil } func parseBusAddr(busAddr string) (int, int, error) { @@ -77,13 +77,13 @@ func main() { flag.Parse() // Only one context should be needed for an application. It should always be closed. - ctx := usb.NewContext() + ctx := gousb.NewContext() defer ctx.Close() ctx.Debug(*debug) var devName string - var vid, pid usb.ID + var vid, pid gousb.ID var bus, addr int switch { case *vidPID == "" && *busAddr == "": @@ -108,7 +108,7 @@ func main() { log.Printf("Scanning for device %q...", devName) // ListDevices is used to find the devices to open. - devs, err := ctx.ListDevices(func(desc *usb.Descriptor) bool { + devs, err := ctx.ListDevices(func(desc *gousb.Descriptor) bool { switch { case vid == desc.Vendor && pid == desc.Product: return true diff --git a/usb/transfer.c b/transfer.c similarity index 100% rename from usb/transfer.c rename to transfer.c diff --git a/usb/transfer.go b/transfer.go similarity index 99% rename from usb/transfer.go rename to transfer.go index be9286c..50d4cf8 100644 --- a/usb/transfer.go +++ b/transfer.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "errors" diff --git a/usb/transfer_stream.go b/transfer_stream.go similarity index 99% rename from usb/transfer_stream.go rename to transfer_stream.go index 3db686a..b467470 100644 --- a/usb/transfer_stream.go +++ b/transfer_stream.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import "io" diff --git a/usb/transfer_stream_test.go b/transfer_stream_test.go similarity index 99% rename from usb/transfer_stream_test.go rename to transfer_stream_test.go index b98647d..1c747aa 100644 --- a/usb/transfer_stream_test.go +++ b/transfer_stream_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "bytes" diff --git a/usb/transfer_test.go b/transfer_test.go similarity index 99% rename from usb/transfer_test.go rename to transfer_test.go index dd653f1..7429a03 100644 --- a/usb/transfer_test.go +++ b/transfer_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import ( "testing" diff --git a/usb/usb.go b/usb.go similarity index 99% rename from usb/usb.go rename to usb.go index da3f477..8c8677c 100644 --- a/usb/usb.go +++ b/usb.go @@ -14,7 +14,7 @@ // limitations under the License. // Package usb provides a wrapper around libusb-1.0. -package usb +package gousb // Context is the libusb context instance. type Context struct { diff --git a/usb/usb_test.go b/usb_test.go similarity index 99% rename from usb/usb_test.go rename to usb_test.go index 9631679..5d57303 100644 --- a/usb/usb_test.go +++ b/usb_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package usb +package gousb import "testing" diff --git a/usbid/describe.go b/usbid/describe.go index 644d7a4..e9e97c8 100644 --- a/usbid/describe.go +++ b/usbid/describe.go @@ -27,17 +27,17 @@ package usbid import ( "fmt" - "github.com/google/gousb/usb" + "github.com/google/gousb" ) // Describe returns a human readable string describing the vendor and product // of the given device. // // The given val must be one of the following: -// - *usb.Descriptor "Product (Vendor)" +// - *gousb.Descriptor "Product (Vendor)" func Describe(val interface{}) string { switch val := val.(type) { - case *usb.Descriptor: + case *gousb.Descriptor: if v, ok := Vendors[val.Vendor]; ok { if d, ok := v.Product[val.Product]; ok { return fmt.Sprintf("%s (%s)", d, v) @@ -53,17 +53,17 @@ func Describe(val interface{}) string { // and protocol associated with a device or interface. // // The given val must be one of the following: -// - *usb.Descriptor "Class (SubClass) Protocol" -// - usb.InterfaceSetup "IfClass (IfSubClass) IfProtocol" +// - *gousb.Descriptor "Class (SubClass) Protocol" +// - gousb.InterfaceSetup "IfClass (IfSubClass) IfProtocol" func Classify(val interface{}) string { var ( - class, sub usb.Class - proto usb.Protocol + class, sub gousb.Class + proto gousb.Protocol ) switch val := val.(type) { - case *usb.Descriptor: + case *gousb.Descriptor: class, sub, proto = val.Class, val.SubClass, val.Protocol - case usb.InterfaceSetting: + case gousb.InterfaceSetting: class, sub, proto = val.Class, val.SubClass, val.Protocol default: return fmt.Sprintf("Unknown (%T)", val) diff --git a/usbid/load.go b/usbid/load.go index 7cf4707..ae4d359 100644 --- a/usbid/load.go +++ b/usbid/load.go @@ -21,20 +21,20 @@ import ( "strings" "time" - "github.com/google/gousb/usb" + "github.com/google/gousb" ) const ( // LinuxUsbDotOrg is one source of files in the format used by this package. - LinuxUsbDotOrg = "http://www.linux-usb.org/usb.ids" + LinuxUsbDotOrg = "http://www.linux-gousb.org/usb.ids" ) var ( // Vendors stores the vendor and product ID mappings. - Vendors map[usb.ID]*Vendor + Vendors map[gousb.ID]*Vendor // Classes stores the class, subclass and protocol mappings. - Classes map[usb.Class]*Class + Classes map[gousb.Class]*Class ) // LoadFromURL replaces the built-in vendor and class mappings with ones loaded diff --git a/usbid/load_data.go b/usbid/load_data.go index f783a53..3ff6cfe 100644 --- a/usbid/load_data.go +++ b/usbid/load_data.go @@ -26,13 +26,13 @@ var LastUpdate = time.Unix(0, 1489154954940548227) const usbIDListData = `# # List of USB ID's # -# Maintained by Stephen J. Gowdy +# Maintained by Stephen J. Gowdy # If you have any new entries, please submit them via -# http://www.linux-usb.org/usb-ids.html +# http://www.linux-gousb.org/usb-ids.html # or send entries as patches (diff -u old new) in the # body of your email (a bot will attempt to deal with it). # The latest version can be obtained from -# http://www.linux-usb.org/usb.ids +# http://www.linux-gousb.org/usb.ids # # Version: 2017.02.12 # Date: 2017-02-12 20:34:05 diff --git a/usbid/parse.go b/usbid/parse.go index 4e17030..5f2f6f4 100644 --- a/usbid/parse.go +++ b/usbid/parse.go @@ -22,14 +22,14 @@ import ( "strconv" "strings" - "github.com/google/gousb/usb" + "github.com/google/gousb" ) // A Vendor contains the name of the vendor and mappings corresponding to all // known products by their ID. type Vendor struct { Name string - Product map[usb.ID]*Product + Product map[gousb.ID]*Product } // String returns the name of the vendor. @@ -41,7 +41,7 @@ func (v Vendor) String() string { // the names of any interfaces that were specified. type Product struct { Name string - Interface map[usb.ID]string + Interface map[gousb.ID]string } // String returns the name of the product. @@ -52,7 +52,7 @@ func (p Product) String() string { // A Class contains the name of the class and mappings for each subclass. type Class struct { Name string - SubClass map[usb.Class]*SubClass + SubClass map[gousb.Class]*SubClass } // String returns the name of the class. @@ -63,7 +63,7 @@ func (c Class) String() string { // A SubClass contains the name of the subclass and any associated protocols. type SubClass struct { Name string - Protocol map[usb.Protocol]string + Protocol map[gousb.Protocol]string } // String returns the name of the SubClass. @@ -75,9 +75,9 @@ func (s SubClass) String() string { // should not be necessary, as a set of mappings is already embedded in the library. // If a new or specialized file is obtained, this can be used to retrieve the mappings, // which can be stored in the global Vendors and Classes map. -func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { - vendors := make(map[usb.ID]*Vendor, 2800) - classes := make(map[usb.Class]*Class) // TODO(kevlar): count +func ParseIDs(r io.Reader) (map[gousb.ID]*Vendor, map[gousb.Class]*Class, error) { + vendors := make(map[gousb.ID]*Vendor, 2800) + classes := make(map[gousb.Class]*Class) // TODO(kevlar): count split := func(s string) (kind string, level int, id uint64, name string, err error) { pieces := strings.SplitN(s, " ", 2) @@ -116,7 +116,7 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { var device *Product parseVendor := func(level int, raw uint64, name string) error { - id := usb.ID(raw) + id := gousb.ID(raw) switch level { case 0: @@ -134,7 +134,7 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { Name: name, } if vendor.Product == nil { - vendor.Product = make(map[usb.ID]*Product) + vendor.Product = make(map[gousb.ID]*Product) } vendor.Product[id] = device @@ -144,7 +144,7 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { } if device.Interface == nil { - device.Interface = make(map[usb.ID]string) + device.Interface = make(map[gousb.ID]string) } device.Interface[id] = name @@ -165,7 +165,7 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { class = &Class{ Name: name, } - classes[usb.Class(id)] = class + classes[gousb.Class(id)] = class case 1: if class == nil { @@ -176,9 +176,9 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { Name: name, } if class.SubClass == nil { - class.SubClass = make(map[usb.Class]*SubClass) + class.SubClass = make(map[gousb.Class]*SubClass) } - class.SubClass[usb.Class(id)] = subclass + class.SubClass[gousb.Class(id)] = subclass case 2: if subclass == nil { @@ -186,9 +186,9 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { } if subclass.Protocol == nil { - subclass.Protocol = make(map[usb.Protocol]string) + subclass.Protocol = make(map[gousb.Protocol]string) } - subclass.Protocol[usb.Protocol(id)] = name + subclass.Protocol[gousb.Protocol(id)] = name default: return fmt.Errorf("too many levels of nesting for class") diff --git a/usbid/testdata_test.go b/usbid/testdata_test.go index 80129e6..c9e0165 100644 --- a/usbid/testdata_test.go +++ b/usbid/testdata_test.go @@ -14,45 +14,45 @@ package usbid -import "github.com/google/gousb/usb" +import "github.com/google/gousb" const testDBPath = "testdata/testdb.txt" var ( - testDBVendors = map[usb.ID]*Vendor{ + testDBVendors = map[gousb.ID]*Vendor{ 0xabcd: { Name: "Vendor One", - Product: map[usb.ID]*Product{ + Product: map[gousb.ID]*Product{ 0x0123: {Name: "Product One"}, 0x0124: {Name: "Product Two"}, }, }, 0xefef: { Name: "Vendor Two", - Product: map[usb.ID]*Product{ + Product: map[gousb.ID]*Product{ 0x0aba: { Name: "Product", - Interface: map[usb.ID]string{ + Interface: map[gousb.ID]string{ 0x12: "Interface One", 0x24: "Interface Two", }, }, 0x0abb: { Name: "Product", - Interface: map[usb.ID]string{ + Interface: map[gousb.ID]string{ 0x12: "Interface", }, }, }, }, } - testDBClasses = map[usb.Class]*Class{ + testDBClasses = map[gousb.Class]*Class{ 0x00: { Name: "(Defined at Interface level)", }, 0x01: { Name: "Audio", - SubClass: map[usb.Class]*SubClass{ + SubClass: map[gousb.Class]*SubClass{ 0x01: {Name: "Control Device"}, 0x02: {Name: "Streaming"}, 0x03: {Name: "MIDI Streaming"}, @@ -60,11 +60,11 @@ var ( }, 0x02: { Name: "Communications", - SubClass: map[usb.Class]*SubClass{ + SubClass: map[gousb.Class]*SubClass{ 0x01: {Name: "Direct Line"}, 0x02: { Name: "Abstract (modem)", - Protocol: map[usb.Protocol]string{ + Protocol: map[gousb.Protocol]string{ 0x00: "None", 0x01: "AT-commands (v.25ter)", 0x02: "AT-commands (PCCA101)",