diff --git a/usb/device.go b/usb/device.go index 5a256c3..9129990 100644 --- a/usb/device.go +++ b/usb/device.go @@ -141,7 +141,7 @@ func (d *Device) OpenEndpoint(cfgNum, ifNum, setNum, epNum uint8) (Endpoint, err return nil, fmt.Errorf("usb: unknown endpoint %02x", epNum) } - end := newEndpoint(d, *ifs, *ep) + end := newEndpoint(d.handle, *ifs, *ep, d.ReadTimeout, d.WriteTimeout) // Set the configuration activeConf, err := libusb.getConfig(d.handle) diff --git a/usb/endpoint.go b/usb/endpoint.go index cd9b427..067fa63 100644 --- a/usb/endpoint.go +++ b/usb/endpoint.go @@ -78,12 +78,12 @@ func (e *endpoint) transfer(buf []byte, timeout time.Duration) (int, error) { return n, nil } -func newEndpoint(d *Device, s InterfaceSetup, e EndpointInfo) *endpoint { +func newEndpoint(h *libusbDevHandle, s InterfaceSetup, e EndpointInfo, rt, wt time.Duration) *endpoint { return &endpoint{ InterfaceSetup: s, EndpointInfo: e, - h: d.handle, - readTimeout: d.ReadTimeout, - writeTimeout: d.WriteTimeout, + h: h, + readTimeout: rt, + writeTimeout: wt, } } diff --git a/usb/endpoint_test.go b/usb/endpoint_test.go index a8b7a04..3e89868 100644 --- a/usb/endpoint_test.go +++ b/usb/endpoint_test.go @@ -17,6 +17,7 @@ package usb import ( "reflect" "testing" + "time" ) func TestEndpoint(t *testing.T) { @@ -61,10 +62,7 @@ func TestEndpoint(t *testing.T) { } { lib := newFakeLibusb() libusb = lib - ep := &endpoint{ - InterfaceSetup: epCfg.InterfaceSetup, - EndpointInfo: epCfg.EndpointInfo, - } + ep := newEndpoint(nil, epCfg.InterfaceSetup, epCfg.EndpointInfo, time.Second, time.Second) op, ok := reflect.TypeOf(ep).MethodByName(epCfg.method) if !ok { t.Fatalf("method %s not found in endpoint struct", epCfg.method)