feat: création classe abstraite capteur #44

Merged
Clement merged 37 commits from refactor/class-abstraite-capteur into master 2023-05-13 10:58:51 +00:00
2 changed files with 19 additions and 25 deletions
Showing only changes of commit e939ee757d - Show all commits

View File

@ -53,7 +53,7 @@ private:
/** /**
* @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci * @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 * @brief true = calibration et false = erreur

View File

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