![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@8:a750d531b381, 2017-09-27 (annotated)
- Committer:
- POTLESS_2
- Date:
- Wed Sep 27 08:02:47 2017 +0000
- Revision:
- 8:a750d531b381
- Parent:
- 7:ad15c386e960
- Child:
- 9:04bfdfc029cb
Code de test globale de la carte sensor head, en utilisant un thread pour la recul des capteurs et ajout du capteur I2C H / T....; Avec variante de la lib 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 | 8:a750d531b381 | 4 | #include "HTU21D.h" |
POTLESS_2 | 4:d84250f67dec | 5 | |
POTLESS_2 | 7:ad15c386e960 | 6 | //Moniteur série |
potless | 1:bef7856b5c0a | 7 | Serial serialMonit (USBTX,USBRX,9600); |
POTLESS_2 | 4:d84250f67dec | 8 | |
POTLESS_2 | 7:ad15c386e960 | 9 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 10 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 11 | |
POTLESS_2 | 6:ebed9093d661 | 12 | //pour Param Cozir |
POTLESS_2 | 6:ebed9093d661 | 13 | const int sizeParam = 6; |
POTLESS_2 | 6:ebed9093d661 | 14 | char param[sizeParam ]; |
POTLESS_2 | 6:ebed9093d661 | 15 | int indexParam; |
POTLESS_2 | 6:ebed9093d661 | 16 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 17 | |
POTLESS_2 | 7:ad15c386e960 | 18 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 19 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 20 | float pression = 0; |
POTLESS_2 | 7:ad15c386e960 | 21 | float Temp = 0; |
POTLESS_2 | 7:ad15c386e960 | 22 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 23 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 24 | int CellO2_2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 25 | |
POTLESS_2 | 7:ad15c386e960 | 26 | //Mesure du tempsd'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 27 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 28 | float RATE = 0; |
POTLESS_2 | 7:ad15c386e960 | 29 | |
POTLESS_2 | 8:a750d531b381 | 30 | //HTU21D |
POTLESS_2 | 8:a750d531b381 | 31 | HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL |
POTLESS_2 | 8:a750d531b381 | 32 | int sample_ftemp; |
POTLESS_2 | 8:a750d531b381 | 33 | float sample_ctemp; |
POTLESS_2 | 8:a750d531b381 | 34 | int sample_ktemp; |
POTLESS_2 | 8:a750d531b381 | 35 | int sample_humid; |
POTLESS_2 | 8:a750d531b381 | 36 | |
POTLESS_2 | 8:a750d531b381 | 37 | //VT100 |
POTLESS_2 | 8:a750d531b381 | 38 | static const char CLS[] = "\x1B[2J"; |
POTLESS_2 | 8:a750d531b381 | 39 | static const char HOME[] = "\x1B[H"; |
POTLESS_2 | 8:a750d531b381 | 40 | |
POTLESS_2 | 7:ad15c386e960 | 41 | //Thread d'intérogation des capteurs |
POTLESS_2 | 7:ad15c386e960 | 42 | Thread thread; |
POTLESS_2 | 7:ad15c386e960 | 43 | |
POTLESS_2 | 7:ad15c386e960 | 44 | void Sensors_thread() |
POTLESS_2 | 6:ebed9093d661 | 45 | { |
POTLESS_2 | 7:ad15c386e960 | 46 | while (true) { |
POTLESS_2 | 7:ad15c386e960 | 47 | |
POTLESS_2 | 7:ad15c386e960 | 48 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 49 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 50 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 51 | pression = sensors.requestPress(); |
POTLESS_2 | 7:ad15c386e960 | 52 | Temp = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 53 | //PPO2 sur ADS1015 |
POTLESS_2 | 7:ad15c386e960 | 54 | ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 55 | //Cell O2 en mV |
POTLESS_2 | 7:ad15c386e960 | 56 | CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 7:ad15c386e960 | 57 | CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 8:a750d531b381 | 58 | |
POTLESS_2 | 8:a750d531b381 | 59 | //HTU21D |
POTLESS_2 | 8:a750d531b381 | 60 | //sample_ftemp = temphumid.sample_ftemp(); |
POTLESS_2 | 8:a750d531b381 | 61 | sample_ctemp = temphumid.sample_ctemp(); |
POTLESS_2 | 8:a750d531b381 | 62 | //sample_ktemp = temphumid.sample_ktemp(); |
POTLESS_2 | 8:a750d531b381 | 63 | sample_humid = temphumid.sample_humid(); |
POTLESS_2 | 4:d84250f67dec | 64 | } |
potless | 2:4a8bf1d53439 | 65 | } |
POTLESS_2 | 4:d84250f67dec | 66 | |
POTLESS_2 | 7:ad15c386e960 | 67 | void Affichage_moniteur() |
POTLESS_2 | 4:d84250f67dec | 68 | { |
POTLESS_2 | 8:a750d531b381 | 69 | |
POTLESS_2 | 8:a750d531b381 | 70 | printf(" CO2 = %d\r\n" , co2); |
POTLESS_2 | 8:a750d531b381 | 71 | printf(" PPO2 = %d\r\n", ppO2); |
POTLESS_2 | 8:a750d531b381 | 72 | printf(" Pression = %f\r\n", pression); |
POTLESS_2 | 8:a750d531b381 | 73 | printf(" Temperature 1 = %f\r\n", Temp); |
POTLESS_2 | 8:a750d531b381 | 74 | printf(" Temperature 2 = %f C\n\r", sample_ctemp); |
POTLESS_2 | 8:a750d531b381 | 75 | printf(" Humidity = %d %%\n\r", sample_humid); |
POTLESS_2 | 8:a750d531b381 | 76 | printf("\n\r"); |
POTLESS_2 | 8:a750d531b381 | 77 | printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 8:a750d531b381 | 78 | printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 7:ad15c386e960 | 79 | printf("\r\n"); |
POTLESS_2 | 8:a750d531b381 | 80 | |
POTLESS_2 | 8:a750d531b381 | 81 | //printf("Temperature: %d F\n\r", sample_ftemp); |
POTLESS_2 | 8:a750d531b381 | 82 | //printf("Temperature: %d K\n\r", sample_ktemp); |
POTLESS_2 | 8:a750d531b381 | 83 | |
POTLESS_2 | 8:a750d531b381 | 84 | |
POTLESS_2 | 8:a750d531b381 | 85 | /* |
POTLESS_2 | 8:a750d531b381 | 86 | printf(HOME); |
POTLESS_2 | 8:a750d531b381 | 87 | printf("\x1b[30m"); |
POTLESS_2 | 8:a750d531b381 | 88 | printf("\x1b[0m\r CO2 = \x1b[1m\x1b[K%d\n", co2); |
POTLESS_2 | 8:a750d531b381 | 89 | printf("\x1b[0m\r Pression = \x1b[1m\x1b[K%f\n", pression); |
POTLESS_2 | 8:a750d531b381 | 90 | printf("\x1b[0m\r Temperature = \x1b[1m\x1b[K%f\n", Temp); |
POTLESS_2 | 8:a750d531b381 | 91 | printf("\x1b[0m\r PPO2 = \x1b[1m\x1b[K%d\n", ppO2); |
POTLESS_2 | 8:a750d531b381 | 92 | printf("\x1b[0m\r Cell O2 n 1 = \x1b[1m\x1b[K%d\n", CellO2_1); |
POTLESS_2 | 8:a750d531b381 | 93 | printf("\x1b[0m\r Cell O2 n 2 = \x1b[1m\x1b[K%d\n", CellO2_2); |
POTLESS_2 | 8:a750d531b381 | 94 | printf("\n"); |
POTLESS_2 | 8:a750d531b381 | 95 | */ |
POTLESS_2 | 4:d84250f67dec | 96 | } |
POTLESS_2 | 4:d84250f67dec | 97 | |
POTLESS_2 | 7:ad15c386e960 | 98 | //Callback de l'intérruption des envois de commandes au Cozir |
POTLESS_2 | 6:ebed9093d661 | 99 | void callbackParam() |
POTLESS_2 | 4:d84250f67dec | 100 | { |
POTLESS_2 | 6:ebed9093d661 | 101 | while(serialMonit.readable()) { |
POTLESS_2 | 6:ebed9093d661 | 102 | if (indexParam == sizeParam) //éviter la saturation du buffer |
POTLESS_2 | 6:ebed9093d661 | 103 | serialMonit.getc(); |
POTLESS_2 | 6:ebed9093d661 | 104 | else |
POTLESS_2 | 6:ebed9093d661 | 105 | param [indexParam++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 6:ebed9093d661 | 106 | if ((indexParam == sizeParam) || (param[indexParam -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 6:ebed9093d661 | 107 | param[indexParam] = 0; |
POTLESS_2 | 6:ebed9093d661 | 108 | newParamFlag = true; |
POTLESS_2 | 6:ebed9093d661 | 109 | } |
POTLESS_2 | 4:d84250f67dec | 110 | } |
POTLESS_2 | 6:ebed9093d661 | 111 | } |
POTLESS_2 | 4:d84250f67dec | 112 | |
POTLESS_2 | 4:d84250f67dec | 113 | int main() |
POTLESS_2 | 4:d84250f67dec | 114 | { |
POTLESS_2 | 8:a750d531b381 | 115 | set_time(1256729737); |
POTLESS_2 | 7:ad15c386e960 | 116 | |
POTLESS_2 | 7:ad15c386e960 | 117 | sensors.Sensors_INIT(false, false, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 6:ebed9093d661 | 118 | |
POTLESS_2 | 6:ebed9093d661 | 119 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
POTLESS_2 | 6:ebed9093d661 | 120 | |
POTLESS_2 | 7:ad15c386e960 | 121 | serialMonit.printf(" Demarrage...\r\n\r\n Entrez les comandes COZIR si besoin :\r\n"); |
POTLESS_2 | 6:ebed9093d661 | 122 | |
POTLESS_2 | 7:ad15c386e960 | 123 | thread.start(Sensors_thread); |
POTLESS_2 | 7:ad15c386e960 | 124 | |
POTLESS_2 | 7:ad15c386e960 | 125 | thread.set_priority(osPriorityRealtime); |
POTLESS_2 | 7:ad15c386e960 | 126 | |
POTLESS_2 | 8:a750d531b381 | 127 | printf(CLS); |
POTLESS_2 | 8:a750d531b381 | 128 | |
POTLESS_2 | 7:ad15c386e960 | 129 | while (true) { |
POTLESS_2 | 6:ebed9093d661 | 130 | |
POTLESS_2 | 7:ad15c386e960 | 131 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 132 | REAL_RATE.start(); |
POTLESS_2 | 7:ad15c386e960 | 133 | |
POTLESS_2 | 7:ad15c386e960 | 134 | Affichage_moniteur(); |
potless | 5:ff7aa975646c | 135 | |
POTLESS_2 | 6:ebed9093d661 | 136 | if (newParamFlag) { |
POTLESS_2 | 6:ebed9093d661 | 137 | wait_ms(500); |
POTLESS_2 | 6:ebed9093d661 | 138 | serialMonit.printf("Param = %s\r\n", param); |
POTLESS_2 | 7:ad15c386e960 | 139 | sensors.cozirSend(param); |
POTLESS_2 | 6:ebed9093d661 | 140 | wait_ms(500); |
POTLESS_2 | 6:ebed9093d661 | 141 | strcpy(param," "); |
POTLESS_2 | 6:ebed9093d661 | 142 | indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 143 | newParamFlag = false; |
POTLESS_2 | 6:ebed9093d661 | 144 | } |
POTLESS_2 | 7:ad15c386e960 | 145 | |
POTLESS_2 | 7:ad15c386e960 | 146 | wait(1); |
POTLESS_2 | 7:ad15c386e960 | 147 | |
POTLESS_2 | 7:ad15c386e960 | 148 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 149 | REAL_RATE.stop(); |
POTLESS_2 | 7:ad15c386e960 | 150 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 7:ad15c386e960 | 151 | RATE = REAL_RATE.read(); |
POTLESS_2 | 7:ad15c386e960 | 152 | //Reset du Timer |
POTLESS_2 | 7:ad15c386e960 | 153 | REAL_RATE.reset(); |
POTLESS_2 | 8:a750d531b381 | 154 | printf("\r\n Temps d execution de la boucle = %f\r\n", RATE); |
POTLESS_2 | 7:ad15c386e960 | 155 | printf("\r\n", ""); |
POTLESS_2 | 7:ad15c386e960 | 156 | |
POTLESS_2 | 4:d84250f67dec | 157 | } |
POTLESS_2 | 4:d84250f67dec | 158 | } |