Skip to content

Commit

Permalink
Merge pull request #1 from mattdf/endpoints
Browse files Browse the repository at this point in the history
Add ability to set Endpoint and Interface for devices with multiple choices
  • Loading branch information
zserge authored Sep 7, 2016
2 parents 132e1c3 + 9954f88 commit 8ac6f75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func main() {
found := false
hid.UsbWalk(func(device hid.Device) {
info := device.Info()
fmt.Printf("%04x:%04x:%04x\n", info.Vendor, info.Product, info.Revision)
fmt.Printf("%04x:%04x:%04x:%02x\n", info.Vendor, info.Product, info.Revision, info.Interface)
found = true
})
if !found {
Expand All @@ -131,7 +131,7 @@ func main() {

hid.UsbWalk(func(device hid.Device) {
info := device.Info()
id := fmt.Sprintf("%04x:%04x:%04x", info.Vendor, info.Product, info.Revision)
id := fmt.Sprintf("%04x:%04x:%04x:%02x", info.Vendor, info.Product, info.Revision, info.Interface)
if id != os.Args[1] {
return
}
Expand Down
9 changes: 9 additions & 0 deletions usb_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func walker(path string, cb func(Device)) error {
device = nil
}
case UsbDescTypeInterface:
if device != nil {
cb(device)
device = nil
}
expected[UsbDescTypeEndpoint] = true
expected[UsbDescTypeReport] = true
i := &interfaceDesc{}
Expand All @@ -250,6 +254,11 @@ func walker(path string, cb func(Device)) error {
}
case UsbDescTypeEndpoint:
if device != nil {
if device.epIn != 0 && device.epOut != 0 {
cb(device)
device.epIn = 0
device.epOut = 0
}
e := &endpointDesc{}
if err := cast(body, e); err != nil {
return err
Expand Down

0 comments on commit 8ac6f75

Please sign in to comment.