diff --git a/usb/descriptor.go b/usb/descriptor.go deleted file mode 100644 index 37fe471..0000000 --- a/usb/descriptor.go +++ /dev/null @@ -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) -} diff --git a/usb/device.go b/usb/device.go index 82889a3..3a4c7e8 100644 --- a/usb/device.go +++ b/usb/device.go @@ -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 { diff --git a/usb/interface.go b/usb/interface.go index 3757c1e..b926e84 100644 --- a/usb/interface.go +++ b/usb/interface.go @@ -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