From 9fc0278283118730b4f4261e35a0b4175815126d Mon Sep 17 00:00:00 2001 From: Filzmaier Josef Date: Thu, 29 Jun 2017 14:31:12 +0200 Subject: [PATCH] Don't reset the configuration if desired config is already active (#6) Fixes issue #5 --- AUTHORS | 3 ++- device.go | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6406cf0..c7743c9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,4 +10,5 @@ Pieter Joost van de Sande Ivan Krasin Jirawat I. Thordur Bjornsson -Vincent Serpoul \ No newline at end of file +Vincent Serpoul +Josef Filzmaier diff --git a/device.go b/device.go index 853b2a2..3083717 100644 --- a/device.go +++ b/device.go @@ -128,8 +128,13 @@ func (d *Device) Config(cfgNum int) (*Config, error) { dev: d, claimed: make(map[int]bool), } - if err := libusb.setConfig(d.handle, uint8(cfgNum)); err != nil { - return nil, fmt.Errorf("failed to set active config %d for the device %s: %v", cfgNum, d, err) + + if activeCfgNum, err := d.ActiveConfigNum(); err != nil { + return nil, fmt.Errorf("failed to query active config of the device %s: %v", d, err) + } else if cfgNum != activeCfgNum { + if err := libusb.setConfig(d.handle, uint8(cfgNum)); err != nil { + return nil, fmt.Errorf("failed to set active config %d for the device %s: %v", cfgNum, d, err) + } } d.mu.Lock() defer d.mu.Unlock()