AresENSEA-CDF2020
/
AresCDFMainCode_capteur_US
Capteur_US
debug.cpp@1:2fe8c402ee79, 2020-07-08 (annotated)
- Committer:
- Nanaud
- Date:
- Wed Jul 08 20:42:19 2020 +0000
- Revision:
- 1:2fe8c402ee79
- Parent:
- 0:dc036b67c87c
- Child:
- 2:094c09903a9c
Amelioration de la lisibilite du code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nanaud | 1:2fe8c402ee79 | 1 | // Nom du fichier : debug.cpp |
Nanaud | 0:dc036b67c87c | 2 | #include "pins.h" |
Nanaud | 0:dc036b67c87c | 3 | |
Nanaud | 1:2fe8c402ee79 | 4 | // Variables globales & timerse |
Nanaud | 1:2fe8c402ee79 | 5 | Serial pc(USBTX, USBRX); |
Nanaud | 1:2fe8c402ee79 | 6 | Ticker ticker_affUS; |
Nanaud | 1:2fe8c402ee79 | 7 | Ticker ticker_affcd; |
Nanaud | 1:2fe8c402ee79 | 8 | bool aff_US[6]; |
Nanaud | 1:2fe8c402ee79 | 9 | bool aff_cd[4]; |
Nanaud | 1:2fe8c402ee79 | 10 | |
Nanaud | 0:dc036b67c87c | 11 | void serialIT(){ |
Nanaud | 0:dc036b67c87c | 12 | //pc.printf("\n\rserialIT on\n\r"); |
Nanaud | 0:dc036b67c87c | 13 | static int i=0; |
Nanaud | 0:dc036b67c87c | 14 | static char buffer[10]=""; // Tableau qui contient la chaine de caractère rentrée dans le terminal. |
Nanaud | 0:dc036b67c87c | 15 | static char cmd[Lcmd]=""; // Variable qui retient que les premiers caractères qui représentent la commande. |
Nanaud | 0:dc036b67c87c | 16 | char tampon = pc.getc(); |
Nanaud | 0:dc036b67c87c | 17 | |
Nanaud | 0:dc036b67c87c | 18 | if((tampon >= 48 && tampon <=57) || (tampon>=97 && tampon<=122) || tampon==13) |
Nanaud | 0:dc036b67c87c | 19 | { |
Nanaud | 0:dc036b67c87c | 20 | buffer[i]=tampon; // Ajout du caractère dans le tableau buffer |
Nanaud | 0:dc036b67c87c | 21 | pc.putc(buffer[i]); // Réécriture sur le terminal du caractère envoyé |
Nanaud | 0:dc036b67c87c | 22 | i++; |
Nanaud | 0:dc036b67c87c | 23 | } |
Nanaud | 0:dc036b67c87c | 24 | |
Nanaud | 0:dc036b67c87c | 25 | if(buffer[i-1]=='\r'){ // Attente un appui sur la touche entrée |
Nanaud | 0:dc036b67c87c | 26 | i=0; |
Nanaud | 0:dc036b67c87c | 27 | copieTab(buffer,cmd); // Sauvegarde la commande dans le tableau cmd |
Nanaud | 0:dc036b67c87c | 28 | cmdChoice(cmd); |
Nanaud | 0:dc036b67c87c | 29 | } |
Nanaud | 0:dc036b67c87c | 30 | } |
Nanaud | 0:dc036b67c87c | 31 | |
Nanaud | 0:dc036b67c87c | 32 | void copieTab(char *tab1,char *tab2){ // Fonction qui recopie un tableau dans un autre |
Nanaud | 0:dc036b67c87c | 33 | //pc.printf("\n\rcopieTab on\n\r"); |
Nanaud | 0:dc036b67c87c | 34 | //pc.printf("\n\r"); |
Nanaud | 0:dc036b67c87c | 35 | for(int j=0;j<Lcmd;j++){ |
Nanaud | 0:dc036b67c87c | 36 | tab2[j]=tab1[j]; |
Nanaud | 0:dc036b67c87c | 37 | //pc.printf("%c",tab2[j]); |
Nanaud | 0:dc036b67c87c | 38 | } |
Nanaud | 0:dc036b67c87c | 39 | //pc.printf("\n\r"); |
Nanaud | 0:dc036b67c87c | 40 | } |
Nanaud | 0:dc036b67c87c | 41 | |
Nanaud | 0:dc036b67c87c | 42 | void cmdChoice(char *cmd){ // Fonction qui permet de choisir de l'activation d'une commande |
Nanaud | 0:dc036b67c87c | 43 | //pc.printf("\n\rcmdChoice on\n\rcmd ="); |
Nanaud | 0:dc036b67c87c | 44 | |
Nanaud | 0:dc036b67c87c | 45 | const char *options[]={ |
Nanaud | 0:dc036b67c87c | 46 | "help", //0 |
Nanaud | 0:dc036b67c87c | 47 | "usao", //1 |
Nanaud | 0:dc036b67c87c | 48 | "us1o", //2 |
Nanaud | 0:dc036b67c87c | 49 | "us2o", //3 |
Nanaud | 0:dc036b67c87c | 50 | "us3o", //4 |
Nanaud | 0:dc036b67c87c | 51 | "us4o", //5 |
Nanaud | 0:dc036b67c87c | 52 | "us5o", //6 |
Nanaud | 0:dc036b67c87c | 53 | "us6o", //7 |
Nanaud | 0:dc036b67c87c | 54 | "tdrv", //8 |
Nanaud | 0:dc036b67c87c | 55 | "cdon", //9 |
Nanaud | 0:dc036b67c87c | 56 | "cdga", //10 |
Nanaud | 0:dc036b67c87c | 57 | "cdgb", //11 |
Nanaud | 0:dc036b67c87c | 58 | 0 |
Nanaud | 0:dc036b67c87c | 59 | }; |
Nanaud | 0:dc036b67c87c | 60 | |
Nanaud | 0:dc036b67c87c | 61 | long option=-1; |
Nanaud | 0:dc036b67c87c | 62 | |
Nanaud | 0:dc036b67c87c | 63 | for (long a=0; options[a] && option<0; a++){ |
Nanaud | 0:dc036b67c87c | 64 | if (!strcmp(cmd,options[a]) || strcmp(cmd,options[a])==1){ // strcmp(cmd,options[a])==1 permet de contourner le problème, à revoir !!! |
Nanaud | 0:dc036b67c87c | 65 | option=a; |
Nanaud | 0:dc036b67c87c | 66 | } |
Nanaud | 0:dc036b67c87c | 67 | //pc.printf("res = %d",strcmp(cmd,options[a])); |
Nanaud | 0:dc036b67c87c | 68 | } |
Nanaud | 0:dc036b67c87c | 69 | |
Nanaud | 0:dc036b67c87c | 70 | switch (option) { |
Nanaud | 0:dc036b67c87c | 71 | case 0: //help |
Nanaud | 0:dc036b67c87c | 72 | pc.printf("\n\n\r###HELP###\n\r"); |
Nanaud | 0:dc036b67c87c | 73 | pc.printf("usao : Affichage resultats capteurs a ultrasons\n\r"); |
Nanaud | 0:dc036b67c87c | 74 | pc.printf("usxo : Affichage resultat capteur ultrasons x\n\r"); |
Nanaud | 0:dc036b67c87c | 75 | pc.printf("tdrv : Lance la fonction test_drv()\n\r"); |
Nanaud | 0:dc036b67c87c | 76 | pc.printf("cdon : Affichage resultats codeurs\n\r"); |
Nanaud | 0:dc036b67c87c | 77 | pc.printf("cdgx : Affichage resultats codeur gauche phase x (a ou b)\n\r"); |
Nanaud | 0:dc036b67c87c | 78 | pc.printf("\n\r"); |
Nanaud | 0:dc036b67c87c | 79 | break; |
Nanaud | 0:dc036b67c87c | 80 | case 1: //usao |
Nanaud | 0:dc036b67c87c | 81 | pc.printf("Capt US ALL ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 82 | aff_US[0]=!aff_US[0];aff_US[1]=!aff_US[1];aff_US[2]=!aff_US[2]; |
Nanaud | 0:dc036b67c87c | 83 | aff_US[3]=!aff_US[3];aff_US[4]=!aff_US[4];aff_US[5]=!aff_US[5]; |
Nanaud | 0:dc036b67c87c | 84 | break; |
Nanaud | 0:dc036b67c87c | 85 | case 2: //us1o |
Nanaud | 0:dc036b67c87c | 86 | pc.printf("Capt US 1 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 87 | aff_US[0]=!aff_US[0]; |
Nanaud | 0:dc036b67c87c | 88 | break; |
Nanaud | 0:dc036b67c87c | 89 | case 3: //us2o |
Nanaud | 0:dc036b67c87c | 90 | pc.printf("Capt US 2 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 91 | aff_US[1]=!aff_US[1]; |
Nanaud | 0:dc036b67c87c | 92 | break; |
Nanaud | 0:dc036b67c87c | 93 | case 4: //us3o |
Nanaud | 0:dc036b67c87c | 94 | pc.printf("Capt US 3 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 95 | aff_US[2]=!aff_US[2]; |
Nanaud | 0:dc036b67c87c | 96 | break; |
Nanaud | 0:dc036b67c87c | 97 | case 5: //us4o |
Nanaud | 0:dc036b67c87c | 98 | pc.printf("Capt US 4 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 99 | aff_US[3]=!aff_US[3]; |
Nanaud | 0:dc036b67c87c | 100 | break; |
Nanaud | 0:dc036b67c87c | 101 | case 6: //us5o |
Nanaud | 0:dc036b67c87c | 102 | pc.printf("Capt US 5 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 103 | aff_US[4]=!aff_US[4]; |
Nanaud | 0:dc036b67c87c | 104 | break; |
Nanaud | 0:dc036b67c87c | 105 | case 7: //us6o |
Nanaud | 0:dc036b67c87c | 106 | pc.printf("Capt US 6 ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 107 | aff_US[5]=!aff_US[5]; |
Nanaud | 0:dc036b67c87c | 108 | break; |
Nanaud | 0:dc036b67c87c | 109 | case 8: //tdrv |
Nanaud | 0:dc036b67c87c | 110 | pc.printf("Fonction test_drv()\n\r"); |
Nanaud | 0:dc036b67c87c | 111 | test_drv(); |
Nanaud | 0:dc036b67c87c | 112 | break; |
Nanaud | 0:dc036b67c87c | 113 | case 9: //cdon |
Nanaud | 0:dc036b67c87c | 114 | pc.printf("Results ALL Encoders ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 115 | aff_cd[0]=!aff_cd[0]; |
Nanaud | 0:dc036b67c87c | 116 | aff_cd[1]=!aff_cd[1]; |
Nanaud | 0:dc036b67c87c | 117 | break; |
Nanaud | 0:dc036b67c87c | 118 | case 10: //cdga |
Nanaud | 0:dc036b67c87c | 119 | pc.printf("Results Encoder Left A ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 120 | aff_cd[0]=!aff_cd[0]; |
Nanaud | 0:dc036b67c87c | 121 | break; |
Nanaud | 0:dc036b67c87c | 122 | case 11: //cdgb |
Nanaud | 0:dc036b67c87c | 123 | pc.printf("Results Encoder Left B ON/OFF\n\r"); |
Nanaud | 0:dc036b67c87c | 124 | aff_cd[1]=!aff_cd[1]; |
Nanaud | 0:dc036b67c87c | 125 | break; |
Nanaud | 0:dc036b67c87c | 126 | default: |
Nanaud | 0:dc036b67c87c | 127 | pc.printf("Commande invalide\n\r"); |
Nanaud | 0:dc036b67c87c | 128 | } |
Nanaud | 0:dc036b67c87c | 129 | } |
Nanaud | 0:dc036b67c87c | 130 | |
Nanaud | 0:dc036b67c87c | 131 | void affUltrasons(){ |
Nanaud | 0:dc036b67c87c | 132 | if(aff_US[0]) printf("Tps US1 = %5.0f uS\n\r", us_out[0]); |
Nanaud | 0:dc036b67c87c | 133 | if(aff_US[1]) printf("Tps US2 = %5.0f uS\n\r", us_out[1]); |
Nanaud | 0:dc036b67c87c | 134 | if(aff_US[2]) printf("Tps US3 = %5.0f uS\n\r", us_out[2]); |
Nanaud | 0:dc036b67c87c | 135 | if(aff_US[3]) printf("Tps US4 = %5.0f uS\n\r", us_out[3]); |
Nanaud | 0:dc036b67c87c | 136 | if(aff_US[4]) printf("Tps US5 = %5.0f uS\n\r", us_out[4]); |
Nanaud | 0:dc036b67c87c | 137 | if(aff_US[5]) printf("Tps US6 = %5.0f uS\n\r", us_out[5]); |
Nanaud | 0:dc036b67c87c | 138 | if(aff_US[0]||aff_US[1]||aff_US[2]||aff_US[3]||aff_US[4]||aff_US[5]) printf("\n\r"); |
Nanaud | 0:dc036b67c87c | 139 | } |
Nanaud | 0:dc036b67c87c | 140 | |
Nanaud | 0:dc036b67c87c | 141 | void affCodeurs(){ |
Nanaud | 0:dc036b67c87c | 142 | if(aff_cd[0]) printf("CdgA = %d\n\r", cpt_cdgA); |
Nanaud | 0:dc036b67c87c | 143 | if(aff_cd[1]) printf("CdgB = %d\n\r", cpt_cdgB); |
Nanaud | 0:dc036b67c87c | 144 | } |
Nanaud | 0:dc036b67c87c | 145 |