b24d2980
achemin1
Nettoyage du code...
|
1
|
#include "libusb_wrapper.h"
|
d6e16d2e
achemin1
Tout propre
|
2
|
#include <stdio.h>
|
4d621b43
achemin1
ajout interface d...
|
3
|
#include <string.h>
|
b24d2980
achemin1
Nettoyage du code...
|
4
|
|
f6896773
achemin1
Prise en charge d...
|
5
|
int main(int argc, char *argv[]){
|
d6e16d2e
achemin1
Tout propre
|
6
|
printf("Hello World :-|\n");
|
b24d2980
achemin1
Nettoyage du code...
|
7
|
|
d6e16d2e
achemin1
Tout propre
|
8
|
libusb_context *context;
|
f6896773
achemin1
Prise en charge d...
|
9
|
usbinit(&context);
|
7e2160f8
achemin1
Ajout du mode debug
|
10
11
12
|
#ifdef DEBUG
libusb_set_option(context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
#endif
|
b24d2980
achemin1
Nettoyage du code...
|
13
|
|
f6896773
achemin1
Prise en charge d...
|
14
15
16
17
18
19
|
if(argc>1){
//command mode
if(strcmp(argv[1], "demo4.1") == 0) { //if 4.1
printf("\e[91mDemo 4.1\e[39m\n");
displayDevices(context);
}
|
72cd0d89
achemin1
(RĂ©)Ajout 4.1 bonus
|
20
21
22
23
|
else if(strcmp(argv[1], "demo4.1plus") == 0) { //if 4.1 bonus
printf("\e[91mDemo 4.1\e[39m\n");
displayDevicesMore(context);
}
|
f6896773
achemin1
Prise en charge d...
|
24
25
|
else if(strcmp(argv[1], "demo4.2") == 0){//if 4.2
printf("\e[91mDemo 4.2\e[39m\n");
|
4d621b43
achemin1
ajout interface d...
|
26
27
28
29
30
31
32
33
34
35
36
|
if(argc > 3){
uint16_t vendor_id;
uint16_t product_id;
sscanf(argv[2], "%hu", &vendor_id);
sscanf(argv[3], "%hu", &product_id);
libusb_device_handle* handle;
handle = libusb_open_device_with_vid_pid(context, vendor_id, product_id);
if(handle != NULL){
printf("Show endpoints of VID:%hu;PID:%hu\n", vendor_id, product_id);
|
f8fc88aa
gperson
avancement juste ...
|
37
|
displayDeviceEndpoints(handle);
|
4d621b43
achemin1
ajout interface d...
|
38
39
40
41
42
43
44
|
}
else{
printf("Error while getting handle of VID:%hu;PID:%hu\n", vendor_id, product_id);
}
}else{
printf("Error, need VID and PID\n");
}
|
f6896773
achemin1
Prise en charge d...
|
45
46
47
48
49
50
51
52
53
54
55
56
|
}else{
printf("Wrong command\n");
}
}else{
//interactive mode
printf("Welcome to interactive mode\n");
/*Future code*/
printf("Finished\n");
}
|
b24d2980
achemin1
Nettoyage du code...
|
57
|
|
b24d2980
achemin1
Nettoyage du code...
|
58
|
|
d6e16d2e
achemin1
Tout propre
|
59
|
usbclose(context);
|
b24d2980
achemin1
Nettoyage du code...
|
60
61
62
|
return 0;
}
|