mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

main.cpp

Committer:
POTLESS_2
Date:
2017-08-02
Revision:
7:ad15c386e960
Parent:
6:ebed9093d661
Child:
8:a750d531b381

File content as of revision 7:ad15c386e960:

#include "mbed.h"
#include <string>
#include "Sensor_head_revB.h"

//Moniteur série
Serial serialMonit (USBTX,USBRX,9600);

//Init de la lib ARNSRS;
SENSOR_HEAD_REV_B sensors;

//pour Param Cozir
const int sizeParam = 6;
char  param[sizeParam ];
int indexParam;
bool newParamFlag = false;

//Variables de stockage des infos capteurs
int co2 = 0;
float pression = 0;
float Temp = 0;
int ppO2 = 0;
int CellO2_1 = 0;
int CellO2_2 = 0;

//Mesure du tempsd'éxecution du loop
Timer REAL_RATE;
float RATE = 0;

//Thread d'intérogation des capteurs
Thread thread;

void Sensors_thread()
{
    while (true) {

        //CO2 sur Cozir
        co2 = sensors.requestCO2();
        //P / T sur MS5837
        pression = sensors.requestPress();
        Temp =  sensors.requestTemp();
        //PPO2 sur ADS1015
        ppO2 = sensors.requestPpO2();
        //Cell O2 en mV
        CellO2_1 = sensors.requestCellO2_1();
        CellO2_2 = sensors.requestCellO2_2();
    }
}

void Affichage_moniteur()
{
    printf("  CO2           = %d\r\n"  , co2);
    printf("  Pression      = %f\r\n", pression);
    printf("  Temperature   = %f\r\n", Temp);
    printf("  PPO2          = %d\r\n", ppO2);
    printf("  Cell O2 n 1   = %d\r\n"  , CellO2_1);
    printf("  Cell O2 n 2   = %d\r\n"  , CellO2_2);
    printf("\r\n");
}

//Callback de l'intérruption des envois de commandes au Cozir
void callbackParam()
{
    while(serialMonit.readable()) {
        if (indexParam  == sizeParam) //éviter la saturation du buffer
            serialMonit.getc();
        else
            param [indexParam++] = serialMonit.getc();//chargement du buffer dans le message
        if ((indexParam == sizeParam) || (param[indexParam -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut...
            param[indexParam] = 0;
            newParamFlag  = true;
        }
    }
}

int main()
{
     set_time(1256729737);
    
    sensors.Sensors_INIT(false, false, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);

    serialMonit.attach(&callbackParam, Serial::RxIrq);

    serialMonit.printf("  Demarrage...\r\n\r\n  Entrez les comandes COZIR si besoin :\r\n");

    thread.start(Sensors_thread);
    
    thread.set_priority(osPriorityRealtime);
    
    while (true) {

        //Démarrage du Timer mesurant le temps d'éxecution du code
        REAL_RATE.start();

        Affichage_moniteur();
        
        if (newParamFlag) {
            wait_ms(500);
            serialMonit.printf("Param = %s\r\n", param);
            sensors.cozirSend(param);
            wait_ms(500);
            strcpy(param," ");
            indexParam = 0;
            newParamFlag = false;
        }

        wait(1);
        
        //Arrêt du Timer mesurant le temps d'éxecution du code
        REAL_RATE.stop();
        //Définition de la nouvelle valeur du temps d'échantillonage du PID.
        RATE = REAL_RATE.read();
        //Reset du Timer
        REAL_RATE.reset();
        printf("\r\n  Temps d'exécution de la boucle = %f\r\n", RATE);
        printf("\r\n", "");
        
    }
}