move descriptor to the device, like config and interface.
Clear separation between descriptor stringers and value stringers for the device and interface.
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
// Copyright 2016 the gousb Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package usb
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Descriptor is a representation of a USB device descriptor.
|
||||
type Descriptor struct {
|
||||
// Bus information
|
||||
Bus uint8 // The bus on which the device was detected
|
||||
Address uint8 // The address of the device on the bus
|
||||
|
||||
// Version information
|
||||
Spec BCD // USB Specification Release Number
|
||||
Device BCD // The device version
|
||||
|
||||
// Product information
|
||||
Vendor ID // The Vendor identifer
|
||||
Product ID // The Product identifier
|
||||
|
||||
// Protocol information
|
||||
Class Class // The class of this device
|
||||
SubClass Class // The sub-class (within the class) of this device
|
||||
Protocol Protocol // The protocol (within the sub-class) of this device
|
||||
|
||||
// Configuration information
|
||||
Configs []ConfigInfo
|
||||
}
|
||||
|
||||
// String represents a human readable representation of the device in the descriptor.
|
||||
func (d *Descriptor) String() string {
|
||||
return fmt.Sprintf("vid=%s,pid=%s,bus=%d,addr=%d", d.Vendor, d.Product, d.Bus, d.Address)
|
||||
}
|
@@ -20,6 +20,38 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Descriptor is a representation of a USB device descriptor.
|
||||
type Descriptor struct {
|
||||
// Bus information
|
||||
Bus uint8 // The bus on which the device was detected
|
||||
Address uint8 // The address of the device on the bus
|
||||
|
||||
// Version information
|
||||
Spec BCD // USB Specification Release Number
|
||||
Device BCD // The device version
|
||||
|
||||
// Product information
|
||||
Vendor ID // The Vendor identifer
|
||||
Product ID // The Product identifier
|
||||
|
||||
// Protocol information
|
||||
Class Class // The class of this device
|
||||
SubClass Class // The sub-class (within the class) of this device
|
||||
Protocol Protocol // The protocol (within the sub-class) of this device
|
||||
|
||||
// Configuration information
|
||||
Configs []ConfigInfo
|
||||
}
|
||||
|
||||
// String returns a human-readable version of the device descriptor.
|
||||
func (d *Descriptor) String() string {
|
||||
var cfgs []int
|
||||
for _, c := range d.Configs {
|
||||
cfgs = append(cfgs, c.Config)
|
||||
}
|
||||
return fmt.Sprintf("%d:%d: %s:%s (available configs: %v)", d.Bus, d.Address, d.Vendor, d.Product, cfgs)
|
||||
}
|
||||
|
||||
// Device represents an opened USB device.
|
||||
type Device struct {
|
||||
handle *libusbDevHandle
|
||||
@@ -32,6 +64,11 @@ type Device struct {
|
||||
claimed *Config
|
||||
}
|
||||
|
||||
// String represents a human readable representation of the device.
|
||||
func (d *Device) String() string {
|
||||
return fmt.Sprintf("vid=%s,pid=%s,bus=%d,addr=%d", d.Vendor, d.Product, d.Bus, d.Address)
|
||||
}
|
||||
|
||||
// Reset performs a USB port reset to reinitialize a device.
|
||||
func (d *Device) Reset() error {
|
||||
if d.handle == nil {
|
||||
|
@@ -29,10 +29,10 @@ type InterfaceInfo struct {
|
||||
AltSettings []InterfaceSetting
|
||||
}
|
||||
|
||||
// String returns a human-readable descripton of the interface and it's
|
||||
// alternate settings.
|
||||
// String returns a human-readable descripton of the interface descriptor and
|
||||
// it's alternate settings.
|
||||
func (i InterfaceInfo) String() string {
|
||||
return fmt.Sprintf("if=%d", i.Number)
|
||||
return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings))
|
||||
}
|
||||
|
||||
// InterfaceSetting contains information about a USB interface with a particular
|
||||
|
Reference in New Issue
Block a user