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.
// 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.
func (c *Config) Interface(intf, alt int) (*Interface, error) {
func (c *Config) Interface(num, alt int) (*Interface, error) {
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) {
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Desc.Interfaces)-1)
if num < 0 || intNum >= len(c.Desc.Interfaces) {
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) {
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()
defer c.mu.Unlock()
if c.claimed[intf] {
return nil, fmt.Errorf("interface %d on %s is already claimed", intf, c)
if c.claimed[num] {
return nil, fmt.Errorf("interface %d on %s is already claimed", num, c)
}
// Claim the interface
if err := libusb.claim(c.dev.handle, uint8(intf)); err != nil {
return nil, fmt.Errorf("failed to claim interface %d on %s: %v", intf, c, err)
if err := libusb.claim(c.dev.handle, uint8(num)); err != nil {
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 {
libusb.release(c.dev.handle, uint8(intf))
return nil, fmt.Errorf("failed to set alternate config %d on interface %d of %s: %v", alt, intf, c, err)
if err := libusb.setAlt(c.dev.handle, uint8(num), uint8(alt)); err != nil {
libusb.release(c.dev.handle, uint8(num))
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{
Setting: ifInfo.AltSettings[alt],
config: c,