libusb_device_handle *h;
int transferred , r;
r = libusb_init(NULL);
libusb_set_debug(NULL, 3);
//Open device
h = libusb_open_device_with_vid_pid(NULL, 0x045e, 0x028e);
if (h == NULL) {
fprintf(stderr, "Failed to open device\n");
return (1);
}
r = libusb_kernel_driver_active(h,0);
if(r>0)
r = libusb_detach_kernel_driver(h,0);
r = libusb_claim_interface(h,0);
if(r!=0)
{
fprintf(stderr, "Interface failed: %d\n",r);
return (1);
}
这是处理设备的一部分,之后在移动部分我有这些代码。
unsigned char buffer[20];
libusb_interrupt_transfer(h, 0x81, buffer, sizeof (buffer), &transferred, 0);
char direction = 'l';
if (((buffer[3] >> 6)&0x01)) {
if (direction != 'r')
direction = 'l';
}
if (((buffer[3] >> 7)&0x01)) {
if (direction != 'd')
direction = 'u';
}
if (((buffer[3] >> 4)&0x01)) {
if (direction != 'u')
direction = 'd';
}
if (((buffer[3] >> 5)&0x01)) {
if (direction != 'l')
direction = 'r';
}
但是这些代码无法移动蛇。它出了什么问题。