Commit 47ec0d5e2cdba9b49496add1c4880763b4d79736
1 parent
f492428d
récupération des endpoints
Showing
3 changed files
with
42 additions
and
0 deletions
Show diff stats
include/libusb_wrapper.h
src/libusb_wrapper.c
... | ... | @@ -17,6 +17,10 @@ void usbclose(libusb_context *context) { |
17 | 17 | |
18 | 18 | void interfaceclaim(libusb_device_handle *handle, struct libusb_interface *interface){ |
19 | 19 | const struct libusb_interface_descriptor * interface_desc = &interface->altsetting[0]; //TODO enlever cette ligne, refactor |
20 | + | |
21 | + if(interface_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC)//ON PEUT VERIFIER LA CLASS | |
22 | + printf("> NOT vendor specific class\n"); | |
23 | + | |
20 | 24 | int status=libusb_claim_interface(handle, interface_desc->bInterfaceNumber); |
21 | 25 | if(status!=0){ perror("libusb_claim_interface"); exit(-1); } |
22 | 26 | } |
... | ... | @@ -270,4 +274,19 @@ void getOurInterfaces(libusb_device *device, |
270 | 274 | //variables globales |
271 | 275 | } |
272 | 276 | |
277 | +} | |
278 | + | |
279 | +char getOnlyEndpoint(struct libusb_interface * interface){ | |
280 | + | |
281 | + const struct libusb_interface_descriptor * interface_desc = &interface->altsetting[0]; | |
282 | + | |
283 | + printf("--bNumEndpoints=%d\n", interface_desc->bNumEndpoints); | |
284 | + printf("--bDescriptorType=%d\n", interface_desc->bDescriptorType); | |
285 | + | |
286 | + const struct libusb_endpoint_descriptor * endpoint_desc = &interface_desc->endpoint[0]; | |
287 | + | |
288 | + if(endpoint_desc->bmAttributes != LIBUSB_TRANSFER_TYPE_INTERRUPT)//ON PEUT VERIFIER LE TRANSFER TYPE | |
289 | + printf("> is NOT of type INTERRUPT\n"); | |
290 | + | |
291 | + return (char)endpoint_desc->bEndpointAddress; | |
273 | 292 | } |
274 | 293 | \ No newline at end of file | ... | ... |
src/main.c
... | ... | @@ -85,7 +85,28 @@ int main(int argc, char *argv[]){ |
85 | 85 | printf("-Vibrators\n"); |
86 | 86 | interfaceclaim(device_handle, int_vibrators); |
87 | 87 | |
88 | + //récupération des endpoints | |
89 | + printf("\nRécupération endpoints\n"); | |
90 | + printf("-Leds"); | |
91 | + int endpoint_leds=getOnlyEndpoint(int_leds); /* ID of endpoint (bit 8 is 0) */ | |
92 | + printf(" is %d\n", endpoint_leds); | |
93 | + printf("-Vibrators"); | |
94 | + int endpoint_vibrators=getOnlyEndpoint(int_vibrators); /* ID of endpoint (bit 8 is 0) */ | |
95 | + printf(" is %d\n", endpoint_vibrators); | |
96 | + | |
97 | + | |
88 | 98 | /*LE CODE UTILE*/ |
99 | +/* | |
100 | + char data[MAX_DATA]; // data to send or to receive | |
101 | + int size=...; // size to send or maximum size to receive | |
102 | + int timeout=...; // timeout in ms | |
103 | + | |
104 | + //OUT interrupt, from host to device | |
105 | + int bytes_out; | |
106 | + int status=libusb_interrupt_transfer(handle,endpoint_out,data,size,&bytes_out,timeout); | |
107 | + if(status!=0){ perror("libusb_interrupt_transfer"); exit(-1); } | |
108 | +*/ | |
109 | + /*FIN DU CODE UTILE*/ | |
89 | 110 | |
90 | 111 | //Close |
91 | 112 | printf("\nUnclaim interfaces ...\n"); | ... | ... |