mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
main.cpp@7:ad15c386e960, 2017-08-02 (annotated)
- Committer:
- POTLESS_2
- Date:
- Wed Aug 02 06:01:03 2017 +0000
- Revision:
- 7:ad15c386e960
- Parent:
- 6:ebed9093d661
- Child:
- 8:a750d531b381
Premier jet code d?di? capteurs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
potless | 1:bef7856b5c0a | 1 | #include "mbed.h" |
potless | 2:4a8bf1d53439 | 2 | #include <string> |
POTLESS_2 | 7:ad15c386e960 | 3 | #include "Sensor_head_revB.h" |
POTLESS_2 | 4:d84250f67dec | 4 | |
POTLESS_2 | 7:ad15c386e960 | 5 | //Moniteur série |
potless | 1:bef7856b5c0a | 6 | Serial serialMonit (USBTX,USBRX,9600); |
POTLESS_2 | 4:d84250f67dec | 7 | |
POTLESS_2 | 7:ad15c386e960 | 8 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 9 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 10 | |
POTLESS_2 | 6:ebed9093d661 | 11 | //pour Param Cozir |
POTLESS_2 | 6:ebed9093d661 | 12 | const int sizeParam = 6; |
POTLESS_2 | 6:ebed9093d661 | 13 | char param[sizeParam ]; |
POTLESS_2 | 6:ebed9093d661 | 14 | int indexParam; |
POTLESS_2 | 6:ebed9093d661 | 15 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 16 | |
POTLESS_2 | 7:ad15c386e960 | 17 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 18 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 19 | float pression = 0; |
POTLESS_2 | 7:ad15c386e960 | 20 | float Temp = 0; |
POTLESS_2 | 7:ad15c386e960 | 21 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 22 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 23 | int CellO2_2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 24 | |
POTLESS_2 | 7:ad15c386e960 | 25 | //Mesure du tempsd'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 26 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 27 | float RATE = 0; |
POTLESS_2 | 7:ad15c386e960 | 28 | |
POTLESS_2 | 7:ad15c386e960 | 29 | //Thread d'intérogation des capteurs |
POTLESS_2 | 7:ad15c386e960 | 30 | Thread thread; |
POTLESS_2 | 7:ad15c386e960 | 31 | |
POTLESS_2 | 7:ad15c386e960 | 32 | void Sensors_thread() |
POTLESS_2 | 6:ebed9093d661 | 33 | { |
POTLESS_2 | 7:ad15c386e960 | 34 | while (true) { |
POTLESS_2 | 7:ad15c386e960 | 35 | |
POTLESS_2 | 7:ad15c386e960 | 36 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 37 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 38 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 39 | pression = sensors.requestPress(); |
POTLESS_2 | 7:ad15c386e960 | 40 | Temp = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 41 | //PPO2 sur ADS1015 |
POTLESS_2 | 7:ad15c386e960 | 42 | ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 43 | //Cell O2 en mV |
POTLESS_2 | 7:ad15c386e960 | 44 | CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 7:ad15c386e960 | 45 | CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 4:d84250f67dec | 46 | } |
potless | 2:4a8bf1d53439 | 47 | } |
POTLESS_2 | 4:d84250f67dec | 48 | |
POTLESS_2 | 7:ad15c386e960 | 49 | void Affichage_moniteur() |
POTLESS_2 | 4:d84250f67dec | 50 | { |
POTLESS_2 | 7:ad15c386e960 | 51 | printf(" CO2 = %d\r\n" , co2); |
POTLESS_2 | 7:ad15c386e960 | 52 | printf(" Pression = %f\r\n", pression); |
POTLESS_2 | 7:ad15c386e960 | 53 | printf(" Temperature = %f\r\n", Temp); |
POTLESS_2 | 7:ad15c386e960 | 54 | printf(" PPO2 = %d\r\n", ppO2); |
POTLESS_2 | 7:ad15c386e960 | 55 | printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 7:ad15c386e960 | 56 | printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 7:ad15c386e960 | 57 | printf("\r\n"); |
POTLESS_2 | 4:d84250f67dec | 58 | } |
POTLESS_2 | 4:d84250f67dec | 59 | |
POTLESS_2 | 7:ad15c386e960 | 60 | //Callback de l'intérruption des envois de commandes au Cozir |
POTLESS_2 | 6:ebed9093d661 | 61 | void callbackParam() |
POTLESS_2 | 4:d84250f67dec | 62 | { |
POTLESS_2 | 6:ebed9093d661 | 63 | while(serialMonit.readable()) { |
POTLESS_2 | 6:ebed9093d661 | 64 | if (indexParam == sizeParam) //éviter la saturation du buffer |
POTLESS_2 | 6:ebed9093d661 | 65 | serialMonit.getc(); |
POTLESS_2 | 6:ebed9093d661 | 66 | else |
POTLESS_2 | 6:ebed9093d661 | 67 | param [indexParam++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 6:ebed9093d661 | 68 | if ((indexParam == sizeParam) || (param[indexParam -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 6:ebed9093d661 | 69 | param[indexParam] = 0; |
POTLESS_2 | 6:ebed9093d661 | 70 | newParamFlag = true; |
POTLESS_2 | 6:ebed9093d661 | 71 | } |
POTLESS_2 | 4:d84250f67dec | 72 | } |
POTLESS_2 | 6:ebed9093d661 | 73 | } |
POTLESS_2 | 4:d84250f67dec | 74 | |
POTLESS_2 | 4:d84250f67dec | 75 | int main() |
POTLESS_2 | 4:d84250f67dec | 76 | { |
POTLESS_2 | 7:ad15c386e960 | 77 | set_time(1256729737); |
POTLESS_2 | 7:ad15c386e960 | 78 | |
POTLESS_2 | 7:ad15c386e960 | 79 | sensors.Sensors_INIT(false, false, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 6:ebed9093d661 | 80 | |
POTLESS_2 | 6:ebed9093d661 | 81 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
POTLESS_2 | 6:ebed9093d661 | 82 | |
POTLESS_2 | 7:ad15c386e960 | 83 | serialMonit.printf(" Demarrage...\r\n\r\n Entrez les comandes COZIR si besoin :\r\n"); |
POTLESS_2 | 6:ebed9093d661 | 84 | |
POTLESS_2 | 7:ad15c386e960 | 85 | thread.start(Sensors_thread); |
POTLESS_2 | 7:ad15c386e960 | 86 | |
POTLESS_2 | 7:ad15c386e960 | 87 | thread.set_priority(osPriorityRealtime); |
POTLESS_2 | 7:ad15c386e960 | 88 | |
POTLESS_2 | 7:ad15c386e960 | 89 | while (true) { |
POTLESS_2 | 6:ebed9093d661 | 90 | |
POTLESS_2 | 7:ad15c386e960 | 91 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 92 | REAL_RATE.start(); |
POTLESS_2 | 7:ad15c386e960 | 93 | |
POTLESS_2 | 7:ad15c386e960 | 94 | Affichage_moniteur(); |
potless | 5:ff7aa975646c | 95 | |
POTLESS_2 | 6:ebed9093d661 | 96 | if (newParamFlag) { |
POTLESS_2 | 6:ebed9093d661 | 97 | wait_ms(500); |
POTLESS_2 | 6:ebed9093d661 | 98 | serialMonit.printf("Param = %s\r\n", param); |
POTLESS_2 | 7:ad15c386e960 | 99 | sensors.cozirSend(param); |
POTLESS_2 | 6:ebed9093d661 | 100 | wait_ms(500); |
POTLESS_2 | 6:ebed9093d661 | 101 | strcpy(param," "); |
POTLESS_2 | 6:ebed9093d661 | 102 | indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 103 | newParamFlag = false; |
POTLESS_2 | 6:ebed9093d661 | 104 | } |
POTLESS_2 | 7:ad15c386e960 | 105 | |
POTLESS_2 | 7:ad15c386e960 | 106 | wait(1); |
POTLESS_2 | 7:ad15c386e960 | 107 | |
POTLESS_2 | 7:ad15c386e960 | 108 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 109 | REAL_RATE.stop(); |
POTLESS_2 | 7:ad15c386e960 | 110 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 7:ad15c386e960 | 111 | RATE = REAL_RATE.read(); |
POTLESS_2 | 7:ad15c386e960 | 112 | //Reset du Timer |
POTLESS_2 | 7:ad15c386e960 | 113 | REAL_RATE.reset(); |
POTLESS_2 | 7:ad15c386e960 | 114 | printf("\r\n Temps d'exécution de la boucle = %f\r\n", RATE); |
POTLESS_2 | 7:ad15c386e960 | 115 | printf("\r\n", ""); |
POTLESS_2 | 7:ad15c386e960 | 116 | |
POTLESS_2 | 4:d84250f67dec | 117 | } |
POTLESS_2 | 4:d84250f67dec | 118 | } |