#include //bibliothèque USB #include #include #include #include #include #define LED_ON 0x21 #define LED_OFF 0x22 #define MOVE_RIGHT 0x04 #define MOVE_LEFT 0x08 #define MOVE_STOP 0x10 #define ACM_CTRL_DTR 0x01 #define ACM_CTRL_RTS 0x02 static int ep_in_addr = 0x83; static int ep_out_addr = 0x04; libusb_device **list; libusb_device_handle *handle = NULL; libusb_device *device; void configuration_periph(libusb_device *device) //Configuration de la tourelle { //Ouverture du pepherique int status=libusb_open(device,&handle); if(status!=0) { perror("libusb_open"); exit(-1); } //Recuperation de la configuration d'indice 0 du périphérique struct libusb_config_descriptor *config; status=libusb_get_active_config_descriptor(device,&config); if(status!=0) { perror("libusb_get_active_config_descriptor"); exit(-1); } //Interfaces int i; int interface; //On détache le noyau de notre périphérique for(i=0;i<(config->bNumInterfaces);i++) { interface=config->interface[i].altsetting[0].bInterfaceNumber; if(libusb_kernel_driver_active(handle,interface)) { status=libusb_detach_kernel_driver(handle,interface); if(status!=0) { perror("libusb_detach_kernel_driver"); exit(-1); } } } //Utilisation d'une configuration du périphérique int configuration=config->bConfigurationValue; status=libusb_set_configuration(handle,configuration); if(status!=0) { perror("libusb_set_configuration"); exit(-1); } //Claim interfaces for(i=0;i<(config->bNumInterfaces);i++) { interface=config->interface[i].altsetting[0].bInterfaceNumber; printf("Numero d'interface : %d\n", interface); status=libusb_claim_interface(handle,interface); if(status!=0) { perror("libusb_claim_interface"); exit(-1); } } } void fermeture(libusb_device_handle *handle) //Fermeture du périphérique { int i, interface, status; libusb_device *device = libusb_get_device(handle); struct libusb_config_descriptor *config; status = libusb_get_active_config_descriptor(device, &config); if(status != 0) { perror("libusb_get_active_config_descriptor");exit(-1); } for(i=0;i<(config->bNumInterfaces);i++) { interface=config->interface[i].altsetting[0].bInterfaceNumber; status=libusb_release_interface(handle,interface); //On libère l'interface if(status!=0) { perror("libusb_release_interface"); exit(-1); } printf("Interface liberee : %d\n",interface); } libusb_close(handle); } void enumeration(libusb_context *context) //Enumération des périphériques USB { int t=0; libusb_device **list; ssize_t count=libusb_get_device_list(context,&list); if(count<0) { perror("libusb_get_device_list"); exit(-1); } ssize_t i=0; for(i=0;i