Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
essai-ds3231.cpp
00001 00002 00003 #include "mbed.h" 00004 #include <stdio.h> 00005 #include <stdlib.h> 00006 #include <string> 00007 #include "objet.h" 00008 #include "ds3231.h" 00009 00010 using namespace std; 00011 00012 //0- Definition/ Parametres/ Configuration/ Materiel 00013 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00014 string target = "STM32F303"; 00015 DigitalIn SW0(PB_5); // Digitale/ In/ SWITCH 00016 DigitalIn SW1(PA_7) ; // Digitale/ In/ SWITCH 00017 DigitalIn SW2(PB_0); // Digitale/ In/ SWITCH 00018 DigitalIn SW3(PA_8); // Digitale/ In/ SWITCH 00019 DigitalOut RXLED(PB_3); // Digitale/ Out/ lumineux/ Led Verte Intégrée 00020 DigitalOut BLED(PA_4); // Digitale/ Out/ lumineux/ Led Bleu 00021 DigitalOut GLED(PA_3); // Digitale/ Out/ lumineux/ Led Verte 00022 DigitalOut RLED(PF_1); // Digitale/ Out/ lumineux/ Led Rouge 00023 DigitalOut SOUND(PB_4); // Digitale/ Out/ Son 00024 AnalogIn padX(PA_0); //Analogique/ pad/ voie X 00025 AnalogIn padY(PA_1); //Analogique/ pad/ voie Y 00026 00027 Serial usb(USBTX, USBRX); // Liaison UART/ Dispositif USB 00028 Serial uart(PA_9, PA_10); // Liaison UART/ Dispositif UART 00029 00030 I2C i2c (PB_7, PB_6); // Liaison I2C/ Dispositif Afficheur 00031 00032 //CAN bCAN(p30, p29); // Liaison CAN/ Dispositif Communication Inter Systeme 00033 00034 00035 //1- Definition/ Constantes Programme 00036 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00037 #define vDEBUG true // Validation Mode DEBUG 00038 #define vACC false // Validation Accelero 00039 #define vSON true // Validation SON 00040 00041 // Definition/ Constantes/ Generale 00042 #define ON false 00043 #define OFF true 00044 00045 // Definition/ Constantes/ Caracteres Alphanumeriques ASCII 00046 #define LF 10 // Line Feed \n 00047 #define CR 13 // Carriage Return \r 00048 #define BS 127 // Back Space 00049 00050 //Definition/ Constantes Orientation 00051 #define bARRET 0 00052 #define bGAUCHE 1 00053 #define bDROITE 2 00054 #define bAVANT 3 00055 00056 // Definition/ Constantes KEYBOARD 00057 #define noKEY 0 // Clavier/ no KEY 00058 #define lKEY 1 // Clavier/ left KEY 00059 #define mKEY 2 // Clavier/ middle KEY 00060 #define rKEY 4 // Clavier/ right KEY 00061 #define razKEY 64 // Clavier/ az KEY 00062 00063 // Definition/ Affichage/ OLED 00064 #define oled_addr 0x78 00065 00066 00067 // Definition/ Identification/ produit 00068 #define productName "Controleur Distant/ bluetooth" 00069 #define versionName "v1.3" 00070 00071 // Definition/ Identification/ PAD 00072 #define padName "Joystick Analogique" 00073 #define padNbAxe 2 // PAD/ Nb Axe MAX 00074 #define padNbSW 3 // PAD/ Nb SW 00075 #define XAxeName "Roulis" 00076 #define YAxeName "Tangage" 00077 00078 // Definition/ Identification/ TRAME 00079 #define wdtTXMAX 100 // Watchdog Emission Trame MAX (periode) 00080 #define wdtRXMAX 1000 // Watchdog Reception Trame MAX 00081 00082 // Definition/ ADC/ Dynamique Signal 00083 #define Adcm 0 // Convertisseur ADC/ Valeur Min 00084 #define AdcM 1023 // Convertisseur ADC/ Valeur Max 00085 #define Adc0 512 // Convertisseur ADC/ Valeur Mediane 00086 00087 // Definition/ PAD/ Dynamique variable 00088 #define Dynm -1000 // Dynamique signal/ Valeur Min 00089 #define DynM 1000 // Dynamique signal/ Valeur Max 00090 #define Dyn0 0 // Dynamique signal/ Valeur Moyenne 00091 00092 // Definition/ PAD/ nombre max géré 00093 #define nbAxesMAX 2 00094 00095 // Definition/ PAD/ parametres loi de pilotage 00096 #define dzmin 0 // Dead Zone/ valeur minimale 00097 #define dzMAX 100 // Dead Zone/ valeur Maximale 00098 #define znlmin 0 // Zone Non Linearite/ valeur minimale 00099 #define znlMax 100 // Zone Non Linearite/ valeur Maximale 00100 #define ctfmin 0.05 // Kpmin: Gain min poportionnel 00101 #define ctfMAX 5 // KpMax: Gain Max poportionnel 00102 #define ctimin 0.0003 // KiMax: Gain Max integral (Constante de temps Integration Max) 00103 #define ctiMAX 0.003 // KiMax: Gain Max integral (Constante de temps Integration Max) 00104 00105 #define CtR 0.00003 // Constante de temps filtrage commande (filtre passe bas) 00106 00107 //Definition/ Constantes temporelles 00108 #define TSample 0.01 // Periode Echantillonnage Process ( 10 ms ) 00109 #define secWDTMAX 1/ TSample // Watchdog Seconde 00110 #define wledWDTMAX 30 // Watchdog MAX/ Led WIFI 00111 #define ledWDTMAX 100 // Watchdog MAX/ Led 00112 #define sonWDTMAX 500 // Watchdog MAX/ signal sonore 00113 #define imuWDTMAX 10 // Watchdog MAX/ process IMU 00114 #define trameWDTMAX 300 // Watchdog MAX/ Duree de vie de la Trame 00115 #define keyWDTMAX 50 // Watchdog MAX/ Durée de vie info touche sur trame 00116 00117 // Definition/ Constantes materiel communication 00118 #define usbBR 115200 // Communication/ port Serie/ UART USB Baut Rate 00119 #define uartBR 9600 // Communication/ port Serie/ UART Baut Rate (Bluetooth) 00120 #define i2cBR 400000 // Communication/ port Serie/ frequence bus I2C 00121 00122 // Definition/ Parametres Protocole Trame 00123 #define idNULL 0 00124 #define idMOBILE 120 00125 #define idMOBILE1 122 00126 #define idMOTOR 123 00127 #define idBALANCE 543 00128 #define idIMU 888 00129 00130 00131 //2- Definition/ Type de donnees 00132 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00133 00134 // Voir fichier: objet.h 00135 00136 00137 00138 //3- Definition/ Variables Globales 00139 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00140 00141 int16_t periode= 10; 00142 00143 int16_t wledWDT = 0; 00144 int16_t rxledWDT = 0; 00145 int16_t rledWDT = 0; 00146 int16_t gledWDT = 0; 00147 int16_t bledWDT = 0; 00148 int16_t secWDT = secWDTMAX; 00149 int16_t sonWDT = 0; 00150 int16_t sw0WDT = 0; 00151 int16_t sw1WDT = 0; 00152 int16_t sw2WDT = 0; 00153 int16_t sw3WDT = 0; 00154 int16_t sw0MASK = 0; 00155 int16_t sw1MASK = 0; 00156 int16_t sw2MASK = 0; 00157 int16_t sw3MASK = 0; 00158 int16_t sw = 0; 00159 00160 int16_t pTX = 0; 00161 int16_t pRX = 0; 00162 int16_t op[10]; 00163 bool fINPUT = true; 00164 00165 int heure = 0; 00166 int minute = 0; 00167 int seconde = 0; 00168 time_t epoch_time; 00169 00170 00171 bool fSB = false; 00172 bool fEB = false; 00173 char startB = '$'; 00174 char dlB = ','; 00175 char endB = '*'; 00176 char rx[wBUFFER]; 00177 int pcar = 0; 00178 00179 00180 int pUSBRx = 0; 00181 int pUSBTx = 0; 00182 00183 string sUSBRx = " "; 00184 00185 00186 Ds3231 rtc(PB_7, PB_6); 00187 00188 PAD_t pad; 00189 TRAME_t trame; 00190 Ticker process; 00191 00192 00193 long int nbTRM = 0; 00194 00195 00196 //4- Definition/ Macro 00197 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00198 00199 #define RX_LED_OFF RXLED = 0; 00200 #define RX_LED_ON RXLED = 1; 00201 00202 #define R_LED_OFF RLED = 1; 00203 #define R_LED_ON RLED = 0; 00204 00205 #define G_LED_OFF GLED = 1; 00206 #define G_LED_ON GLED = 0; 00207 00208 #define B_LED_OFF BLED = 1; 00209 #define B_LED_ON BLED = 0; 00210 00211 #define SON_OFF SOUND = 0; 00212 #define SON_ON SOUND = 1; 00213 00214 00215 00216 //5- Definition/ Procedures 00217 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00218 00219 //5.1- Definition/ Procedure/ Reception UART USB (interruption) 00220 void rx_usb_isr(){ 00221 char car; 00222 int count = 0; 00223 00224 car= usb.getc(); 00225 00226 switch((int)car){ 00227 00228 case 97: //Touche 'a' 00229 break; 00230 case 122: //Touche 'z' 00231 break; 00232 00233 case BS://Touche 'Back Space' 00234 if(sUSBRx.length()> 0){ 00235 sUSBRx.erase(sUSBRx.length()-1,1); 00236 while(count< sUSBRx.length()){usb.printf(" ");++count;}; 00237 usb.printf("\r%s",sUSBRx); 00238 }; 00239 break; 00240 case LF: // Touche Line Feed '\n' 00241 break; 00242 case CR: //Touche Carriage Return '\r' 00243 sUSBRx+= "\r\n"; 00244 usb.printf("\r\n"); 00245 sUSBRx= ""; 00246 break; 00247 default: //Touche Caractere ASCII 00248 sUSBRx+= car; 00249 usb.printf("%c",car); 00250 break; 00251 }; // fin switch((int)car){ 00252 00253 } 00254 00255 00256 00257 00258 //5.2- Definition/ Procedure/ Reception UART BT (interruption) 00259 void rx_uart_isr(){ 00260 // __disable_irq(); 00261 00262 char RxCar; 00263 char stB; 00264 string str; 00265 int identifier; 00266 00267 RxCar= uart.getc(); 00268 00269 // if(vDEBUG == true){ usb.printf("%c",RxCar); }; // DEBUG/ USB 00270 // bledWDT= 3; 00271 00272 if((RxCar== startB )&& (fEB== false)){pcar= 0; fSB = true; fEB= false;}; // Synchronisation Trame (Start Beacon) 00273 if(fSB== true){rx[pcar]= RxCar; ++pcar;}; 00274 if((RxCar== endB )&& (fSB== true)){fEB= true;}; 00275 if(pcar>= wBUFFER){fSB= false; fEB= false; pcar= 0;}; 00276 if((fSB== true)&& (fEB== true)){ // Synchronisation OK 00277 fSB= false; fEB= false; 00278 // usb.printf("%s\r\n", rx); 00279 00280 sscanf(rx,"%c,%i",&stB, &identifier); 00281 switch(identifier){ 00282 case idMOBILE: // Trame idMOBILE 00283 trame.wdtRX = 100; 00284 sscanf(rx,"%c,%i,%i,%i,%i,%i,%i,%c",&trame.sb, &trame.r[0], &trame.r[1], &trame.r[2], &trame.r[3], &trame.r[4], &trame.r[5], &trame.eb); // Réception Données Trame 00285 usb.printf("Rx from MOBILE : %s %s\r\n", rx, ctime(&epoch_time)); 00286 switch(trame.r[3]){ // Traitement rMODE 00287 case mSTP: // mode STOP 00288 bledWDT= 30; gledWDT= 0; rledWDT= 0; 00289 break; 00290 case mMAN: // mode MANUEL 00291 bledWDT= 0; gledWDT= 30; rledWDT= 0; 00292 break; 00293 case mPA : // mode PA 00294 bledWDT= 0; gledWDT= 0; rledWDT= 30; 00295 break; 00296 00297 default :break; 00298 }; // fin switch(trame.r[3]){ 00299 rxledWDT= 3; 00300 break; 00301 00302 default : break; 00303 }; // fin switch(identifier){ 00304 }; // fin if((fSRx== true)&& (fERx== true)){ 00305 // __enable_irq(); 00306 00307 } 00308 00309 00310 00311 //5.3- Definition/ Procedure/ Process (interruption) 00312 void process_isr(){ 00313 float aP, aI; 00314 int ctn; 00315 int8_t key; 00316 00317 // --ledWDT; if(ledWDT<= 0){ledWDT= ledWDTMAX; RX_LED_OFF; SON_OFF;}; if(ledWDT< 5){RX_LED_ON; SON_ON;}; 00318 00319 --sw0WDT; if(sw0WDT<= 0){sw0WDT= 0;}; // wdt SW0 00320 --sw1WDT; if(sw1WDT<= 0){sw1WDT= 0;}; // wdt SW1 00321 --sw2WDT; if(sw2WDT<= 0){sw2WDT= 0;}; // wdt SW2 00322 --sw3WDT; if(sw3WDT<= 0){sw3WDT= 0;}; // wdt SW3 00323 00324 --rxledWDT; if(rxledWDT<= 0){rxledWDT= 0; RX_LED_OFF;}else{RX_LED_ON;}; // wdt LED INTEGREE 00325 00326 --rledWDT; if(rledWDT<= 0){rledWDT= 0; R_LED_OFF;}else{R_LED_ON;}; // wdt LED ROUGE 00327 --gledWDT; if(gledWDT<= 0){gledWDT= 0; G_LED_OFF;}else{G_LED_ON;}; // wdt LED VERTE 00328 --bledWDT; if(bledWDT<= 0){bledWDT= 0; B_LED_OFF;}else{B_LED_ON;}; // wdt LED VERTE 00329 00330 --sonWDT; if(sonWDT<= 0){sonWDT= 0; SON_OFF;}else{SON_ON;}; // wdt son 00331 00332 --trame.wdtTX; if(trame.wdtTX < 0) {trame.wdtTX = 0;}; // wdt TX TRAME (periode emission) 00333 00334 --trame.wdtRX; if(trame.wdtRX <= 0) {trame.wdtRX = 0; ;}; // wdt RX TRAME 00335 if(trame.wdtRX == 1 ) {ctn= wBUFFER- 1; 00336 while(ctn>= 0){trame.rx[ctn]= '+'; --ctn;}; 00337 ctn= wBUFFER- 3; trame.rx[ctn]= '\r'; 00338 ctn= wBUFFER- 2; trame.rx[ctn]= '\n'; 00339 sonWDT= 25; 00340 }; 00341 00342 --secWDT; if(secWDT<= 0){secWDT= 0;}; // wdt Seconde 00343 00344 // a- Process/ Gestion CLAVIER 00345 key = noKEY; 00346 if(SW1== 1){key= lKEY;}; // appui touche RIGHT 00347 if(SW2== 1){key= mKEY;}; // appui touche MIDDLE 00348 if(SW3== 1){key= rKEY;}; // appui touche LEFT 00349 if(SW0== 0){key= razKEY;}; // appui touche RAZ (touche inversée) 00350 00351 // b- Process/ Gestion LED 00352 switch(key){ 00353 case lKEY : if(fINPUT== true){sonWDT= 3; sw1WDT= keyWDTMAX ; bledWDT= 10; fINPUT= false;}; break; 00354 case mKEY : if(fINPUT== true){sonWDT= 3; sw2WDT= keyWDTMAX ; gledWDT= 10; fINPUT= false;}; break; 00355 case rKEY : if(fINPUT== true){sonWDT= 3; sw3WDT= keyWDTMAX ; rledWDT= 10; fINPUT= false;}; break; 00356 case razKEY : if(fINPUT== true){sonWDT= 3; sw0WDT= keyWDTMAX ; 00357 bledWDT= 5; gledWDT= 5; rledWDT= 5; fINPUT= false;}; break; 00358 case noKEY : fINPUT= true; break; 00359 default : break; 00360 }; 00361 00362 // c- Process/ Gestion PAD 00363 // c.1- Process/ Gestion PAD/ SW 00364 ctn= 0; 00365 while(ctn<= padNbSW){ 00366 switch(ctn){ 00367 case 0: // Gestion SW(0]: RAZ loi 00368 pad.sw[0].value= OFF; if(key== razKEY){pad.sw[0].value= ON;}; 00369 if(pad.sw[0].value== ON){ 00370 pad.axe[1].in= Dyn0; pad.axe[1].i0= Dyn0; pad.axe[1].i= 0; pad.axe[1].out= 0; 00371 pad.axe[0].in= Dyn0; pad.axe[0].i0= Dyn0; pad.axe[0].i= 0; pad.axe[0].out= 0; 00372 }; 00373 break; 00374 case 1: // Gestion SW(1] 00375 break; 00376 case 2: // Gestion SW(2] 00377 break; 00378 case 3: // Gestion SW(3] 00379 break; 00380 case 4: // Gestion SW(4] 00381 break; 00382 default:break; 00383 }; 00384 ++ctn; 00385 }; // fin while(ctn<= padNbSW){ 00386 00387 00388 // c.2- Process/ Gestion SW 00389 sw= mSTB; 00390 if(sw0WDT> 0){sw= mRAZ;}; 00391 if(sw1WDT> 0){sw= mSTP;}; 00392 if(sw2WDT> 0){sw= mMAN;}; 00393 if(sw3WDT> 0){sw= mPA; }; 00394 00395 00396 // c.2- Process/ Gestion PAD 00397 // c.2- Process/ Gestion PAD/ axe 1 00398 pad.axe[0].out = 2*padX- 1; 00399 if(pad.axe[0].out< -1){pad.axe[0].out= -1;}; 00400 if(pad.axe[0].out> 1){pad.axe[0].out= 1;}; 00401 00402 // c.2.3- Process/ Gestion PAD/ axe Tangage 00403 pad.axe[1].out = 2*padY- 1; 00404 if(pad.axe[1].out< -1){pad.axe[1].out= -1;}; 00405 if(pad.axe[1].out> 1){pad.axe[1].out= 1;}; 00406 00407 00408 --periode; 00409 if(periode<= 0){ 00410 sprintf(trame.tx,"%c,%d,%d,%d,%d,%d,%d,%c %d \r\n", startB, trame.id, (int)(DynM* pad.axe[1].out), (int)(DynM* pad.axe[0].out), sw, 0, 0, endB, epoch_time); 00411 uart.printf("%s",trame.tx); 00412 // usb.printf("Tx to MOBILE : %s",trame.tx); 00413 00414 periode= 10; 00415 }; 00416 00417 } 00418 00419 00420 00421 00422 00423 00424 //5.4- Definition/ Procedures/ Initialisation 00425 int InitProcess(void){ 00426 00427 int cmpt= 0, ctn= 0, status= 0; 00428 00429 pTX= 0; 00430 RX_LED_OFF; 00431 R_LED_OFF; 00432 G_LED_OFF; 00433 B_LED_OFF; 00434 SON_OFF; 00435 00436 usb.printf("\r\n\r\n\r\n"); 00437 if(vDEBUG== true){usb.printf("%s/ Initialisation ..... %s \r\n", productName, versionName); wait(1);}; 00438 00439 00440 // Signal Sonore et Lumineux de Bienvenue 00441 SON_ON; wait(0.1); SON_OFF; 00442 R_LED_ON; G_LED_ON; B_LED_ON; 00443 00444 // if(vDEBUG== true){usb.println(" "); usb.print(productName); usb.print(" nb axes: "); usb.println(padNbAxe);delay(10);}; 00445 cmpt= 0; 00446 while(cmpt< padNbAxe){ 00447 // if(vDEBUG== true){usb.print("-"); delay(500);}; 00448 switch(cmpt){ 00449 case 0:// Axe Latteral (Roulis) 00450 // pad.axe[cmpt].nom = XAxeName; // "Roulis"; // Axe/ Designation 00451 pad.axe[cmpt].scB = 100; // Mode Commande : 100 (%: 100 -> Proportionnelle pure, 0 -> Integrale Pure) 00452 pad.axe[cmpt].dzB = 7; // Dead Zone : 5 (% plage) 00453 pad.axe[cmpt].znlB = 25; // Zone Non Linearite: 50 (% plage) 00454 pad.axe[cmpt].ctfB= 20; // Gain Proportionnel: 20 (% plage) 00455 pad.axe[cmpt].ctiB= 0; // Gain Integral : 0 (% plage) 00456 pad.axe[cmpt].gainI= 20; // Gain Integration deuxieme zone lineaire/ Valeure 00457 // RAZ filtre moyenneur 00458 // pad.axe[cmpt].fm[0]= 0; pad.axe[cmpt].fm[1]= 0; pad.axe[cmpt].fm[2]= 0; pad.axe[cmpt].fm[3]= 0; pad.axe[cmpt].fm[4]= 0; 00459 break; 00460 00461 case 1:// Axe Antero posterieur (Tangage) 00462 // pad.axe[cmpt].nom = YAxeName; //"Tangage";// Axe/ Designation 00463 pad.axe[cmpt].scB = 100; // Mode Commande : 100 (%: 100 -> Proportionnelle pure, 0 -> Integrale Pure) // Commande Integrale Pure 00464 pad.axe[cmpt].dzB = 5; // Dead Zone : 10 (% plage) 00465 pad.axe[cmpt].znlB = 70; // Zone Non Linearite: 40 (% plage) 00466 pad.axe[cmpt].ctfB= 20; // Gain Proportionnel: 20 (% plage) 00467 pad.axe[cmpt].ctiB= 0; // Gain Integral : 0 (% plage) 00468 pad.axe[cmpt].gainI= 25; // Gain Integration deuxieme zone lineaire/ Valeure 00469 // RAZ filtre moyenneur 00470 // pad.axe[cmpt].fm[0]= 0; pad.axe[cmpt].fm[1]= 0; pad.axe[cmpt].fm[2]= 0; pad.axe[cmpt].fm[3]= 0; pad.axe[cmpt].fm[4]= 0; 00471 break; 00472 default: break; 00473 }; // fin switch(cmpt){ 00474 00475 pad.axe[cmpt].sc = pad.axe[cmpt].scB/ 100; 00476 pad.axe[cmpt].dzm = pad.axe[cmpt].dzB; pad.axe[cmpt].dzm/= 100; // Dead Zone/ Valeur min 00477 pad.axe[cmpt].dzm*= -1; 00478 pad.axe[cmpt].dzM = pad.axe[cmpt].dzB; pad.axe[cmpt].dzM/= 100; // Dead Zone/ Valeur MAX 00479 pad.axe[cmpt].znlm= pad.axe[cmpt].znlB; pad.axe[cmpt].znlm/= 100; // Zone Non Linearite/ Valeur min 00480 pad.axe[cmpt].znlm*= -1; 00481 pad.axe[cmpt].znlM= pad.axe[cmpt].znlB; pad.axe[cmpt].znlM/= 100; // Zone Non Linearite/ Valeur MAX 00482 pad.axe[cmpt].ctf = ctfmin+ (((pad.axe[cmpt].ctfB*(ctfMAX- ctfmin))/100)); // Gain Proportionnel/ Valeur nominale 00483 pad.axe[cmpt].cti = ctimin+ (((pad.axe[cmpt].ctiB*(ctiMAX- ctimin))/100)); // Gain Integral/ Valeur nominale 00484 pad.axe[cmpt].l = 0; 00485 pad.axe[cmpt].i = 0; 00486 pad.axe[cmpt].p = 0; 00487 pad.axe[cmpt].i0 = 0; 00488 pad.axe[cmpt].in = 0; 00489 pad.axe[cmpt].out = 0; 00490 pad.axe[cmpt].x= 0; pad.axe[cmpt].dX= 0; pad.axe[cmpt].X= 0; 00491 00492 ++cmpt; 00493 }; // fin while(cmpt<= padNbAxe){ 00494 00495 00496 // if(vDEBUG== true){usb.println(" "); delay(10);}; 00497 00498 // Initialisation/ Module/ PAD/ SW 00499 // if(vDEBUG== true){usb.print(productName); usb.print("/ Initialisation/ PAD/ SW "); delay(10);}; 00500 cmpt= 0; 00501 while(cmpt<= padNbSW){ 00502 // if(vDEBUG== true){usb.print("-"); delay(10);}; 00503 switch(cmpt){ 00504 case 0:// Switch SW0: RAZ 00505 pad.sw[0].value = OFF; 00506 break; 00507 default: break; 00508 }; // fin switch(cmpt){ 00509 ++cmpt; 00510 }; // fin while(cmpt<= padNbSW){ 00511 00512 00513 // Initialisation/ Module/ Trame emission et reception UART 00514 // if(vDEBUG== true){usb.print(productName); usb.print("/ Initialisation/ PAD/ Trame "); delay(10);}; 00515 trame.wdtTX = wdtTXMAX; 00516 trame.wdtRX = wdtRXMAX; 00517 ctn= wBUFFER- 1; while(ctn>= 0){trame.rx[ctn]= ' '; --ctn;}; 00518 trame.pcar = -1; 00519 trame.fSB = false; 00520 trame.fEB = false; 00521 trame.sb = startB; 00522 trame.eb = endB; 00523 trame.dlb = dlB; 00524 trame.id = idMOBILE; 00525 00526 //Initialisation/ Materiel/ DS3231 00527 // ds3231_time_t time = {12,0,0,0,1}; 00528 // int16_t ret_val= rtc.set_time(time); 00529 00530 00531 //Initialisation/ Materiel/ Communication/ UART USB 00532 usb.baud(usbBR); wait(0.3); 00533 usb.attach(&rx_usb_isr, Serial::RxIrq); 00534 // USB.attach(&Tx_USB_Isr, Serial::TxIrq); 00535 pUSBRx= 0; pUSBTx= 0; 00536 00537 //Initialisation/ Materiel/ Communication/ UART BT 00538 uart.baud(uartBR); wait(0.3); 00539 uart.attach(&rx_uart_isr, Serial::RxIrq); 00540 // uart.attach(&Tx_uart_Isr, Serial::TxIrq); 00541 00542 //Initialisation/ Materiel/ Communication/ I2C 00543 i2c.frequency(i2cBR); wait(0.2); 00544 00545 00546 //Initialisation/ Materiel/ Communication/ RTC 00547 // epoch_time = rtc.get_epoch(); // ds3231 00548 00549 // Signal Sonore et Lumineux de Sortie 00550 SON_ON; wait(0.1); SON_OFF; 00551 R_LED_OFF; G_LED_OFF; B_LED_OFF; 00552 00553 //Initialisation/ Materiel/ Interruption principale 00554 if(status ==0){process.attach(&process_isr, TSample);}; 00555 00556 return status; 00557 } 00558 00559 00560 00561 00562 00563 00564 //5.6- Definition/ Procedure/ Alarme 00565 void alarme(void){ 00566 while(1){ 00567 B_LED_OFF; G_LED_OFF; R_LED_OFF; wait(0.3); 00568 B_LED_ON; G_LED_OFF; R_LED_OFF; wait(0.3); 00569 B_LED_OFF; G_LED_ON; R_LED_OFF; wait(0.3); 00570 B_LED_OFF; G_LED_OFF; R_LED_ON; wait(0.3); 00571 B_LED_OFF; G_LED_OFF; R_LED_OFF; wait(0.3); 00572 }; 00573 } 00574 00575 00576 00577 //5.6- Definition/ Procedure/ Principale 00578 int main(){ 00579 int statusInit= 0; 00580 string svalue = ""; 00581 00582 statusInit= InitProcess(); // Processus Principal/ Initialisation 00583 if(statusInit== -1){ alarme();}; // Processus Principal/ Initialisation/ Probleme/ ARRET 00584 00585 usb.printf("\r\n\r\n--------------------------------------------------------\r\n\r\n"); 00586 usb.printf("%s/ %s version : %s \r\n", target, productName, versionName); 00587 usb.printf("\r\n\r\n"); 00588 00589 usb.printf("Parametre/ TSample (ms) : %d \r\n", (int)(1000*TSample)); 00590 usb.printf("Parametre/ USB Baud Rate : %d \r\n", usbBR); 00591 usb.printf("\r\n"); 00592 usb.printf("%s/ STATUS : Running ... \r\n\r\n", productName); 00593 00594 // Processus principal 00595 while(true){ 00596 00597 if(secWDT<= 0){ 00598 epoch_time = rtc.get_epoch(); 00599 rledWDT= 5; 00600 secWDT= secWDTMAX; 00601 }; 00602 00603 /* 00604 // 5.15.1- Gestion Bus I2C 00605 tmp1= 888; 00606 tmp2= 999; 00607 tmp1= power.read_bus_voltage(); 00608 tmp2= power.read_current(); 00609 eTENSION= tmp1; 00610 eCOURANT= tmp2; 00611 00612 // 5.15.2- Gestion Bus CAN 00613 // 5.15.2.1- CAN Emission 00614 if(sndCAN== true){ // CAN/ Emission 00615 // CANTx.clear(); 00616 switch(processCAN){ 00617 case 0: CANTx.id= idMOBILE; processCAN= 1;break; // CAN/ demande info IMU 00618 case 1: CANTx.id= idIMU; processCAN= 0;break; 00619 default: break; 00620 }; // fin switch(processCAN){ 00621 CANTx.len= 1; 00622 CANTx.data[0]= 0; 00623 bCAN.write(CANTx); 00624 sndCAN= false; 00625 }; // fin if(sndCAN== true){ 00626 00627 // 5.15.2.2- CAN Reception 00628 if(rcvCAN== true){ // CAN/ Reception 00629 switch(CANRx.id){ 00630 case idIMU : // imuWDT= 100; 00631 // led(1, d20ms); 00632 break; 00633 default : break; 00634 }; // fin swith(CANRx.id){ 00635 rcvCAN= false; 00636 }; // fin if(rcvCAN== true){ 00637 */ 00638 }; // fin while(true){ 00639 00640 } // Fin int main() { 00641 00642
Generated on Sat Jul 23 2022 01:21:18 by
1.7.2