From 28a4c23af3bdfb0b5e8fdd50656f0adf645bf491 Mon Sep 17 00:00:00 2001 From: Ivan Krasin Date: Sun, 16 Jun 2013 19:54:30 -0700 Subject: [PATCH 1/2] Add RequestType enum values to be passed to Device.Control() --- usb/constants.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/usb/constants.go b/usb/constants.go index b83c2d3..8a25984 100644 --- a/usb/constants.go +++ b/usb/constants.go @@ -147,3 +147,23 @@ var isoUsageTypeDescription = map[IsoUsageType]string{ func (iut IsoUsageType) String() string { return isoUsageTypeDescription[iut] } + +type RequestType uint8 + +const ( + REQUEST_TYPE_STANDARD = C.LIBUSB_REQUEST_TYPE_STANDARD + REQUEST_TYPE_CLASS = C.LIBUSB_REQUEST_TYPE_CLASS + REQUEST_TYPE_VENDOR = C.LIBUSB_REQUEST_TYPE_VENDOR + REQUEST_TYPE_RESERVED = C.LIBUSB_REQUEST_TYPE_RESERVED +) + +var requestTypeDescription = map[RequestType]string{ + REQUEST_TYPE_STANDARD: "standard", + REQUEST_TYPE_CLASS: "class", + REQUEST_TYPE_VENDOR: "vendor", + REQUEST_TYPE_RESERVED: "reserved", +} + +func (rt RequestType) String() string { + return requestTypeDescription[rt] +} From b0713f61b43641e5d4fdf4d7a44ea58dfdc8e997 Mon Sep 17 00:00:00 2001 From: Ivan Krasin Date: Sun, 16 Jun 2013 20:29:54 -0700 Subject: [PATCH 2/2] Allow opening multiple endpoints for the same device, if configuration is also the same. --- usb/device.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/usb/device.go b/usb/device.go index 1264e65..bd39ce1 100644 --- a/usb/device.go +++ b/usb/device.go @@ -157,8 +157,14 @@ func (d *Device) OpenEndpoint(conf, iface, setup, epoint uint8) (Endpoint, error found: // Set the configuration - if errno := C.libusb_set_configuration(d.handle, C.int(conf)); errno < 0 { - return nil, fmt.Errorf("usb: setcfg: %s", usbError(errno)) + var activeConf C.int + if errno := C.libusb_get_configuration(d.handle, &activeConf); errno < 0 { + return nil, fmt.Errorf("usb: getcfg: %s", usbError(errno)) + } + if int(activeConf) != int(conf) { + if errno := C.libusb_set_configuration(d.handle, C.int(conf)); errno < 0 { + return nil, fmt.Errorf("usb: setcfg: %s", usbError(errno)) + } } // Claim the interface