add xbox example and make some changes to support it
This commit is contained in:
22
usb/debug.go
Normal file
22
usb/debug.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package usb
|
||||||
|
|
||||||
|
// To enable internal debugging:
|
||||||
|
// -ldflags "-X github.com/kylelemons/gousb/usb.debugInternal true"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log" // TODO(kevlar): make a logger
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var debug *log.Logger
|
||||||
|
var debugInternal string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var out io.Writer = ioutil.Discard
|
||||||
|
if debugInternal != "" {
|
||||||
|
out = os.Stderr
|
||||||
|
}
|
||||||
|
debug = log.New(out, "usb", log.LstdFlags|log.Lshortfile)
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import "C"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
//"log" // TODO(kevlar): make a logger
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -112,23 +111,26 @@ func (d *Device) OpenEndpoint(conf, iface, setup, epoint uint8) (Endpoint, error
|
|||||||
Device: d,
|
Device: d,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var setAlternate bool
|
||||||
for _, c := range d.Configs {
|
for _, c := range d.Configs {
|
||||||
if c.Config != conf {
|
if c.Config != conf {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("found conf: %#v\n", c)
|
debug.Printf("found conf: %#v\n", c)
|
||||||
for _, i := range c.Interfaces {
|
for _, i := range c.Interfaces {
|
||||||
if i.Number != iface {
|
if i.Number != iface {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("found iface: %#v\n", i)
|
debug.Printf("found iface: %#v\n", i)
|
||||||
for _, s := range i.Setups {
|
for i, s := range i.Setups {
|
||||||
if s.Alternate != setup {
|
if s.Alternate != setup {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("found setup: %#v\n", s)
|
setAlternate = i != 0
|
||||||
|
|
||||||
|
debug.Printf("found setup: %#v [default: %v]\n", s, !setAlternate)
|
||||||
for _, e := range s.Endpoints {
|
for _, e := range s.Endpoints {
|
||||||
fmt.Printf("ep %02x search: %#v\n", epoint, s)
|
debug.Printf("ep %02x search: %#v\n", epoint, s)
|
||||||
if e.Address != epoint {
|
if e.Address != epoint {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -178,10 +180,11 @@ found:
|
|||||||
d.lock.Unlock() // unlock immediately because the next calls may block
|
d.lock.Unlock() // unlock immediately because the next calls may block
|
||||||
|
|
||||||
// Choose the alternate
|
// Choose the alternate
|
||||||
// This doesn't seem to work...
|
if setAlternate {
|
||||||
if errno := C.libusb_set_interface_alt_setting(d.handle, C.int(iface), C.int(setup)); errno < 0 {
|
if errno := C.libusb_set_interface_alt_setting(d.handle, C.int(iface), C.int(setup)); errno < 0 {
|
||||||
//log.Printf("ignoring altsetting error: %s", usbError(errno))
|
debug.Printf("altsetting error: %s", usbError(errno))
|
||||||
return nil, fmt.Errorf("usb: setalt: %s", usbError(errno))
|
return nil, fmt.Errorf("usb: setalt: %s", usbError(errno))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return end, nil
|
return end, nil
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package usb
|
package usb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// #include <libusb-1.0/libusb.h>
|
// #include <libusb-1.0/libusb.h>
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type usbError C.int
|
type usbError C.int
|
||||||
|
|
||||||
func (e usbError) Error() string {
|
func (e usbError) Error() string {
|
||||||
return "libusb: " + usbErrorString[e]
|
return fmt.Sprintf("libusb: %s [code %d]", usbErrorString[e], int(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
316
xbox/xbox.go
Normal file
316
xbox/xbox.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user