Add Device.OutEndpoint, simplify endpoint test.

This commit is contained in:
Sebastian Zagrodzki
2017-04-10 01:11:38 +02:00
parent 57b10f0dd3
commit b1dcaa1195
3 changed files with 88 additions and 72 deletions

View File

@@ -182,6 +182,7 @@ func (d *Device) openEndpoint(cfgNum, ifNum, setNum, epAddr uint8) (*endpoint, e
return end, nil
}
// InEndpoint prepares an IN endpoint for transfer.
func (d *Device) InEndpoint(cfgNum, ifNum, setNum, epNum uint8) (*InEndpoint, error) {
ep, err := d.openEndpoint(cfgNum, ifNum, setNum, endpointAddr(epNum, EndpointDirectionIn))
if err != nil {
@@ -193,6 +194,18 @@ func (d *Device) InEndpoint(cfgNum, ifNum, setNum, epNum uint8) (*InEndpoint, er
}, nil
}
// OutEndpoint prepares an OUT endpoint for transfer.
func (d *Device) OutEndpoint(cfgNum, ifNum, setNum, epNum uint8) (*OutEndpoint, error) {
ep, err := d.openEndpoint(cfgNum, ifNum, setNum, endpointAddr(epNum, EndpointDirectionOut))
if err != nil {
return nil, err
}
return &OutEndpoint{
endpoint: ep,
timeout: d.WriteTimeout,
}, nil
}
// GetStringDescriptor returns a device string descriptor with the given index
// number. The first supported language is always used and the returned
// descriptor string is converted to ASCII (non-ASCII characters are replaced