feat: gestion oled screen #48

Merged
Clement merged 5 commits from feat/oled-screen into master 2023-05-14 07:16:32 +00:00
14 changed files with 380 additions and 165 deletions
Showing only changes of commit ddefd7e15f - Show all commits

View File

@ -28,11 +28,15 @@ build_flags =
-D POID_DOUT=14
-D POID_SCK=15
-D MOYENNE_CALIBRATION=20
; trash can ID
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
-D TRASHCAN_TWO=\"4brip5fwm001bs9\"
-D TRASHCAN_THREE=\"n4il9ckl5016aqi\"
-D API_HOST=\"iot.epi.cb85.software\"
;---CAPTEUR FULL CONFIG---
-D ULTRA_SOUND_FULL=\"10\"
-D DHT_FULL=\"20:30/60:80\"
-D POID_FULL=\"100\"

View File

@ -18,7 +18,49 @@ Class Program {
+ setup()
}
abstract Class Capteur {
# full: bool
# type: String
# fullVall: String
+ Capteur(type: String, fullVal: String)
+ {abstract} tar(val: int): bool
+ {abstract} read(): String = 0
+ isFull(): bool
+ getValType(): String
}
class Balance{
- capteur: HX711*
- initialized: bool
- calibrationFact: int
- initialVal: long
+ Balance(doutPin: int, sck: int, fullVal:String)
+ read(): String
+ initCalibration(): bool
+ calibration(poidsRef: int, moyenneCalibration: int): bool
+ tar(val: int = 0): bool
}
class Ultrason{
- capteur: DHT*
+ HumiTemp(pin: int, type: String, fullVal: String)
+ read(): String
}
class Ultrason{
- capteur: Ultrasonic*
+ Ultrason(triguer: int, echo: int, fullVal: String)
+ read(): String
}
Balance --|> Capteur
Ultrason --|> Capteur
HumiTemp --|> Capteur
Program <-- Balance
Program <-- Ultrason
Program <-- HumiTemp
@enduml

View File

@ -6,6 +6,9 @@
#include <Ultrasonic.h>
#include "API.h"
#include "Capteur.h"
#include "Ultrason.h"
#include "HumiTemp.h"
#include "Balance.h"
class Program{
@ -29,20 +32,19 @@ private:
* @brief capteur humi/temp
*
*/
DHT *dht;
Capteur *dht;
/**
* @brief capteur ultra son pour le niveau de remplissage de la poubelle
*
*/
Ultrasonic *ultrasonic;
Capteur *ultrasonic;
/**
* @brief capteur poid pour le niveau de remplissage de la poubelle
*
*/
Balance *balance;
Capteur *balance;
/**
* @brief Réference de l'API pour les calls

View File

@ -1,62 +0,0 @@
#include "../include/Balance.h"
Balance::Balance(int doutPin, int sckPin) {
scale.begin(doutPin, sckPin);
this->initialized = false;
scale.set_scale();
scale.tare();
this->initialVal = 0;
this->calibrationFact = 0;
}
boolean Balance::initCalibration() {
scale.set_scale();
scale.tare();
this->initialVal = scale.read_average(20);
return true;
}
boolean Balance::calibration(int poidsRef,int moyenne_calibration) {
int rawValref = 0; // Valeur brute de plexiglas et poids réf
int tempPoids = 0; // C'est la valeur du poids en grammes calculée grâce au facteur de calibration
rawValref = scale.read_average(moyenne_calibration);
this->calibrationFact = (rawValref - this->initialVal) / poidsRef;
do {
scale.set_scale(calibrationFact);
tempPoids = scale.get_units(5);
if (tempPoids < poidsRef) {
calibrationFact -= 1;
} else if (tempPoids > poidsRef) {
calibrationFact += 1;
}
} while (tempPoids != poidsRef);
return initialized = true;
}
double Balance::getAverage(int nbMesure) {
if (initialized == true) {
return scale.get_units(nbMesure);
} else {
return 0;
}
}
double Balance::getValue() {
if (initialized == true) {
return scale.get_units();
} else {
return 0;
}
}
void Balance::setCalibrationFact(int caliFact){
this->initialized = true;
this->calibrationFact = caliFact;
scale.set_scale(caliFact);
}

View File

@ -3,41 +3,32 @@
#include <Arduino.h>
#include <HX711.h>
class Balance {
#include "Capteur.h"
class Balance: public Capteur{
public:
/**
* @brief constructeur
*
* @param doutPin : pin DOUT du module HX711
*
* @param sckPin : pin horloge du module HX711
*
* @param poidsRef : valeur de poids posée sur la balance ref en grammes
*/
Balance(int doutPin, int sckPin);
* @param[in] doutPin : pin DOUT du module HX711
* @param[in] sckPin : pin horloge du module HX711
* @param[in] fullVall : valeur a la quel la poubelle est pleine
*/
Balance(int doutPin, int sckPin, String fullVall);
/**
* @brief determine le poids
* @brief lit la valeur du capteur de poid
*
* @return poids (double)
*/
double getValue();
/**
* @brief determine la moyenne poids
*
* @param nbMesure : nombre de mesure effectues pour la moyenne
*
* @return moyenne poids (double)
*/
double getAverage(int nbMesure);
* @return String retour la valeur
*/
String read();
/**
* @brief tare et scale a 0, et recuperation de la valeur brut du plateau
*/
boolean initCalibration();
bool initCalibration();
/**
* @brief initialisation du calibrage
@ -47,29 +38,34 @@ public:
*
* @return renvoi un true si calibration bien effectue
*/
boolean calibration(int poidsRef,int moyenne_calibration);
//TODO: faire doc setCalibration fact
void setCalibrationFact(int caliFact);
bool calibration(int poidsRef,int moyenne_calibration);
/**
* @brief tar le capteur de poids
*
* @param[in] val valeur de référence du capteur
* @return true si la tarre a bien réussi (ou si il n'a pas besoins de tarre)
* @return false erreur durrant la tar
*/
bool tar(int val = 0);
private:
/**
* @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci
*/
HX711* capteur;
/**
* @brief true = calibration et false = erreur
*/
boolean initialized;
bool initialized;
/**
* @brief Facteur de calibration obtenu par : (val brute poids ref - val brute poids plexiglas)/ poids ref
*/
int calibrationFact;
/**
* @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci
*/
HX711 scale;
/**
* @brief Valeur moyenne brute du poids sans rien sur la balance juste le plexiglas
*/

View File

@ -0,0 +1,67 @@
#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,...)
* @param[in] fullVal valeur a la quel la poubelle est considéré comme pleine
*/
Capteur(String type, String fullVal);
/**
* @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 revoie la valeur full
*
* @return true la poubelle est pleine
* @return false la poubelle n'est pas pleine
*/
bool isFull();
String getValType();
protected:
/**
* @brief la poubelle est pleinne
* est mis a jours par read()
*/
bool full;
/**
* @brief type de mesure lue (T/H, W, D,...)
*
*/
String type;
/**
* @brief valeur a la quel la poubelle est considéré comme pleine
*
*/
String fullVall;
};
#endif // CAPTEUR_H

View File

@ -0,0 +1,35 @@
#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,...)
* @param fullVal valeur au quel la poubelle est considéré comme pleinne
*/
HumiTemp(int pin, String type, String fullVall);
/**
* @brief lit le capteur d'humi/temp
*
* @return String valeur format "XX/YY" X% et Y°C
*/
String read();
private:
DHT* capteur;
};
#endif //HUMI_TEMP_H

View File

@ -0,0 +1,38 @@
#ifndef ULTRASON_H
#define ULTRASON_H
#include <Arduino.h>
#include <Ultrasonic.h>
#include "Capteur.h"
class Ultrason: public Capteur{
public:
/**
* @brief Construct a new Ultrason object
*
* @param trigeur pin trigeur du capteur ultra son
* @param echo pin echo du capteur ultra son
* @param fullVall valeur a la quel la poubelle est pleine
*/
Ultrason(int trigeur, int echo, String fullVall);
/**
* @brief lit la valeur du capteur ultra son
*
* @return String retour la valeur
*/
String read();
private:
/**
* @brief capteur utiliser ultrason utiliser pour la mesure
*
*/
Ultrasonic* capteur;
};
#endif // ULTRASON_H

View File

@ -0,0 +1,58 @@
#include "../include/Balance.h"
Balance::Balance(int doutPin, int sckPin, String fullVall):
Capteur("W", fullVall){
this->capteur = new HX711();
this->capteur->begin(doutPin, sckPin);
this->initialized = false;
this->capteur->set_scale();
this->capteur->tare();
this->initialVal = 0;
this->calibrationFact = 0;
this->initCalibration();
}
boolean Balance::initCalibration() {
this->capteur->set_scale();
this->capteur->tare();
this->initialVal = this->capteur->read_average(20);
return true;
}
boolean Balance::calibration(int poidsRef,int moyenne_calibration) {
int rawValref = 0; // Valeur brute de plexiglas et poids réf
int tempPoids = 0; // C'est la valeur du poids en grammes calculée grâce au facteur de calibration
rawValref = this->capteur->read_average(moyenne_calibration);
this->calibrationFact = (rawValref - this->initialVal) / poidsRef;
do {
this->capteur->set_scale(calibrationFact);
tempPoids = this->capteur->get_units(5);
if (tempPoids < poidsRef) {
calibrationFact -= 1;
} else if (tempPoids > poidsRef) {
calibrationFact += 1;
}
} while (tempPoids != poidsRef);
return initialized = true;
}
String Balance::read() {
int sortie = (int)this->capteur->get_units();
this->full = sortie > this->fullVall.toInt();
if (this->initialized == true) {
return String(sortie);
} else {
return "0";
}
}
bool Balance::tar(int val){
this->initialized = true;
this->calibrationFact = val;
this->capteur->set_scale(val);
return this->initialized;
}

View File

@ -0,0 +1,22 @@
#include "../include/Capteur.h"
Capteur::Capteur(String type, String fullVall){
this->type = type;
this->fullVall = fullVall;
}
bool Capteur::tar(int val){
return true;
}
bool Capteur::isFull(){
return this->full;
}
String Capteur::getValType(){
return this->type;
}

View File

@ -0,0 +1,26 @@
#include "../include/HumiTemp.h"
HumiTemp::HumiTemp(int pin, String type, String fullVall):
Capteur("H/T",fullVall){
this->capteur = new DHT(pin, type.c_str());
this->capteur->begin();
}
String HumiTemp::read(){
String sortie = "";
int hum = this->capteur->readHumidity(true);
int temp = this->capteur->readTemperature(false,true);
//valeur pour un élevage d'astico de pèche selon chatGPT
if((temp > 20 && temp < 30) && (hum > 60 && hum < 80)){//TODO: passer les valeurs en config
this->full = true;
}else{
this->full = false;
}
sortie += String(hum);
sortie += "/";
sortie += String(temp);
return sortie;
}
//TODO: faire en soirte qu'il y ai un nombre de cycle pour l'aparition d'asticots (entre 1 et 3 jours)

View File

@ -0,0 +1,19 @@
#include "../include/Ultrason.h"
Ultrason::Ultrason(int trigeur, int echo, String fullVall):
Capteur("D",fullVall){
this->capteur = new Ultrasonic(trigeur, echo);
}
String Ultrason::read(){
int sortie = this->capteur->read();
if (sortie < this->fullVall.toInt())
{
this->full = true;
}else{
this->full = false;
}
return String(sortie);
}//TODO: faire en sorte que full se reset avec une autre val

View File

@ -1,41 +1,41 @@
#include "Program.h"
int distance;
Program::Program(){
////////SERIALS//////
Serial1.begin(MONITOR_SPEED);
Serial.begin(MONITOR_SPEED);
Program::Program()
// Serial
Serial.begin(MONITOR_SPEED); // motitor pour debug
Serial1.begin(MONITOR_SPEED); // port serie pour l'esp
///////INITIALISATION OBJ//////
////////API///////
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
this->balance = new Balance(POID_DOUT,POID_SCK);
this->dht = new DHT(DHTPIN, DHTTYPE);
///////INITIALISATION OK//////
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
Serial.print("start calibr : ");
this->balance->initCalibration();
this->balance->setCalibrationFact(1077);
Serial.println("OK");
//this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
dht->begin();
//////CAPTEUR/////
this->ultrasonic = new Ultrason(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO, ULTRA_SOUND_FULL);
this->dht = new HumiTemp(DHTPIN, DHTTYPE, DHT_FULL);
this->balance = new Balance(POID_DOUT,POID_SCK, POID_FULL);
this->balance->tar(1077);
}
void Program::loop(){
distance = this->ultrasonic->read();
String distance = this->ultrasonic->read();
String humitemp = this->dht->read();
String poid = this->balance->read();
this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull());
Serial.print("Distance in CM = " + distance);
Serial.println(this->ultrasonic->isFull()?" true":" false");
//TODO: envoyer les infos des capteur par la suite
this->api->sendValue(humitemp, TRASHCAN_TWO, this->dht->getValType(), this->dht->isFull());
Serial.print("humiTemp = " + humitemp);
Serial.println(this->dht->isFull()?" true":" false");
Serial.println("Temperature = " + String(dht->readTemperature())+" °C");
Serial.println("Humidite = " + String(dht->readHumidity())+" %");
this->api->sendValue(poid, TRASHCAN_THREE, this->balance->getValType(), this->balance->isFull());
Serial.print("poid = " + poid);
Serial.println(this->balance->isFull()?" true":" false");
Serial.println();
//this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false); //TODO: faire estimation poubelle plenne
//this->api->sendValue(this->balance->getValue(), TRASHCAN_TWO, ,false); //TODO: faire estimation poubelle plenne
Serial.print("Distance in CM: ");
Serial.println(distance);
delay(1000);
}

View File

@ -1,47 +1,15 @@
#ifndef TESTING
#include <Arduino.h>
// #include "Program.h"
#include "Program.h"
// Program* program;
// void setup() {
// program = new Program();
// }
// void loop() {
// program->loop();
// }
#include "Balance.h"
Balance *balance;
void setup(){
Serial.begin(MONITOR_SPEED);
balance = new Balance(14,15);
Serial.print("start calibr : ");
balance->initCalibration();
Serial.println("OK");
// Serial.print("posé poids");
// delay(5000);
// Serial.println("OK");
// balance->calibration(500, MOYENNE_CALIBRATION);
// Serial.println("END calibration");
balance->setCalibrationFact(1077);
Program* program;
void setup() {
program = new Program();
program = new Program();
}
void loop(){
// delay(500);
Serial.println(balance->getValue());
void loop() {
program->loop();
}
#endif