1
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);
} 

this is the part of handling the device and after that in moving section i have these piece of codes.

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';
}

But with these piece of code are not able to move the snake.What was wrong with it.

hlapa
  • 11
  • 1

0 Answers0