add Barometer
This commit is contained in:
parent
e773e6c099
commit
b73bc67c8e
44
IOT/Capteur/lib/Capteur/include/Barometer.h
Normal file
44
IOT/Capteur/lib/Capteur/include/Barometer.h
Normal 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
|
45
IOT/Capteur/lib/Capteur/src/Barometer.cpp
Normal file
45
IOT/Capteur/lib/Capteur/src/Barometer.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user