4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
1
|
#include <stdio.h>
|
8fc8e350
henyxia
USB Initializatio...
|
2
3
|
#include <stdbool.h>
#include <libusb-1.0/libusb.h>
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
4
|
|
8fc8e350
henyxia
USB Initializatio...
|
5
6
|
#define VENDOR_ID 0xfccf
#define PRODUCT_ID 0xa001
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
7
|
|
8fc8e350
henyxia
USB Initializatio...
|
8
|
bool initUI(void)
|
a0ae785b
Jean Wasilewski
Non working version
|
9
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
10
|
int ret;
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
11
|
|
8fc8e350
henyxia
USB Initializatio...
|
12
13
14
15
|
libusb_device_handle* screenHandle;
ret = libusb_init(NULL);
if(ret != 0)
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
16
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
17
18
|
printf("Error while initializing libusb, return : %d\n", ret);
return false;
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
19
20
|
}
|
8fc8e350
henyxia
USB Initializatio...
|
21
22
23
|
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
|
24
|
|
8fc8e350
henyxia
USB Initializatio...
|
25
|
struct libusb_device_descriptor dDevice;
|
155f7ac1
Jean Wasilewski
Some BMP recognition
|
26
|
|
8fc8e350
henyxia
USB Initializatio...
|
27
28
29
30
|
printf("Starting lsusb things\n");
if(cnt < 0)
|
262d40e6
Jean Wasilewski
Working version b...
|
31
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
32
33
|
printf("Unable to get USB device list\n");
return false;
|
10b7eef7
henyxia
Separated color a...
|
34
35
|
}
|
8fc8e350
henyxia
USB Initializatio...
|
36
37
|
printf("%d devices detected\n", cnt);
printf("List of compatible devices detected\n");
|
10b7eef7
henyxia
Separated color a...
|
38
|
|
8fc8e350
henyxia
USB Initializatio...
|
39
|
for (int i = 0; i < cnt; i++)
|
10b7eef7
henyxia
Separated color a...
|
40
|
{
|
8fc8e350
henyxia
USB Initializatio...
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
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...
|
56
|
}
|
4daa2ca3
Jean Wasilewski
Displaying a pixe...
|
57
|
|
8fc8e350
henyxia
USB Initializatio...
|
58
|
libusb_free_device_list(list, 1);
|
262d40e6
Jean Wasilewski
Working version b...
|
59
|
|
8fc8e350
henyxia
USB Initializatio...
|
60
61
62
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
|
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...
|
93
|
|
8fc8e350
henyxia
USB Initializatio...
|
94
95
|
return true;
}
|
262d40e6
Jean Wasilewski
Working version b...
|
96
|
|
8fc8e350
henyxia
USB Initializatio...
|
97
98
99
100
|
int main(void)
{
if(!initUI())
printf("Unable to initialize the UI\n");
|
262d40e6
Jean Wasilewski
Working version b...
|
101
|
|
8fc8e350
henyxia
USB Initializatio...
|
102
|
return 0;
|
262d40e6
Jean Wasilewski
Working version b...
|
103
|
}
|