Max Bismuth
/
MX28-Scan3D_DB03-IRQ
Scan Mines
Fork of MX28-Scan3D_DB03-IRQ by
main.cpp@0:129e8567ddbd, 2015-05-17 (annotated)
- Committer:
- dbrousse
- Date:
- Sun May 17 17:29:44 2015 +0000
- Revision:
- 0:129e8567ddbd
- Child:
- 1:538b13cb6699
Modification pour 3 sorties Neopixels
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dbrousse | 0:129e8567ddbd | 1 | /************************************ |
dbrousse | 0:129e8567ddbd | 2 | * DB le 12/05/2015 MX28-Scan3D_DB03-IRQ |
dbrousse | 0:129e8567ddbd | 3 | * Pilotage MX-28 MX-106 avec liaison série : Trame Scan3D |
dbrousse | 0:129e8567ddbd | 4 | * &abcdefghij/ début $, fin /, longueur variable |
dbrousse | 0:129e8567ddbd | 5 | * à partir de prog pour Trame VoiceTronics2015 |
dbrousse | 0:129e8567ddbd | 6 | * Réception Série par IRQ |
dbrousse | 0:129e8567ddbd | 7 | * Piloter les positions des 2 servomoteurs V et H |
dbrousse | 0:129e8567ddbd | 8 | * Débit = 57142bit/s |
dbrousse | 0:129e8567ddbd | 9 | * |
dbrousse | 0:129e8567ddbd | 10 | * Particularité Matrice Led Neopixels |
dbrousse | 0:129e8567ddbd | 11 | * Une seule instance possible avec la classe NeoStrip : |
dbrousse | 0:129e8567ddbd | 12 | * Problème, pour nous il faut 3 voies : panelLed1, panelLed2 et panelLed3 ! |
dbrousse | 0:129e8567ddbd | 13 | * les 2 autres voies "faite à la main" avec les fonctions : |
dbrousse | 0:129e8567ddbd | 14 | * - void writeBitCode1(numMatriceLed) et void writeBitCode0(numMatriceLed) |
dbrousse | 0:129e8567ddbd | 15 | * - void writeMatriceLed(int numMatriceLed, int N, int valRouge, int valVerte, int valBleu) |
dbrousse | 0:129e8567ddbd | 16 | * |
dbrousse | 0:129e8567ddbd | 17 | * Cible : Carte mbed_S3DHQ_2015 |
dbrousse | 0:129e8567ddbd | 18 | *************************************/ |
dbrousse | 0:129e8567ddbd | 19 | |
dbrousse | 0:129e8567ddbd | 20 | #include "mbed.h" |
dbrousse | 0:129e8567ddbd | 21 | #include "MX-28_DefConstantes.h" |
dbrousse | 0:129e8567ddbd | 22 | #include "NeoStrip.h" |
dbrousse | 0:129e8567ddbd | 23 | |
dbrousse | 0:129e8567ddbd | 24 | #define ID_SERVO_VERTICAL 2 // MX-106R |
dbrousse | 0:129e8567ddbd | 25 | #define ID_SERVO_HORIZONTALE 3 // MX-28R |
dbrousse | 0:129e8567ddbd | 26 | |
dbrousse | 0:129e8567ddbd | 27 | #define N1 64 // Nombre de pixels(Led) du panneau Led 1 |
dbrousse | 0:129e8567ddbd | 28 | #define N2 64 // Nombre de pixels(Led) du panneau Led 2 |
dbrousse | 0:129e8567ddbd | 29 | #define N3 64 // Nombre de pixels(Led) du panneau Led 3 |
dbrousse | 0:129e8567ddbd | 30 | |
dbrousse | 0:129e8567ddbd | 31 | DigitalOut led01(LED1); |
dbrousse | 0:129e8567ddbd | 32 | DigitalOut led02(LED2); |
dbrousse | 0:129e8567ddbd | 33 | DigitalOut led03(LED3); |
dbrousse | 0:129e8567ddbd | 34 | DigitalOut led04(LED4); |
dbrousse | 0:129e8567ddbd | 35 | |
dbrousse | 0:129e8567ddbd | 36 | DigitalOut dir(p17); |
dbrousse | 0:129e8567ddbd | 37 | DigitalOut laser(p5); |
dbrousse | 0:129e8567ddbd | 38 | DigitalOut panelLed2(p7); |
dbrousse | 0:129e8567ddbd | 39 | DigitalOut panelLed3(p8); |
dbrousse | 0:129e8567ddbd | 40 | |
dbrousse | 0:129e8567ddbd | 41 | unsigned char numeroOctetRecu=0; |
dbrousse | 0:129e8567ddbd | 42 | char octetRecu; //premier octet reçu |
dbrousse | 0:129e8567ddbd | 43 | char bufferRec[12]; // buffer de réception serialPc |
dbrousse | 0:129e8567ddbd | 44 | |
dbrousse | 0:129e8567ddbd | 45 | Serial serialPc(USBTX, USBRX); // tx, rx, écarté car driver incompatible avec LabVIEW |
dbrousse | 0:129e8567ddbd | 46 | //Serial serialPc(p28, p27); // tx, rx (c'est l'uart2 du LPC1768) |
dbrousse | 0:129e8567ddbd | 47 | //Serial uartMX28(p13, p14); // tx, rx pour MX28 (uart1 du LPC1768) |
dbrousse | 0:129e8567ddbd | 48 | Serial uartMX28(p28, p27); // tx, rx pour MX28 (uart1 du LPC1768) |
dbrousse | 0:129e8567ddbd | 49 | |
dbrousse | 0:129e8567ddbd | 50 | NeoStrip panelLed1(p6, N1); // creation de l'objet panelLed1 cde par p6, N1 Led |
dbrousse | 0:129e8567ddbd | 51 | //NeoStrip panelLed2(p7, N2); // creation de l'objet panelLed2 cde par p7, N2 Led |
dbrousse | 0:129e8567ddbd | 52 | //NeoStrip panelLed3(p8, N3); // creation de l'objet panelLed3 cde par p8, N3 Led |
dbrousse | 0:129e8567ddbd | 53 | |
dbrousse | 0:129e8567ddbd | 54 | //------------------------------------------------------------------------------------------------ |
dbrousse | 0:129e8567ddbd | 55 | // Envoi de la trame de pilotage a un servomoteur MX-28 |
dbrousse | 0:129e8567ddbd | 56 | void write (char id, char longueurTrame, char instruction, char param1 = NULL, char param2 = NULL, char param3 = NULL, char param4 = NULL) |
dbrousse | 0:129e8567ddbd | 57 | { |
dbrousse | 0:129e8567ddbd | 58 | char Cks; |
dbrousse | 0:129e8567ddbd | 59 | |
dbrousse | 0:129e8567ddbd | 60 | Cks = ~( id + longueurTrame + instruction + param1 + param2 + param3 + param4); //calcul du checkSum |
dbrousse | 0:129e8567ddbd | 61 | //serialPc.printf("Cks : %d\n", Cks); |
dbrousse | 0:129e8567ddbd | 62 | dir = 1; |
dbrousse | 0:129e8567ddbd | 63 | uartMX28.putc(0xFF); |
dbrousse | 0:129e8567ddbd | 64 | uartMX28.putc(0xFF); |
dbrousse | 0:129e8567ddbd | 65 | uartMX28.putc(id); |
dbrousse | 0:129e8567ddbd | 66 | uartMX28.putc(longueurTrame); |
dbrousse | 0:129e8567ddbd | 67 | uartMX28.putc(instruction); |
dbrousse | 0:129e8567ddbd | 68 | if (longueurTrame >= 3) { |
dbrousse | 0:129e8567ddbd | 69 | uartMX28.putc(param1); |
dbrousse | 0:129e8567ddbd | 70 | } |
dbrousse | 0:129e8567ddbd | 71 | if (longueurTrame >= 4) { |
dbrousse | 0:129e8567ddbd | 72 | uartMX28.putc(param2); |
dbrousse | 0:129e8567ddbd | 73 | } |
dbrousse | 0:129e8567ddbd | 74 | if (longueurTrame >= 5) { |
dbrousse | 0:129e8567ddbd | 75 | uartMX28.putc(param3); |
dbrousse | 0:129e8567ddbd | 76 | } |
dbrousse | 0:129e8567ddbd | 77 | if (longueurTrame >= 6) { |
dbrousse | 0:129e8567ddbd | 78 | uartMX28.putc(param4); |
dbrousse | 0:129e8567ddbd | 79 | } |
dbrousse | 0:129e8567ddbd | 80 | uartMX28.putc(Cks); |
dbrousse | 0:129e8567ddbd | 81 | |
dbrousse | 0:129e8567ddbd | 82 | wait_us(MX28_WAIT_AFTER_WRITE); // Attendre l'envoie complet de la trame. |
dbrousse | 0:129e8567ddbd | 83 | dir = 0; |
dbrousse | 0:129e8567ddbd | 84 | } |
dbrousse | 0:129e8567ddbd | 85 | |
dbrousse | 0:129e8567ddbd | 86 | // Set goal position of engine |
dbrousse | 0:129e8567ddbd | 87 | void setPosition(char id, int goal) |
dbrousse | 0:129e8567ddbd | 88 | { |
dbrousse | 0:129e8567ddbd | 89 | char goal_h = goal >> 8; |
dbrousse | 0:129e8567ddbd | 90 | char goal_l = goal; |
dbrousse | 0:129e8567ddbd | 91 | //serialPc.printf("Goal set : %d %d %d\n", goal, goal_h, goal_l); |
dbrousse | 0:129e8567ddbd | 92 | write(id, 5, MX28_WRITE_DATA, MX28_GOAL_POSITION_L, goal_l, goal_h); |
dbrousse | 0:129e8567ddbd | 93 | } |
dbrousse | 0:129e8567ddbd | 94 | |
dbrousse | 0:129e8567ddbd | 95 | //--------------------------------------------------------------------------------------------- |
dbrousse | 0:129e8567ddbd | 96 | // fonction écriture Bit code 1 et 0 pour matrice Led Neopixels |
dbrousse | 0:129e8567ddbd | 97 | void writeBitCode1(int numMatriceLed) |
dbrousse | 0:129e8567ddbd | 98 | { |
dbrousse | 0:129e8567ddbd | 99 | if(numMatriceLed==2){panelLed2=1;} |
dbrousse | 0:129e8567ddbd | 100 | else{panelLed3=1;} |
dbrousse | 0:129e8567ddbd | 101 | for(int i=0;i<37;i++) {int x = i*i*i; x=x*x;} // pour T1H=700ns |
dbrousse | 0:129e8567ddbd | 102 | if(numMatriceLed==2){panelLed2=0;} |
dbrousse | 0:129e8567ddbd | 103 | else{panelLed3=0;} |
dbrousse | 0:129e8567ddbd | 104 | for(int i=0;i<16;i++) {int x = i*i*i; x=x*x;} // pour T1L= 450ns + 150ns pour exe fonction |
dbrousse | 0:129e8567ddbd | 105 | } |
dbrousse | 0:129e8567ddbd | 106 | void writeBitCode0(int numMatriceLed) |
dbrousse | 0:129e8567ddbd | 107 | { |
dbrousse | 0:129e8567ddbd | 108 | if(numMatriceLed==2){panelLed2=1;} |
dbrousse | 0:129e8567ddbd | 109 | else{panelLed3=1;} |
dbrousse | 0:129e8567ddbd | 110 | for(int i=0;i<15;i++) {int x = i*i*i; x=x*x;} // pour T0H=350ns |
dbrousse | 0:129e8567ddbd | 111 | if(numMatriceLed==2){panelLed2=0;} |
dbrousse | 0:129e8567ddbd | 112 | else{panelLed3=0;} |
dbrousse | 0:129e8567ddbd | 113 | for(int i=0;i<32;i++) {int x = i*i*i; x=x*x;} // pour T0L=650ns+150ns pour exe fonction |
dbrousse | 0:129e8567ddbd | 114 | } |
dbrousse | 0:129e8567ddbd | 115 | //--------------------------------------------------------------------------------------------- |
dbrousse | 0:129e8567ddbd | 116 | // fonction écriture matrice Led Neopixels |
dbrousse | 0:129e8567ddbd | 117 | void writeMatriceLed(int numMatriceLed, int N, int valRouge, int valVerte, int valBleu) |
dbrousse | 0:129e8567ddbd | 118 | { |
dbrousse | 0:129e8567ddbd | 119 | int valeurCouleurVRB = valVerte*65536+valRouge*256+valBleu; |
dbrousse | 0:129e8567ddbd | 120 | for(int i=0;i<N;i++) { |
dbrousse | 0:129e8567ddbd | 121 | int mask_1sur24Bits = 0x800000; |
dbrousse | 0:129e8567ddbd | 122 | for(int j=0;j<24;j++) { |
dbrousse | 0:129e8567ddbd | 123 | if(valeurCouleurVRB & mask_1sur24Bits) { |
dbrousse | 0:129e8567ddbd | 124 | writeBitCode1(numMatriceLed); |
dbrousse | 0:129e8567ddbd | 125 | } |
dbrousse | 0:129e8567ddbd | 126 | else { |
dbrousse | 0:129e8567ddbd | 127 | writeBitCode0(numMatriceLed); |
dbrousse | 0:129e8567ddbd | 128 | } |
dbrousse | 0:129e8567ddbd | 129 | mask_1sur24Bits = mask_1sur24Bits >> 1; |
dbrousse | 0:129e8567ddbd | 130 | } |
dbrousse | 0:129e8567ddbd | 131 | } |
dbrousse | 0:129e8567ddbd | 132 | } |
dbrousse | 0:129e8567ddbd | 133 | |
dbrousse | 0:129e8567ddbd | 134 | |
dbrousse | 0:129e8567ddbd | 135 | //--------------------------------------------------------------------------------------------- |
dbrousse | 0:129e8567ddbd | 136 | // fonction appelée par interruption si réception sur serialPc |
dbrousse | 0:129e8567ddbd | 137 | void receptionPc() |
dbrousse | 0:129e8567ddbd | 138 | { |
dbrousse | 0:129e8567ddbd | 139 | led04 =1; |
dbrousse | 0:129e8567ddbd | 140 | octetRecu = serialPc.getc(); |
dbrousse | 0:129e8567ddbd | 141 | if(octetRecu == '$') { |
dbrousse | 0:129e8567ddbd | 142 | numeroOctetRecu = 0; |
dbrousse | 0:129e8567ddbd | 143 | memset(&bufferRec[0], 0, sizeof(bufferRec)); |
dbrousse | 0:129e8567ddbd | 144 | } else { |
dbrousse | 0:129e8567ddbd | 145 | bufferRec[numeroOctetRecu-1] = octetRecu; |
dbrousse | 0:129e8567ddbd | 146 | ///Debug serialPc.printf("%c",octetRecu); //////// |
dbrousse | 0:129e8567ddbd | 147 | } |
dbrousse | 0:129e8567ddbd | 148 | if(octetRecu == '/') { |
dbrousse | 0:129e8567ddbd | 149 | if ((bufferRec[0] == '0')&&(numeroOctetRecu == 8)) { // si c'est une commande de position MX28+MX106 |
dbrousse | 0:129e8567ddbd | 150 | int b = bufferRec[1] - 0x30; |
dbrousse | 0:129e8567ddbd | 151 | int c = bufferRec[2] - 0x30; |
dbrousse | 0:129e8567ddbd | 152 | int d = bufferRec[3] - 0x30; |
dbrousse | 0:129e8567ddbd | 153 | int e = bufferRec[4] - 0x30; |
dbrousse | 0:129e8567ddbd | 154 | int f = bufferRec[5] - 0x30; |
dbrousse | 0:129e8567ddbd | 155 | int g = bufferRec[6] - 0x30; |
dbrousse | 0:129e8567ddbd | 156 | int anglePositionVerticale = (b * 100) + (c * 10) + d; |
dbrousse | 0:129e8567ddbd | 157 | int valeurPositionVerticale = anglePositionVerticale * 4095 / 360; |
dbrousse | 0:129e8567ddbd | 158 | setPosition(ID_SERVO_VERTICAL, valeurPositionVerticale); |
dbrousse | 0:129e8567ddbd | 159 | int anglePositionHorizontale = (e * 100) + (f * 10) + g; |
dbrousse | 0:129e8567ddbd | 160 | int valeurPositionHorizontale = anglePositionHorizontale * 4095 / 360; |
dbrousse | 0:129e8567ddbd | 161 | wait_us(2000); // Attendre fin de la trame de réponse du Servo Vertical |
dbrousse | 0:129e8567ddbd | 162 | //setPosition(ID_SERVO_HORIZONTALE, valeurPositionHorizontale); |
dbrousse | 0:129e8567ddbd | 163 | //Pour Debug |
dbrousse | 0:129e8567ddbd | 164 | serialPc.printf("idServ = %d \tvaleurPosition = %d\n",ID_SERVO_VERTICAL, valeurPositionVerticale); |
dbrousse | 0:129e8567ddbd | 165 | serialPc.printf("idServ = %d \tvaleurPosition = %d\n",ID_SERVO_HORIZONTALE, valeurPositionHorizontale); |
dbrousse | 0:129e8567ddbd | 166 | } |
dbrousse | 0:129e8567ddbd | 167 | if ((bufferRec[0] == '1')&&(numeroOctetRecu == 2)) { // si demande de lecture de la position |
dbrousse | 0:129e8567ddbd | 168 | led03 = 1; // indic |
dbrousse | 0:129e8567ddbd | 169 | |
dbrousse | 0:129e8567ddbd | 170 | //Vider le buffer de réception uartMX28 |
dbrousse | 0:129e8567ddbd | 171 | while(uartMX28.readable()) { |
dbrousse | 0:129e8567ddbd | 172 | uartMX28.getc(); |
dbrousse | 0:129e8567ddbd | 173 | } |
dbrousse | 0:129e8567ddbd | 174 | write(ID_SERVO_VERTICAL, 4, MX28_READ_DATA, MX28_PRESENT_POSITION_L,2); |
dbrousse | 0:129e8567ddbd | 175 | char octetRecuMX[8]; |
dbrousse | 0:129e8567ddbd | 176 | char i=0; |
dbrousse | 0:129e8567ddbd | 177 | int tempoReception=0; |
dbrousse | 0:129e8567ddbd | 178 | while((tempoReception < 1000000)&&(i<8)) { |
dbrousse | 0:129e8567ddbd | 179 | if(uartMX28.readable()) { |
dbrousse | 0:129e8567ddbd | 180 | octetRecuMX[i] = uartMX28.getc(); |
dbrousse | 0:129e8567ddbd | 181 | i++; |
dbrousse | 0:129e8567ddbd | 182 | } |
dbrousse | 0:129e8567ddbd | 183 | tempoReception++; |
dbrousse | 0:129e8567ddbd | 184 | } |
dbrousse | 0:129e8567ddbd | 185 | /*for(int i=0;i<8;i++) { |
dbrousse | 0:129e8567ddbd | 186 | octetRecuMX[i] = uartMX28.getc(); |
dbrousse | 0:129e8567ddbd | 187 | } |
dbrousse | 0:129e8567ddbd | 188 | for(int i=0;i<8;i++) { |
dbrousse | 0:129e8567ddbd | 189 | serialPc.putc(octetRecuMX[i]); |
dbrousse | 0:129e8567ddbd | 190 | }*/ |
dbrousse | 0:129e8567ddbd | 191 | int valeurLue = octetRecuMX[6] * 256 + octetRecuMX[5]; |
dbrousse | 0:129e8567ddbd | 192 | serialPc.printf("Valeur lue %d\n",valeurLue); ///////////Pour test A modifier !!!!! |
dbrousse | 0:129e8567ddbd | 193 | wait(0.2); |
dbrousse | 0:129e8567ddbd | 194 | led03 = 0; // |
dbrousse | 0:129e8567ddbd | 195 | } |
dbrousse | 0:129e8567ddbd | 196 | if ((bufferRec[0] == '2')&&(numeroOctetRecu == 3)) { // si c'est une commande Laser |
dbrousse | 0:129e8567ddbd | 197 | if (bufferRec[1] == '1') { |
dbrousse | 0:129e8567ddbd | 198 | //Laser on |
dbrousse | 0:129e8567ddbd | 199 | led02 = 1; // indic commande Laser on |
dbrousse | 0:129e8567ddbd | 200 | laser = 1; |
dbrousse | 0:129e8567ddbd | 201 | } else { |
dbrousse | 0:129e8567ddbd | 202 | //Laser off |
dbrousse | 0:129e8567ddbd | 203 | led02 = 0; // indic commande Laser off |
dbrousse | 0:129e8567ddbd | 204 | laser = 0; |
dbrousse | 0:129e8567ddbd | 205 | } |
dbrousse | 0:129e8567ddbd | 206 | } |
dbrousse | 0:129e8567ddbd | 207 | if ((bufferRec[0] == '3')&&(numeroOctetRecu == 11)) { // si commande panneau led supérieur |
dbrousse | 0:129e8567ddbd | 208 | led03 = 1; // indic commande panneau led supérieur |
dbrousse | 0:129e8567ddbd | 209 | // A terminer |
dbrousse | 0:129e8567ddbd | 210 | int b = bufferRec[1] - 0x30; |
dbrousse | 0:129e8567ddbd | 211 | int c = bufferRec[2] - 0x30; |
dbrousse | 0:129e8567ddbd | 212 | int d = bufferRec[3] - 0x30; |
dbrousse | 0:129e8567ddbd | 213 | int e = bufferRec[4] - 0x30; |
dbrousse | 0:129e8567ddbd | 214 | int f = bufferRec[5] - 0x30; |
dbrousse | 0:129e8567ddbd | 215 | int g = bufferRec[6] - 0x30; |
dbrousse | 0:129e8567ddbd | 216 | int h = bufferRec[7] - 0x30; |
dbrousse | 0:129e8567ddbd | 217 | int i = bufferRec[8] - 0x30; |
dbrousse | 0:129e8567ddbd | 218 | int j = bufferRec[9] - 0x30; |
dbrousse | 0:129e8567ddbd | 219 | int colorLed1 = (b*100+c*10+d)*65536+(e*100+f*10+g)*256+(h*100+i*10+j); |
dbrousse | 0:129e8567ddbd | 220 | panelLed1.clear(); |
dbrousse | 0:129e8567ddbd | 221 | for(int n=0;n<N1;n++) { |
dbrousse | 0:129e8567ddbd | 222 | panelLed1.setPixel(n,colorLed1); |
dbrousse | 0:129e8567ddbd | 223 | } |
dbrousse | 0:129e8567ddbd | 224 | panelLed1.write(); |
dbrousse | 0:129e8567ddbd | 225 | |
dbrousse | 0:129e8567ddbd | 226 | wait(0.2); |
dbrousse | 0:129e8567ddbd | 227 | led03 = 0; // indic commande panneau led supérieur |
dbrousse | 0:129e8567ddbd | 228 | } |
dbrousse | 0:129e8567ddbd | 229 | if ((bufferRec[0] == '4')&&(numeroOctetRecu == 11)) { // si commande panneau led latéral 1 |
dbrousse | 0:129e8567ddbd | 230 | led03 = 1; // indic commande panneau led |
dbrousse | 0:129e8567ddbd | 231 | int b = bufferRec[1] - 0x30; |
dbrousse | 0:129e8567ddbd | 232 | int c = bufferRec[2] - 0x30; |
dbrousse | 0:129e8567ddbd | 233 | int d = bufferRec[3] - 0x30; |
dbrousse | 0:129e8567ddbd | 234 | int e = bufferRec[4] - 0x30; |
dbrousse | 0:129e8567ddbd | 235 | int f = bufferRec[5] - 0x30; |
dbrousse | 0:129e8567ddbd | 236 | int g = bufferRec[6] - 0x30; |
dbrousse | 0:129e8567ddbd | 237 | int h = bufferRec[7] - 0x30; |
dbrousse | 0:129e8567ddbd | 238 | int i = bufferRec[8] - 0x30; |
dbrousse | 0:129e8567ddbd | 239 | int j = bufferRec[9] - 0x30; |
dbrousse | 0:129e8567ddbd | 240 | int valeurRouge = (b*100+c*10+d); |
dbrousse | 0:129e8567ddbd | 241 | int valeurVerte = (e*100+f*10+g); |
dbrousse | 0:129e8567ddbd | 242 | int valeurBleu = (h*100+i*10+j); |
dbrousse | 0:129e8567ddbd | 243 | writeMatriceLed(2,N2,valeurRouge, valeurVerte, valeurBleu); |
dbrousse | 0:129e8567ddbd | 244 | wait(0.2); |
dbrousse | 0:129e8567ddbd | 245 | led03 = 0; // indic commande panneau led |
dbrousse | 0:129e8567ddbd | 246 | } |
dbrousse | 0:129e8567ddbd | 247 | if ((bufferRec[0] == '5')&&(numeroOctetRecu == 11)) { // si commande panneau led latéral 2 |
dbrousse | 0:129e8567ddbd | 248 | led03 = 1; // indic commande panneau led |
dbrousse | 0:129e8567ddbd | 249 | int b = bufferRec[1] - 0x30; |
dbrousse | 0:129e8567ddbd | 250 | int c = bufferRec[2] - 0x30; |
dbrousse | 0:129e8567ddbd | 251 | int d = bufferRec[3] - 0x30; |
dbrousse | 0:129e8567ddbd | 252 | int e = bufferRec[4] - 0x30; |
dbrousse | 0:129e8567ddbd | 253 | int f = bufferRec[5] - 0x30; |
dbrousse | 0:129e8567ddbd | 254 | int g = bufferRec[6] - 0x30; |
dbrousse | 0:129e8567ddbd | 255 | int h = bufferRec[7] - 0x30; |
dbrousse | 0:129e8567ddbd | 256 | int i = bufferRec[8] - 0x30; |
dbrousse | 0:129e8567ddbd | 257 | int j = bufferRec[9] - 0x30; |
dbrousse | 0:129e8567ddbd | 258 | int valeurRouge = (b*100+c*10+d); |
dbrousse | 0:129e8567ddbd | 259 | int valeurVerte = (e*100+f*10+g); |
dbrousse | 0:129e8567ddbd | 260 | int valeurBleu = (h*100+i*10+j); |
dbrousse | 0:129e8567ddbd | 261 | writeMatriceLed(3,N3,valeurRouge, valeurVerte, valeurBleu); |
dbrousse | 0:129e8567ddbd | 262 | wait(0.2); |
dbrousse | 0:129e8567ddbd | 263 | led03 = 0; // indic commande panneau led |
dbrousse | 0:129e8567ddbd | 264 | } |
dbrousse | 0:129e8567ddbd | 265 | if ((bufferRec[0] == '6')&&(numeroOctetRecu == 2)) { // si c'est une demande mesure accéléromètre |
dbrousse | 0:129e8567ddbd | 266 | //LECTURE ET ENVOIE des mesures d'accélérations |
dbrousse | 0:129e8567ddbd | 267 | // A Faire |
dbrousse | 0:129e8567ddbd | 268 | } |
dbrousse | 0:129e8567ddbd | 269 | |
dbrousse | 0:129e8567ddbd | 270 | numeroOctetRecu = 0; |
dbrousse | 0:129e8567ddbd | 271 | } else { |
dbrousse | 0:129e8567ddbd | 272 | numeroOctetRecu++; |
dbrousse | 0:129e8567ddbd | 273 | } |
dbrousse | 0:129e8567ddbd | 274 | led04 =0; |
dbrousse | 0:129e8567ddbd | 275 | } |
dbrousse | 0:129e8567ddbd | 276 | |
dbrousse | 0:129e8567ddbd | 277 | int main() |
dbrousse | 0:129e8567ddbd | 278 | { |
dbrousse | 0:129e8567ddbd | 279 | uartMX28.baud(57142); // débit standard pour les MX-28 et -106 |
dbrousse | 0:129e8567ddbd | 280 | serialPc.baud(115200); |
dbrousse | 0:129e8567ddbd | 281 | serialPc.attach(&receptionPc); // defini la fonction interruption |
dbrousse | 0:129e8567ddbd | 282 | panelLed1.setBrightness(1); // par défaut à 50% |
dbrousse | 0:129e8567ddbd | 283 | //serialPc.printf("Entrer une commande\n"); |
dbrousse | 0:129e8567ddbd | 284 | led01 = 1; |
dbrousse | 0:129e8567ddbd | 285 | // Clear buffer |
dbrousse | 0:129e8567ddbd | 286 | memset(&bufferRec[0], 0, sizeof(bufferRec)); |
dbrousse | 0:129e8567ddbd | 287 | |
dbrousse | 0:129e8567ddbd | 288 | while(1) { |
dbrousse | 0:129e8567ddbd | 289 | led01 = 0; |
dbrousse | 0:129e8567ddbd | 290 | wait(0.1); |
dbrousse | 0:129e8567ddbd | 291 | led01 = 1; |
dbrousse | 0:129e8567ddbd | 292 | wait(0.1); |
dbrousse | 0:129e8567ddbd | 293 | } |
dbrousse | 0:129e8567ddbd | 294 | } |