#include #include #include #include #define VENDOR_ID 0xfccf #define PRODUCT_ID 0xa001 #define ENDPOINT_OUT 0x01 #define MAX_SIZE_OUT 64 libusb_device_handle* screenHandle; bool initUI(void) { int ret; ret = libusb_init(NULL); if(ret != 0) { printf("Error while initializing libusb, return : %d\n", ret); return false; } struct libusb_config_descriptor* dConfig = NULL; libusb_device** list = NULL; ssize_t cnt = libusb_get_device_list(NULL, &list); struct libusb_device_descriptor dDevice; printf("Starting lsusb things\n"); if(cnt < 0) { printf("Unable to get USB device list\n"); return false; } printf("%d devices detected\n", cnt); printf("List of compatible devices detected\n"); for (int i = 0; i < cnt; i++) { libusb_device *device = list[i]; ret = libusb_get_device_descriptor(device, &dDevice); if(VENDOR_ID == dDevice.idVendor && PRODUCT_ID == dDevice.idProduct) { printf("Bus %03d Device %03d: ID %04x:%04x\n", libusb_get_bus_number(device), libusb_get_device_address(device), dDevice.idVendor, dDevice.idProduct); ret = libusb_open(device, &screenHandle); if(ret != 0) { printf("Unable to open this device, error %d\n", ret); return false; } } } libusb_free_device_list(list, 1); ret = libusb_get_config_descriptor(libusb_get_device(screenHandle), 0, &dConfig); if(ret!=0) { printf("Descriptor for this device unavailable\n"); return false; } else { for(int j=0; jbNumInterfaces; j++) { if(libusb_kernel_driver_active(screenHandle, j) && (libusb_detach_kernel_driver(screenHandle, j) != 0)) { printf("Unable to detach this device\n"); return false; } } ret = libusb_set_configuration(screenHandle, dConfig->bConfigurationValue); if(ret != 0) { printf("Configuration unavailable, error %d\n", ret); return false; } for(int j=0; jbNumInterfaces; j++) if(libusb_claim_interface(screenHandle, j) != 0) { printf("Device not claimed\n"); return false; } else printf("Interface %d ready\n", j); } libusb_free_config_descriptor(dConfig); return true; } int main(void) { int transfered; if(!initUI()) { printf("Unable to initialize the UI\n"); return 1; } printf("Screen Initialized\n"); sleep(2); printf("Sending GREEN command\n"); //libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, data, MAX_SIZE_OUT, &transfered, 0); unsigned char odata[] = {0x81, 0xF8, 0x1F}; libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, odata, 3, &transfered, 0); sleep(2); printf("Sending BLUE command\n"); odata[0] = 0x81; odata[1] = 0x07; odata[2] = 0xFF; libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, odata, 3, &transfered, 0); sleep(2); printf("Sending PIXEL command\n"); unsigned char data[] = {0x82, 0x0A, 0x00, 0x0A, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, data, 18, &transfered, 0); /* data[0] = 0x02; data[1] = 0x00; data[2] = 0x00; data[3] = 0x1F; data[4] = 0x00; data[5] = 0x00; data[6] = 0x00; data[7] = 0x00; libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, data, 3, &transfered, 0); */ return 0; }