Move files from gousb/usb to gousb

This commit is contained in:
Sebastian Zagrodzki
2017-05-06 00:11:11 +02:00
parent acb9ee3242
commit 5200a36191
33 changed files with 79 additions and 79 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
// #include <libusb.h>
import "C"

View File

@@ -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.

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"reflect"

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -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

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import "testing"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"testing"

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -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{

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"errors"

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package usb
package gousb
import "testing"

View File

@@ -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))

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"fmt"

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"testing"

View File

@@ -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

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"errors"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import "io"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"bytes"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import (
"testing"

View File

@@ -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 {

View File

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package usb
package gousb
import "testing"

View File

@@ -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)

View File

@@ -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

View File

@@ -26,13 +26,13 @@ var LastUpdate = time.Unix(0, 1489154954940548227)
const usbIDListData = `#
# List of USB ID's
#
# Maintained by Stephen J. Gowdy <linux.usb.ids@gmail.com>
# Maintained by Stephen J. Gowdy <linux.gousb.ids@gmail.com>
# 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

View File

@@ -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")

View File

@@ -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)",