From cf8950d2cbeaf0dd9dd3c10a04029af421f98b45 Mon Sep 17 00:00:00 2001 From: rguillom Date: Mon, 20 Jan 2020 23:16:16 +0100 Subject: [PATCH] suppression magic numbers --- Pgm PC/init_USB.c | 17 +++++++++-------- lufa-master/PolytechLille/PAD/PAD.c | 7 ++++--- main.c | 16 +++++++++------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Pgm PC/init_USB.c b/Pgm PC/init_USB.c index 4bbf169..d65131a 100644 --- a/Pgm PC/init_USB.c +++ b/Pgm PC/init_USB.c @@ -3,9 +3,9 @@ #include /* Caractéristiques du périphérique */ -#define VENDOR_ID 0x2341 -#define PRODUCT_ID 0x0001 -#define TAB_PA_SIZE 10 +#define VENDOR_ID 0x2341 +#define PRODUCT_ID 0x0001 +#define TAB_PA_SIZE 10 libusb_device_handle *handle=NULL; libusb_device *device=NULL; @@ -182,7 +182,7 @@ void receive_data(unsigned char tab_PA[TAB_PA_SIZE], unsigned char *boutons, uns status = libusb_interrupt_transfer(handle, PA, joystick_xy, length, &transferred, timeout); if(status!=0){perror("libusb_interrupt_transfer");exit(-1);} - //TODO Pas sûr ! + if (joystick_xy !=NULL){ *joystick_x = joystick_xy[0]; //On sépare la data de chaque axe *joystick_y = joystick_xy[1]; @@ -214,7 +214,7 @@ int main(){ unsigned char boutons, boutons_anc=0xff; unsigned char joystick_x, joystick_x_anc=0xff; unsigned char joystick_y, joystick_y_anc=0xff; - unsigned char caractere; + //unsigned char caractere; //TODO boucle while(pas d'arrêt), envoi et rcpt @@ -228,11 +228,12 @@ int main(){ } else { */ - //printf("début rcpt\n"); + receive_data(tab_PA, &boutons, &joystick_x, &joystick_y); //Réception des boutons et joystick - //printf("fin rcpt\n"); + + printf("Boutons : %02x, Joystick_x : %02x, Joystick_y :%02x\n", boutons, joystick_x, joystick_y); //Affichage si changement - //if ((boutons != boutons_anc) || (joystick_x != joystick_x_anc) || (joystick_y != joystick_y_anc)) printf("Boutons : %02x, Joystick_x : %02x, Joystick_y :%c\n", boutons, joystick_x, joystick_y); //Affichage si changement + if ((boutons != boutons_anc) || (joystick_x != joystick_x_anc) || (joystick_y != joystick_y_anc)) printf("Boutons : %02x, Joystick_x : %02x, Joystick_y :%c\n", boutons, joystick_x, joystick_y); //Affichage si changement boutons_anc = boutons; joystick_x_anc = joystick_x; diff --git a/lufa-master/PolytechLille/PAD/PAD.c b/lufa-master/PolytechLille/PAD/PAD.c index 44d3b3f..497d728 100644 --- a/lufa-master/PolytechLille/PAD/PAD.c +++ b/lufa-master/PolytechLille/PAD/PAD.c @@ -38,9 +38,10 @@ #include "PAD.h" -#define debut_rcpt 0x40 //valeur arbitraire pour détecter un début de trame +#define debut_rcpt 0x40 //valeur arbitraire pour détecter un début de trame +#define DEBIT 9600 //débit liaison série en bauds -uint8_t boutons=0xaa; +uint8_t boutons=0xaa; //arbitraire pour test de la réception série uint8_t joystick_x=0xbb; uint8_t joystick_y=0xcc; @@ -78,7 +79,7 @@ void SetupHardware(void) /**INITIALISATIONS*/ /* Hardware Initialization */ USB_Init(); - Serial_Init(9600,0); //9600 Bauds, configuration + Serial_Init(DEBIT,0); //9600 Bauds, configuration /* Initialize Relays */ //DDRD |= ALL_RELAYS; // Port pour la liaison série diff --git a/main.c b/main.c index 74b14eb..5e5f85a 100644 --- a/main.c +++ b/main.c @@ -3,9 +3,11 @@ // For the serial port -#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz -#define tempo 25 -#define debit 9600 //débit liaison série en bauds +#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz +#define tempo 25 +#define debit 9600 //débit liaison série en bauds +#define ADC0 0 +#define ADC1 1 #define debut_serial_tx 0x40 //pour détecter la transmission d'une trame pour le 16u2 void init_serial(int speed) @@ -138,8 +140,8 @@ int main(void){ //Récupération des valeurs des boutons et joystick, et mise en forme boutons = get_buttons(); - joystick_x = get_joystick(0); - joystick_y = get_joystick(1); + joystick_x = get_joystick(ADC0); + joystick_y = get_joystick(ADC1); while(1){ boutons_anc = boutons; @@ -148,9 +150,9 @@ int main(void){ //Récupération des valeurs des boutons et joystick, et mise en forme boutons = get_buttons(); - joystick_x = get_joystick(0); + joystick_x = get_joystick(ADC0); _delay_ms(tempo); - joystick_y = get_joystick(1); + joystick_y = get_joystick(ADC1); //Port série libre if ((UCSR0A & (1<