make addr() part of EndpointInfo

This commit is contained in:
Sebastian Zagrodzki
2017-04-09 18:55:41 +02:00
parent 13f4e95f2f
commit f58798160d
2 changed files with 8 additions and 8 deletions

View File

@@ -44,14 +44,18 @@ type EndpointInfo struct {
UsageType UsageType UsageType UsageType
} }
// String returns the human-readable description of the endpoint. func (e EndpointInfo) addr() uint8 {
func (e EndpointInfo) String() string {
addr := e.Number addr := e.Number
if e.Direction == EndpointDirectionIn { if e.Direction == EndpointDirectionIn {
addr |= 0x80 addr |= 0x80
} }
return addr
}
// String returns the human-readable description of the endpoint.
func (e EndpointInfo) String() string {
ret := make([]string, 0, 3) ret := make([]string, 0, 3)
ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, addr, e.TransferType)) ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, e.addr(), e.TransferType))
switch e.TransferType { switch e.TransferType {
case TransferTypeIsochronous: case TransferTypeIsochronous:
ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType)) ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType))

View File

@@ -374,11 +374,7 @@ func (libusbImpl) alloc(d *libusbDevHandle, ep *EndpointInfo, timeout time.Durat
return nil, fmt.Errorf("libusb_alloc_transfer(%d) failed", isoPackets) return nil, fmt.Errorf("libusb_alloc_transfer(%d) failed", isoPackets)
} }
xfer.dev_handle = (*C.libusb_device_handle)(d) xfer.dev_handle = (*C.libusb_device_handle)(d)
addr := ep.Number & endpointNumMask xfer.endpoint = C.uchar(ep.addr())
if ep.Direction == EndpointDirectionIn {
addr |= endpointDirectionMask
}
xfer.endpoint = C.uchar(addr)
xfer.timeout = C.uint(timeout / time.Millisecond) xfer.timeout = C.uint(timeout / time.Millisecond)
xfer._type = C.uchar(ep.TransferType) xfer._type = C.uchar(ep.TransferType)
xfer.num_iso_packets = C.int(isoPackets) xfer.num_iso_packets = C.int(isoPackets)