Add config, interfaces, endpoints, etc

This commit is contained in:
Kyle Lemons
2012-03-26 00:06:53 -07:00
parent 804a3c6ab8
commit ba2dd5404f
8 changed files with 235 additions and 28 deletions

View File

@@ -6,7 +6,9 @@ import "C"
import (
"log"
"reflect"
"runtime"
"unsafe"
)
type DeviceInfo struct {
@@ -80,6 +82,30 @@ func newDevice(handle *C.libusb_device_handle) *Device {
return d
}
func (d *Device) Reset() error {
if errno := C.libusb_reset_device(d.handle); errno != 0 {
return usbError(errno)
}
return nil
}
func (d *Device) Control(rType, request uint8, val, idx uint16, data []byte) (int, error) {
dataSlice := (*reflect.SliceHeader)(unsafe.Pointer(&data))
n := C.libusb_control_transfer(
d.handle,
C.uint8_t(rType),
C.uint8_t(request),
C.uint16_t(val),
C.uint16_t(idx),
(*C.uchar)(unsafe.Pointer(dataSlice.Data)),
C.uint16_t(len(data)),
0)
if n < 0 {
return int(n), usbError(n)
}
return int(n), nil
}
func (d *Device) Close() error {
if d.handle != nil {
log.Printf("device %p closed", d.handle)