Esempio n. 1
0
func (dev *linuxDevice) writeReport(hid_report_type int, data []byte) error {
	if dev.handle == nil {
		return errors.New("No USB device opend before.")
	}
	if len(data) > 0xffff {
		return errors.New("data longer than 65535 bytes, means overflow, isn't supported")
	}
	if len(data) == 0 {
		return nil
	}

	const reportId = 1
	const index = 0
	const timeout = 1000

	written := C.libusb_control_transfer(dev.handle,
		C.uint8_t(ENDPOINT_OUT|RECIPIENT_DEVICE|DT_REPORT|hid_report_type),
		C.uint8_t(HID_SET_REPORT),
		C.uint16_t(reportId),
		C.uint16_t(index),
		(*C.uchar)(&data[0]),
		C.uint16_t(len(data)),
		C.uint(timeout))

	if int(written) == len(data) {
		return nil
	}
	return usbError(written)
}
Esempio n. 2
0
File: usb.go Progetto: karitra/mp707
// USB_GET_FEATURE
func (t *MP707Dev) usbReadCtl() *UsbError {
	if r := C.libusb_control_transfer( t.dev, 0xA1, 0x01, 0x300, 0, t.inb, len(t.inb), TIMEOUT ); r != 0 {
		return MakeUsbError(r)
	}

	return nil
}
Esempio n. 3
0
File: usb.go Progetto: karitra/mp707
// bmRequest bits config
// 
// 12345678
// -        Transfer direction: 0 host->device, 1 device -> host
//  --      Type: 0 std, 1 class, 2 vendor, 3 reserved
//    ----- Recipient: 0 device, 1 if, 2 endpoint, 3 other
//
// USB_SET_FEATURE
func (t *MP707Dev) usbWriteCtl() *UsbError {
	if r := C.libusb_control_transfer( t.dev, 0x21, 0x09, 0x300, 0, t.outb, len(t.outb), TIMEOUT ); r != 0 {
		return MakeUsbError(r)
	}

	return nil
}
Esempio n. 4
0
func SetColor(clr color.Color) {
	command_buffer := [4]C.uchar{0x05, 0x00, 0x00, 0x00}

	r, g, b, _ := clr.RGBA()
	command_buffer[1] = C.uchar(uint8(r))
	command_buffer[2] = C.uchar(uint8(g))
	command_buffer[3] = C.uchar(uint8(b))

	C.libusb_control_transfer(keyboardHandle, 33, 9, 0x305, 1, &command_buffer[0], 0x4, 1000)
}
Esempio n. 5
0
func ColorChange(handle *C.struct_libusb_device_handle, color chan byte) {
	command_buffer := [4]C.uchar{0x05, 0x00, 0x00, 0x00}

	for {
		command_buffer[1] = C.uchar(<-color)
		command_buffer[2] = C.uchar(<-color)
		command_buffer[3] = C.uchar(<-color)

		r := C.libusb_control_transfer(handle, 33, 9, 0x305, 1, &command_buffer[0], 0x4, 1000)
		log.Printf("Color Change Response %d\n", r)
	}
}
Esempio n. 6
0
File: usb.go Progetto: hanwen/usb
func (h *DeviceHandle) ControlTransfer(reqType, req byte, value, index uint16,
	data []byte, timeout int) error {
	var ptr *byte
	if len(data) > 0 {
		ptr = &data[0]
	}
	if len(data) > 0xffff {
		return fmt.Errorf("overflow")
	}
	err := C.libusb_control_transfer(h.me(),
		C.uint8_t(reqType), C.uint8_t(req), C.uint16_t(value), C.uint16_t(index),
		(*C.uchar)(ptr), C.uint16_t(len(data)), C.uint(timeout))
	return toErr(err)
}
Esempio n. 7
0
func (d *Device) Control(rType, request uint8, val, idx uint16, data []byte) (int, error) {
	//log.Printf("control xfer: %d:%d/%d:%d %x", idx, rType, request, val, string(data))
	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)),
		C.uint(d.ControlTimeout/time.Millisecond))
	if n < 0 {
		return int(n), usbError(n)
	}
	return int(n), nil
}