diff --git a/IOT/lib/Capteur/include/Balance.h b/IOT/lib/Capteur/include/Balance.h index 9d98c77..7b95342 100644 --- a/IOT/lib/Capteur/include/Balance.h +++ b/IOT/lib/Capteur/include/Balance.h @@ -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 diff --git a/IOT/lib/Capteur/src/Balance.cpp b/IOT/lib/Capteur/src/Balance.cpp index 9858416..07721ae 100644 --- a/IOT/lib/Capteur/src/Balance.cpp +++ b/IOT/lib/Capteur/src/Balance.cpp @@ -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); }