4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
1
|
#include <stdio.h>
|
8fc8e350
henyxia
USB Initializatio...
|
2
|
#include <stdbool.h>
|
0907768b
henyxia
Displaying some c...
|
3
|
#include <unistd.h>
|
8fc8e350
henyxia
USB Initializatio...
|
4
|
#include <libusb-1.0/libusb.h>
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
5
|
|
0907768b
henyxia
Displaying some c...
|
6
7
8
9
10
11
|
#define VENDOR_ID 0xfccf
#define PRODUCT_ID 0xa001
#define ENDPOINT_OUT 0x01
#define MAX_SIZE_OUT 64
libusb_device_handle* screenHandle;
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
12
|
|
8fc8e350
henyxia
USB Initializatio...
|
13
|
bool initUI(void)
|
a0ae785b
Jean Wasilewski
Non working version
|
14
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
15
|
int ret;
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
16
|
|
8fc8e350
henyxia
USB Initializatio...
|
17
18
|
ret = libusb_init(NULL);
if(ret != 0)
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
19
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
20
21
|
printf("Error while initializing libusb, return : %d\n", ret);
return false;
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
22
23
|
}
|
8fc8e350
henyxia
USB Initializatio...
|
24
25
26
|
struct libusb_config_descriptor* dConfig = NULL;
libusb_device** list = NULL;
ssize_t cnt = libusb_get_device_list(NULL, &list);
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
27
|
|
8fc8e350
henyxia
USB Initializatio...
|
28
|
struct libusb_device_descriptor dDevice;
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
29
|
|
8fc8e350
henyxia
USB Initializatio...
|
30
31
32
33
|
printf("Starting lsusb things\n");
if(cnt < 0)
|
262d40e6
Jean Wasilewski
Working version b...
|
34
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
35
36
|
printf("Unable to get USB device list\n");
return false;
|
10b7eef7
henyxia
Separated color a...
|
37
38
|
}
|
8fc8e350
henyxia
USB Initializatio...
|
39
40
|
printf("%d devices detected\n", cnt);
printf("List of compatible devices detected\n");
|
10b7eef7
henyxia
Separated color a...
|
41
|
|
8fc8e350
henyxia
USB Initializatio...
|
42
|
for (int i = 0; i < cnt; i++)
|
10b7eef7
henyxia
Separated color a...
|
43
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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;
}
}
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
59
|
}
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
60
|
|
8fc8e350
henyxia
USB Initializatio...
|
61
|
libusb_free_device_list(list, 1);
|
262d40e6
Jean Wasilewski
Working version b...
|
62
|
|
8fc8e350
henyxia
USB Initializatio...
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
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; j<dConfig->bNumInterfaces; 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; j<dConfig->bNumInterfaces; 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);
|
262d40e6
Jean Wasilewski
Working version b...
|
96
|
|
8fc8e350
henyxia
USB Initializatio...
|
97
98
|
return true;
}
|
262d40e6
Jean Wasilewski
Working version b...
|
99
|
|
8fc8e350
henyxia
USB Initializatio...
|
100
101
|
int main(void)
{
|
0907768b
henyxia
Displaying some c...
|
102
103
|
int transfered;
|
8fc8e350
henyxia
USB Initializatio...
|
104
|
if(!initUI())
|
0907768b
henyxia
Displaying some c...
|
105
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
106
|
printf("Unable to initialize the UI\n");
|
0907768b
henyxia
Displaying some c...
|
107
108
109
110
111
112
113
|
return 1;
}
printf("Screen Initialized\n");
sleep(2);
|
4e2d795d
henyxia
Four pixels succe...
|
114
|
printf("Sending GREEN command\n");
|
0907768b
henyxia
Displaying some c...
|
115
116
|
//libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, data, MAX_SIZE_OUT, &transfered, 0);
|
ec5a157f
henyxia
Purple screen
|
117
|
unsigned char odata[] = {0x81, 0x0E, 0x40};
|
4e2d795d
henyxia
Four pixels succe...
|
118
119
|
libusb_bulk_transfer(screenHandle, ENDPOINT_OUT, odata, 3, &transfered, 0);
|
8fc8e350
henyxia
USB Initializatio...
|
120
|
return 0;
|
262d40e6
Jean Wasilewski
Working version b...
|
121
|
}
|