more comment updates, rename "intf" parameter of Interface to "num"

This commit is contained in:
Sebastian Zagrodzki
2017-06-13 10:48:28 +02:00
parent e40669b614
commit e1fd376a2e
4 changed files with 20 additions and 20 deletions

View File

@@ -83,37 +83,37 @@ func (c *Config) String() string {
} }
// Interface claims and returns an interface on a USB device. // Interface claims and returns an interface on a USB device.
// inft specifies the number of an interface to claim, and alt specifies the // num specifies the number of an interface to claim, and alt specifies the
// alternate setting number for that interface. // alternate setting number for that interface.
func (c *Config) Interface(intf, alt int) (*Interface, error) { func (c *Config) Interface(num, alt int) (*Interface, error) {
if c.dev == nil { if c.dev == nil {
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c) return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", num, alt, c)
} }
if intf < 0 || intf >= len(c.Desc.Interfaces) { if num < 0 || intNum >= len(c.Desc.Interfaces) {
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Desc.Interfaces)-1) return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", num, c, len(c.Desc.Interfaces)-1)
} }
ifInfo := c.Desc.Interfaces[intf] ifInfo := c.Desc.Interfaces[num]
if alt < 0 || alt >= len(ifInfo.AltSettings) { if alt < 0 || alt >= len(ifInfo.AltSettings) {
return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1) return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1)
} }
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
if c.claimed[intf] { if c.claimed[num] {
return nil, fmt.Errorf("interface %d on %s is already claimed", intf, c) return nil, fmt.Errorf("interface %d on %s is already claimed", num, c)
} }
// Claim the interface // Claim the interface
if err := libusb.claim(c.dev.handle, uint8(intf)); err != nil { if err := libusb.claim(c.dev.handle, uint8(num)); err != nil {
return nil, fmt.Errorf("failed to claim interface %d on %s: %v", intf, c, err) return nil, fmt.Errorf("failed to claim interface %d on %s: %v", num, c, err)
} }
if err := libusb.setAlt(c.dev.handle, uint8(intf), uint8(alt)); err != nil { if err := libusb.setAlt(c.dev.handle, uint8(num), uint8(alt)); err != nil {
libusb.release(c.dev.handle, uint8(intf)) libusb.release(c.dev.handle, uint8(num))
return nil, fmt.Errorf("failed to set alternate config %d on interface %d of %s: %v", alt, intf, c, err) return nil, fmt.Errorf("failed to set alternate config %d on interface %d of %s: %v", alt, num, c, err)
} }
c.claimed[intf] = true c.claimed[num] = true
return &Interface{ return &Interface{
Setting: ifInfo.AltSettings[alt], Setting: ifInfo.AltSettings[alt],
config: c, config: c,

View File

@@ -19,7 +19,7 @@ package gousb
import "C" import "C"
import "strconv" import "strconv"
// Class represents a USB-IF class or subclass code. // Class represents a USB-IF (Implementers Forum) class or subclass code.
type Class uint8 type Class uint8
// Standard classes defined by USB spec. // Standard classes defined by USB spec.

View File

@@ -31,7 +31,7 @@ type InterfaceDesc struct {
} }
// String returns a human-readable descripton of the interface descriptor and // String returns a human-readable descripton of the interface descriptor and
// it's alternate settings. // its alternate settings.
func (i InterfaceDesc) String() string { func (i InterfaceDesc) String() string {
return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings)) return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings))
} }
@@ -43,9 +43,9 @@ type InterfaceSetting struct {
Number int Number int
// Alternate is the number of this alternate setting. // Alternate is the number of this alternate setting.
Alternate int Alternate int
// Class is the USB-IF class code, as defined by the USB spec. // Class is the USB-IF (Implementers Forum) class code, as defined by the USB spec.
Class Class Class Class
// SubClass is the USB-IF subclass code, as defined by the USB spec. // SubClass is the USB-IF (Implementers Forum) subclass code, as defined by the USB spec.
SubClass Class SubClass Class
// Protocol is USB protocol code, as defined by the USB spe.c // Protocol is USB protocol code, as defined by the USB spe.c
Protocol Protocol Protocol Protocol

View File

@@ -19,8 +19,8 @@ import (
"fmt" "fmt"
) )
// BCD is a binary-coded decimal version number, with first 8 bits representing // BCD is a binary-coded decimal version number. Its first 8 bits represent
// the major version number, an latter 8 bits the minor version number. // the major version number, its last 8 bits represent the minor version number.
// Major and minor are composed of 4+4 bits, where each 4 bits represents // Major and minor are composed of 4+4 bits, where each 4 bits represents
// a decimal digit. // a decimal digit.
// Example: BCD(0x1234) means major 12 (decimal) and minor 34 (decimal). // Example: BCD(0x1234) means major 12 (decimal) and minor 34 (decimal).