Compare commits

...

3 Commits

Author SHA1 Message Date
36dd744da5 add balance to main program 2023-05-02 22:01:20 +02:00
e939ee757d refactor: balance lib 2023-05-02 22:01:10 +02:00
2b318c00f9 fix: add api adresse 2023-05-02 22:00:51 +02:00
5 changed files with 28 additions and 34 deletions

View File

@ -28,11 +28,10 @@ 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 API_HOST=\"iot.epi.cb85.software\"

View File

@ -44,9 +44,7 @@ private:
* @brief capteur poid pour le niveau de remplissage de la poubelle
*
*/
Balance *balance;
//TODO chagé type to capteur
Capteur *balance;
/**
* @brief Réference de l'API pour les calls

View File

@ -53,7 +53,7 @@ private:
/**
* @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci
*/
HX711 scale;
HX711* capteur;
/**
* @brief true = calibration et false = erreur

View File

@ -1,20 +1,23 @@
#include "../include/Balance.h"
Balance::Balance(int doutPin, int sckPin) {
Balance::Balance(int doutPin, int sckPin, String fullVall):
Capteur("W", fullVall){
scale.begin(doutPin, sckPin);
this->capteur = new HX711();
this->capteur->begin(doutPin, sckPin);
this->initialized = false;
scale.set_scale();
scale.tare();
this->capteur->set_scale();
this->capteur->tare();
this->initialVal = 0;
this->calibrationFact = 0;
this->initCalibration();
}
boolean Balance::initCalibration() {
scale.set_scale();
scale.tare();
this->initialVal = scale.read_average(20);
this->capteur->set_scale();
this->capteur->tare();
this->initialVal = this->capteur->read_average(20);
return true;
}
@ -23,11 +26,11 @@ 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);
rawValref = this->capteur->read_average(moyenne_calibration);
this->calibrationFact = (rawValref - this->initialVal) / poidsRef;
do {
scale.set_scale(calibrationFact);
tempPoids = scale.get_units(5);
this->capteur->set_scale(calibrationFact);
tempPoids = this->capteur->get_units(5);
if (tempPoids < poidsRef) {
calibrationFact -= 1;
} else if (tempPoids > poidsRef) {
@ -37,26 +40,17 @@ boolean Balance::calibration(int poidsRef,int moyenne_calibration) {
return initialized = true;
}
double Balance::getAverage(int nbMesure) {
String Balance::read() {
if (initialized == true) {
return scale.get_units(nbMesure);
if (this->initialized == true) {
return String(this->capteur->get_units());
} else {
return 0;
}
}
double Balance::getValue() {
if (initialized == true) {
return scale.get_units();
} else {
return 0;
return "0";
}
}
void Balance::setCalibrationFact(int caliFact){
this->initialized = true;
this->calibrationFact = caliFact;
scale.set_scale(caliFact);
this->capteur->set_scale(caliFact);
}

View File

@ -14,14 +14,14 @@ Program::Program(){
//////CAPTEUR/////
this->ultrasonic = new Ultrason(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO, "10");//TODO: mettre la valeur en config
this->dht = new HumiTemp(DHTPIN, DHTTYPE, "20:30/60:80");//TODO: mettre la valeur en config
//TODO: init balance
//calibration factor : 1077
this->balance = new Balance(POID_DOUT,POID_SCK,"500");//TODO: mettre la valter en donfig
this->balance->tar(1077);
}
void Program::loop(){
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);
@ -32,6 +32,9 @@ void Program::loop(){
Serial.println(this->dht->isFull()?" true":" false");
//TODO: Lire balance
//this->api->sendValue(poid, TRASHCAN_TWO, this->balance->getValType(), this->balance->isFull());
Serial.print("humiTemp = " + this->dht->read());
Serial.println(this->dht->isFull()?" true":" false");
delay(1000);
}