예제 #1
0
파일: golibusb.go 프로젝트: acsellers/Go510
func SpecialKeyMonitor(handle *C.struct_libusb_device_handle, output chan guinput.KeyEvent) {

	data_buffer := make([]C.uchar, 512)
	key_endpoint := C.uchar(0x82)
	transferred_bytes := C.int(0)
	pressed_duos := uint8(0)

	for {
		e := C.libusb_interrupt_transfer(handle, key_endpoint, &data_buffer[0], 512, &transferred_bytes, 10)
		switch e {
		case 0:
			//we did it
			log.Print("Special Key data received")

			//the media buttons and dials in the top uh right
			//THey transfer 2 bytes and the first byte is 2, so duos
			if transferred_bytes == 2 && data_buffer[0] == 0x02 {
				ParseDuos(uint8(data_buffer[1]), pressed_duos, output)
				pressed_duos = uint8(data_buffer[1])
			}
			for i := 0; i < int(transferred_bytes); i++ {
				fmt.Printf("%02x\n", data_buffer[i])
			}
		case -7:
			//nothing happened
		default:
			//augh, panic
			fmt.Println("Augh panic")
		}
	}

}
예제 #2
0
파일: io.go 프로젝트: thequux/gousb
func interruptTransfer(ep *EndpointHandle, p []byte, _ bool) (n int, err error) {
	var transferred C.int
	err0 := returnUsbError(C.libusb_interrupt_transfer(
		ep.handle.handle,
		C.uchar(ep.ep),
		(*C.uchar)(unsafe.Pointer(&p[0])),
		C.int(len(p)),
		&transferred,
		0))
	if err0 != nil {
		err = err0
	}
	return int(transferred), err
}
예제 #3
0
파일: endpoint.go 프로젝트: pjvds/gousb
func interrupt_xfer(e *endpoint, buf []byte, timeout time.Duration) (int, error) {
	if len(buf) == 0 {
		return 0, nil
	}

	data := (*reflect.SliceHeader)(unsafe.Pointer(&buf)).Data

	var cnt C.int
	if errno := C.libusb_interrupt_transfer(
		e.handle,
		C.uchar(e.Address),
		(*C.uchar)(unsafe.Pointer(data)),
		C.int(len(buf)),
		&cnt,
		C.uint(timeout/time.Millisecond)); errno < 0 {
		return 0, usbError(errno)
	}
	return int(cnt), nil
}
예제 #4
0
파일: golibusb.go 프로젝트: acsellers/Go510
//Scan for keys on the normal interface
func NormalKeyMonitor(handle *C.struct_libusb_device_handle, output chan guinput.KeyEvent) {
	//libusb will drop data into data_buffer, our endpoint id is 0x81 (from lsusb)
	data_buffer := make([]C.uchar, 8)
	current_keys := make([]uint8, 8)
	key_endpoint := C.uchar(0x81)
	transferred_bytes := C.int(0)

	for {
		e := C.libusb_interrupt_transfer(handle, key_endpoint, &data_buffer[0], 8, &transferred_bytes, 100)
		switch e {
		case 0:
			//you got the dataz!!
			//TODO: use a slice instead of starting at 2
			fmt.Printf("Received usb packet: %02x|%02x.%02x.%02x.%02x.%02x.%02x\n", data_buffer[1], data_buffer[2], data_buffer[3], data_buffer[4], data_buffer[5], data_buffer[6], data_buffer[7])
			for i := 2; i < 8; i++ {
				if data_buffer[i] == 0x00 && current_keys[i] != 0 {
					output <- guinput.KeyEvent{guinput.KEY_UP_CODE, current_keys[i]}
					current_keys[i] = 0x00
				}
				if data_buffer[i] != 0x00 {
					log.Printf("Key pressed:%02x", data_buffer[i])
					ucode := KEYMAP[uint8(data_buffer[i])]
					if ucode != current_keys[i] && current_keys[i] != 0 {
						output <- guinput.KeyEvent{guinput.KEY_UP_CODE, current_keys[i]}
					}
					current_keys[i] = ucode
					output <- guinput.KeyEvent{guinput.KEY_DOWN_CODE, current_keys[i]}
				}
			}
			if uint8(data_buffer[0]) != current_keys[0] {
				ParseModifiers(uint8(data_buffer[0]), current_keys[0], output)
				current_keys[0] = uint8(data_buffer[0])
			}
		case -7:
			//nothing happened
		default:
			//augh, panic
			log.Printf("Normal libusb goroutine encountered %d", e)
		}
	}
}
예제 #5
0
파일: new.go 프로젝트: acsellers/Go510
func SetLCD(pix *image.Gray) {
	if !Connected {
		if err := StartLibUsb(); err != nil {
			return
		}
		defer EndLibUsb()
	}
	var img [992]C.uchar
	imgOffset := 32
	var curr, row uint8

	for offset := 0; offset < 5; offset++ {
		for col := 0; col < 160; col++ {
			curr = 0
			for row = 0; row < 8; row++ {
				if pix.Pix[(offset*8+int(row)-pix.Rect.Min.Y)*pix.Stride+(col-pix.Rect.Min.X)]>>4 > 0 {
					curr += 1 << row
				}
			}
			img[imgOffset] = C.uchar(curr)
			imgOffset++
		}
	}
	for col := 0; col < 160; col++ {
		curr = 0
		for row = 0; row < 3; row++ {
			if pix.Pix[(40+int(row)-pix.Rect.Min.Y)*pix.Stride+(col-pix.Rect.Min.X)]>>4 > 0 {
				curr += 1 << row
			}
		}
		img[imgOffset] = C.uchar(curr)
		imgOffset++
	}

	//magic byte from libg15 and USBTrace
	img[0] = 0x03

	transferred := C.int(0)
	C.libusb_interrupt_transfer(keyboardHandle, 0x3, &img[0], 992, &transferred, 1000)
}