gofmt
This commit is contained in:
@@ -10,12 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
device = flag.String("device", "vend:prod", "Device to which to connect")
|
device = flag.String("device", "vend:prod", "Device to which to connect")
|
||||||
config = flag.Int("config", 1, "Endpoint to which to connect")
|
config = flag.Int("config", 1, "Endpoint to which to connect")
|
||||||
iface = flag.Int("interface", 0, "Endpoint to which to connect")
|
iface = flag.Int("interface", 0, "Endpoint to which to connect")
|
||||||
setup = flag.Int("setup", 0, "Endpoint to which to connect")
|
setup = flag.Int("setup", 0, "Endpoint to which to connect")
|
||||||
endpoint = flag.Int("endpoint", 1, "Endpoint to which to connect")
|
endpoint = flag.Int("endpoint", 1, "Endpoint to which to connect")
|
||||||
debug = flag.Int("debug", 3, "Debug level for libusb")
|
debug = flag.Int("debug", 3, "Debug level for libusb")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -81,7 +81,7 @@ func main() {
|
|||||||
|
|
||||||
log.Printf("Connecting to endpoint...")
|
log.Printf("Connecting to endpoint...")
|
||||||
log.Printf("- %#v", dev.Descriptor)
|
log.Printf("- %#v", dev.Descriptor)
|
||||||
ep, err := dev.OpenEndpoint(uint8(*config), uint8(*iface), uint8(*setup), uint8(*endpoint) | uint8(usb.ENDPOINT_DIR_IN))
|
ep, err := dev.OpenEndpoint(uint8(*config), uint8(*iface), uint8(*setup), uint8(*endpoint)|uint8(usb.ENDPOINT_DIR_IN))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("open: %s", err)
|
log.Fatalf("open: %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -117,9 +117,9 @@ func newConfig(dev *C.libusb_device, cfg *C.struct_libusb_config_descriptor) Con
|
|||||||
Attributes: uint8(end.bmAttributes),
|
Attributes: uint8(end.bmAttributes),
|
||||||
MaxPacketSize: uint16(end.wMaxPacketSize),
|
MaxPacketSize: uint16(end.wMaxPacketSize),
|
||||||
//MaxIsoPacket: uint32(C.libusb_get_max_iso_packet_size(dev, C.uchar(end.bEndpointAddress))),
|
//MaxIsoPacket: uint32(C.libusb_get_max_iso_packet_size(dev, C.uchar(end.bEndpointAddress))),
|
||||||
PollInterval: uint8(end.bInterval),
|
PollInterval: uint8(end.bInterval),
|
||||||
RefreshRate: uint8(end.bRefresh),
|
RefreshRate: uint8(end.bRefresh),
|
||||||
SynchAddress: uint8(end.bSynchAddress),
|
SynchAddress: uint8(end.bSynchAddress),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
descs = append(descs, i)
|
descs = append(descs, i)
|
||||||
|
@@ -4,8 +4,8 @@ package usb
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
16
usb/iso.go
16
usb/iso.go
@@ -8,8 +8,8 @@ int submit(struct libusb_transfer *xfer);
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -24,8 +24,8 @@ func iso_callback(cptr unsafe.Pointer) {
|
|||||||
func (end *endpoint) allocTransfer() *Transfer {
|
func (end *endpoint) allocTransfer() *Transfer {
|
||||||
// Use libusb_get_max_iso_packet_size ?
|
// Use libusb_get_max_iso_packet_size ?
|
||||||
const (
|
const (
|
||||||
iso_packets = 8 // 128 // 242
|
iso_packets = 8 // 128 // 242
|
||||||
packet_size = 2*960 // 1760
|
packet_size = 2 * 960 // 1760
|
||||||
)
|
)
|
||||||
|
|
||||||
xfer := C.libusb_alloc_transfer(C.int(iso_packets))
|
xfer := C.libusb_alloc_transfer(C.int(iso_packets))
|
||||||
@@ -82,16 +82,16 @@ func (t *Transfer) Submit(timeout time.Duration) error {
|
|||||||
|
|
||||||
func (t *Transfer) Wait(b []byte) (n int, err error) {
|
func (t *Transfer) Wait(b []byte) (n int, err error) {
|
||||||
select {
|
select {
|
||||||
case <-time.After(10*time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
return 0, fmt.Errorf("wait timed out after 10s")
|
return 0, fmt.Errorf("wait timed out after 10s")
|
||||||
case <-t.done:
|
case <-t.done:
|
||||||
}
|
}
|
||||||
n = int(t.xfer.actual_length)
|
n = int(t.xfer.actual_length)
|
||||||
copy(b, ((*[1<<16]byte)(unsafe.Pointer(t.xfer.buffer)))[:n])
|
copy(b, ((*[1 << 16]byte)(unsafe.Pointer(t.xfer.buffer)))[:n])
|
||||||
/*
|
/*
|
||||||
for i, pkt := range t.pkts {
|
for i, pkt := range t.pkts {
|
||||||
log.Printf("PACKET[%4d] - %#v", i, pkt)
|
log.Printf("PACKET[%4d] - %#v", i, pkt)
|
||||||
}*/
|
}*/
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user