Move files from gousb/usb to gousb
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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")
|
||||
|
@@ -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)",
|
||||
|
Reference in New Issue
Block a user