add Barometer

This commit is contained in:
Clement 2023-06-26 17:23:41 +02:00
parent e773e6c099
commit b73bc67c8e
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#ifndef BAROMETER_H
#define BAROMETER_H
#include <Arduino.h>
#include <SFE_BMP180.h>
#include <Wire.h>
#include "Capteur.h"
class Barometer : public Capteur{
public:
/**
* @brief Construct a new Capteur object
*
*/
Barometer();
/**
* @brief lit la valeur du capteur
*
* @return String valeur forma "XX/YY" X mBar et Y °C
*/
virtual String read();
/**
* @brief retourne le type de valeur lue
*
* @return String
*/
String getValType();
//TODO: faire commentaire
int getTemp();
int getPressure();
private:
//TODO: faire commentaire
SFE_BMP180* capteur;
};
#endif // BAROMETER_H

View File

@ -0,0 +1,45 @@
#include "../include/Barometer.h"
Barometer::Barometer():
Capteur("P/T"){
this->capteur = new SFE_BMP180();
this->capteur->begin();
}
int Barometer::getTemp(){
char status = capteur->startTemperature();
if (status != 0){
delay(status);
}
double temp;
status = this->capteur->getTemperature(temp);
if(status == 0){
Serial.println("Temperature reading failed ");
return -1;
}
return temp;
}
int Barometer::getPressure(){
char status = this->capteur->startPressure(3);
if(status){
delay(status);
}
double press = 0;
double T = 0;
status = this->capteur->getPressure(press, T);
if(status == 0){
Serial.println("Pressure reading failed ");
return -1;
}
return press;
}
String Barometer::read(){
String sortie = "";
sortie += String(this->getPressure());
sortie += "/";
sortie += String(this->getTemp());
return sortie;
}