Rename ListDevices to OpenDevices. Add more doc for RemoteWakeup.
This commit is contained in:
@@ -28,7 +28,12 @@ type ConfigDesc struct {
|
||||
// SelfPowered is true if the device is powered externally, i.e. not
|
||||
// drawing power from the USB bus.
|
||||
SelfPowered bool
|
||||
// RemoteWakeup is true if the device supports remote wakeup.
|
||||
// RemoteWakeup is true if the device supports remote wakeup, i.e.
|
||||
// an external signal that will wake up a suspended USB device. An example
|
||||
// might be a keyboard that can wake up through a keypress after
|
||||
// the host put it in suspend mode. Note that gousb does not support
|
||||
// device power management, RemoteWakeup only refers to the reported device
|
||||
// capability.
|
||||
RemoteWakeup bool
|
||||
// MaxPower is the maximum current the device draws from the USB bus
|
||||
// in this configuration.
|
||||
@@ -89,7 +94,7 @@ 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", num, alt, c)
|
||||
}
|
||||
if num < 0 || intNum >= len(c.Desc.Interfaces) {
|
||||
if num < 0 || num >= 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[num]
|
||||
|
@@ -80,7 +80,7 @@ func Example_complex() {
|
||||
|
||||
// Iterate through available Devices, finding all that match a known VID/PID.
|
||||
vid, pid := gousb.ID(0x04f2), gousb.ID(0xb531)
|
||||
devs, err := ctx.ListDevices(func(desc *gousb.DeviceDesc) bool {
|
||||
devs, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool {
|
||||
// this function is called for every device present.
|
||||
// Returning true means the device should be opened.
|
||||
return desc.Vendor == vid && desc.Product == pid
|
||||
@@ -90,7 +90,7 @@ func Example_complex() {
|
||||
defer d.Close()
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("ListDevices(): %v", err)
|
||||
log.Fatalf("OpenDevices(): %v", err)
|
||||
}
|
||||
if len(devs) == 0 {
|
||||
log.Fatalf("no devices found matching VID %s and PID %s", vid, pid)
|
||||
|
10
usb.go
10
usb.go
@@ -145,12 +145,12 @@ func NewContext() *Context {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// ListDevices calls each with each enumerated device.
|
||||
// If the function returns true, the device is opened and a Device is returned if the operation succeeds.
|
||||
// OpenDevices calls opener with each enumerated device.
|
||||
// If the opener returns true, the device is opened and a Device is returned if the operation succeeds.
|
||||
// Every Device returned (whether an error is also returned or not) must be closed.
|
||||
// If there are any errors enumerating the devices,
|
||||
// the final one is returned along with any successfully opened devices.
|
||||
func (c *Context) ListDevices(each func(desc *DeviceDesc) bool) ([]*Device, error) {
|
||||
func (c *Context) OpenDevices(opener func(desc *DeviceDesc) bool) ([]*Device, error) {
|
||||
list, err := libusb.getDevices(c.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -166,7 +166,7 @@ func (c *Context) ListDevices(each func(desc *DeviceDesc) bool) ([]*Device, erro
|
||||
continue
|
||||
}
|
||||
|
||||
if each(desc) {
|
||||
if opener(desc) {
|
||||
handle, err := libusb.open(dev)
|
||||
if err != nil {
|
||||
reterr = err
|
||||
@@ -188,7 +188,7 @@ func (c *Context) ListDevices(each func(desc *DeviceDesc) bool) ([]*Device, erro
|
||||
// be called to release the device if the returned device wasn't nil.
|
||||
func (c *Context) OpenDeviceWithVIDPID(vid, pid ID) (*Device, error) {
|
||||
var found bool
|
||||
devs, err := c.ListDevices(func(desc *DeviceDesc) bool {
|
||||
devs, err := c.OpenDevices(func(desc *DeviceDesc) bool {
|
||||
if found {
|
||||
return false
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ package gousb
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestListDevices(t *testing.T) {
|
||||
func TestOPenDevices(t *testing.T) {
|
||||
_, done := newFakeLibusb()
|
||||
defer done()
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestListDevices(t *testing.T) {
|
||||
c.Debug(0)
|
||||
|
||||
descs := []*DeviceDesc{}
|
||||
devs, err := c.ListDevices(func(desc *DeviceDesc) bool {
|
||||
devs, err := c.OpenDevices(func(desc *DeviceDesc) bool {
|
||||
descs = append(descs, desc)
|
||||
return true
|
||||
})
|
||||
@@ -36,7 +36,7 @@ func TestListDevices(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
t.Fatalf("ListDevices(): %s", err)
|
||||
t.Fatalf("OpenDevices(): %s", err)
|
||||
}
|
||||
|
||||
if got, want := len(devs), len(fakeDevices); got != want {
|
||||
|
Reference in New Issue
Block a user