feat : lecteur capteur température (DHT22)
This commit is contained in:
parent
a01b3b0f98
commit
36a1fe4d91
@ -1,7 +1,9 @@
|
|||||||
#ifndef PROGRAM_H
|
#ifndef PROGRAM_H
|
||||||
#define PROGRAM_H
|
#define PROGRAM_H
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
#include "Capteur.h"
|
||||||
|
#include "HumiTemp.h"
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public:
|
public:
|
||||||
@ -14,6 +16,11 @@ public:
|
|||||||
* Program main loop
|
* Program main loop
|
||||||
*/
|
*/
|
||||||
void loop();
|
void loop();
|
||||||
|
private:
|
||||||
|
|
||||||
|
//TODO: faire commentaire
|
||||||
|
Capteur* DHT;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
49
IOT/lib/Capteur/include/Capteur.h
Normal file
49
IOT/lib/Capteur/include/Capteur.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef CAPTEUR_H
|
||||||
|
#define CAPTEUR_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
class Capteur{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Capteur object
|
||||||
|
*
|
||||||
|
* @param[in] type type de mesure lue (T/H, W, D,...)
|
||||||
|
*/
|
||||||
|
Capteur(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief tar le capteur si il a besoins d'être tarré
|
||||||
|
*
|
||||||
|
* @param[in] val *opt* si le capteur a besoins d'une valeur de ref pour être tarré
|
||||||
|
* @return true si la tarre a bien réussi (ou si il n'a pas besoins de tarre)
|
||||||
|
* @return false erreur durrant la tar
|
||||||
|
*/
|
||||||
|
virtual bool tar(int val = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lit la valeur du capteur
|
||||||
|
*
|
||||||
|
* @return String retour la valeur
|
||||||
|
*/
|
||||||
|
virtual String read() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief retourne le type de valeur lue
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String getValType();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief type de mesure lue (T/H, W, D,...)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
String type;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // CAPTEUR_H
|
38
IOT/lib/Capteur/include/HumiTemp.h
Normal file
38
IOT/lib/Capteur/include/HumiTemp.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef HUMI_TEMP_H
|
||||||
|
#define HUMI_TEMP_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include "Capteur.h"
|
||||||
|
|
||||||
|
class HumiTemp : public Capteur{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Humi Temp object
|
||||||
|
*
|
||||||
|
* @param pin pin du capteur dht
|
||||||
|
* @param type type de capteur dht (11,22,...)
|
||||||
|
*/
|
||||||
|
HumiTemp(int pin, uint8_t type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lit le capteur d'humi/temp
|
||||||
|
*
|
||||||
|
* @return String valeur format "XX/YY" X% et Y°C
|
||||||
|
*/
|
||||||
|
String read();
|
||||||
|
|
||||||
|
//TODO: faire commentaire
|
||||||
|
int getTemp();
|
||||||
|
int getHumi();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
DHT* capteur;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //HUMI_TEMP_H
|
13
IOT/lib/Capteur/src/Capteur.cpp
Normal file
13
IOT/lib/Capteur/src/Capteur.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "../include/Capteur.h"
|
||||||
|
|
||||||
|
Capteur::Capteur(String type){
|
||||||
|
this->type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Capteur::tar(int val){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String Capteur::getValType(){
|
||||||
|
return this->type;
|
||||||
|
}
|
34
IOT/lib/Capteur/src/HumiTemp.cpp
Normal file
34
IOT/lib/Capteur/src/HumiTemp.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "../include/HumiTemp.h"
|
||||||
|
|
||||||
|
HumiTemp::HumiTemp(int pin, uint8_t type):
|
||||||
|
Capteur("H/T"){
|
||||||
|
this->capteur = new DHT(pin, type);
|
||||||
|
this->capteur->begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
int HumiTemp::getTemp(){
|
||||||
|
int temp = this->capteur->readTemperature();
|
||||||
|
if(isnan(temp)){
|
||||||
|
Serial.println(" DHT reading failed ");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int HumiTemp::getHumi(){
|
||||||
|
int hum = this->capteur->readHumidity();
|
||||||
|
if(isnan(hum)){
|
||||||
|
Serial.println(" DHT reading failed ");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return hum;
|
||||||
|
}
|
||||||
|
|
||||||
|
String HumiTemp::read(){
|
||||||
|
String sortie = "";
|
||||||
|
|
||||||
|
sortie += String(this->getHumi());
|
||||||
|
sortie += "/";
|
||||||
|
sortie += String(this->getTemp());
|
||||||
|
return sortie;
|
||||||
|
}
|
@ -52,6 +52,8 @@ upload_speed = 921600
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
; example:
|
; example:
|
||||||
; erropix/ESP32 AnalogWrite@0.2
|
; erropix/ESP32 AnalogWrite@0.2
|
||||||
|
adafruit/DHT sensor library@^1.4.4
|
||||||
|
adafruit/Adafruit Unified Sensor@^1.1.9 ; required by DHT
|
||||||
|
|
||||||
; Checker settings
|
; Checker settings
|
||||||
check_tool = clangtidy, cppcheck
|
check_tool = clangtidy, cppcheck
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
Program::Program() {
|
Program::Program() {
|
||||||
// Startup
|
// Startup
|
||||||
Serial.begin(MONITOR_SPEED);
|
Serial.begin(MONITOR_SPEED);
|
||||||
|
this->DHT = new HumiTemp(D4, DHT22);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::loop() {
|
void Program::loop() {
|
||||||
// Loop
|
// Loop
|
||||||
|
delay(2000);
|
||||||
|
Serial.println(this->DHT->read());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user