Don't reset the configuration if desired config is already active (#6)
Fixes issue #5
This commit is contained in:

committed by
zagrodzki

parent
aa64bae804
commit
9fc0278283
3
AUTHORS
3
AUTHORS
@@ -10,4 +10,5 @@ Pieter Joost van de Sande <pj@born2code.net>
|
||||
Ivan Krasin <imkrasin@gmail.com>
|
||||
Jirawat I. <nodtem66@gmail.com>
|
||||
Thordur Bjornsson <thorduri@secnorth.net>
|
||||
Vincent Serpoul <vincent@serpoul.com>
|
||||
Vincent Serpoul <vincent@serpoul.com>
|
||||
Josef Filzmaier <josef.filzmaier@gmail.com>
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user