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-09-27
Revision:
8:a750d531b381
Parent:
7:ad15c386e960
Child:
9:04bfdfc029cb

File content as of revision 8:a750d531b381:

#include "mbed.h"
#include <string>
#include "Sensor_head_revB.h"
#include "HTU21D.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;

//HTU21D
HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL
int sample_ftemp;
float sample_ctemp;
int sample_ktemp;
int sample_humid;

//VT100
static const char CLS[] = "\x1B[2J";
static const char HOME[] = "\x1B[H";

//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();
        
        //HTU21D
        //sample_ftemp = temphumid.sample_ftemp();
        sample_ctemp = temphumid.sample_ctemp();
        //sample_ktemp = temphumid.sample_ktemp();
        sample_humid = temphumid.sample_humid();
    }
}

void Affichage_moniteur()
{
    
    printf("  CO2             = %d\r\n"  , co2);
    printf("  PPO2            = %d\r\n", ppO2);
    printf("  Pression        = %f\r\n", pression);
    printf("  Temperature 1   = %f\r\n", Temp);
    printf("  Temperature 2   = %f C\n\r", sample_ctemp);
    printf("  Humidity        = %d %%\n\r", sample_humid);
    printf("\n\r");
    printf("  Cell O2 n 1     = %d\r\n"  , CellO2_1);
    printf("  Cell O2 n 2     = %d\r\n"  , CellO2_2);
    printf("\r\n");
    
    //printf("Temperature: %d F\n\r", sample_ftemp);    
    //printf("Temperature: %d K\n\r", sample_ktemp);    
    
   
    /*
    printf(HOME);
    printf("\x1b[30m");
    printf("\x1b[0m\r  CO2          = \x1b[1m\x1b[K%d\n", co2);
    printf("\x1b[0m\r  Pression     = \x1b[1m\x1b[K%f\n", pression);
    printf("\x1b[0m\r  Temperature  = \x1b[1m\x1b[K%f\n", Temp);
    printf("\x1b[0m\r  PPO2         = \x1b[1m\x1b[K%d\n", ppO2);
    printf("\x1b[0m\r  Cell O2 n 1  = \x1b[1m\x1b[K%d\n", CellO2_1);
    printf("\x1b[0m\r  Cell O2 n 2  = \x1b[1m\x1b[K%d\n", CellO2_2);
    printf("\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);
    
    printf(CLS);
    
    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 execution de la boucle = %f\r\n", RATE);
        printf("\r\n", "");
        
    }
}