#include "HX711.h" #include "SwimTrackerConfig.h" #include template class Scale { public: bool measure(uint16_t &measurementOut) { //if (hx711_.is_ready()) //{ long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_; if (value < 0) measurementOut = (int16_t)(-value / DIVIDER); else measurementOut = 0; return true; //} //else { // long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_; // // Serial.printf("Measurement failed %ld\n", value); // return false; //} } void begin(uint32_t pinDOUT, uint32_t pinSCK) { hx711_.begin(pinDOUT, pinSCK); }; void tare(uint32_t numMeasurementsToAverage = 50) { hx711_.read_average(3); offset_ = hx711_.read_average(numMeasurementsToAverage); Serial.printf("Tare offset %ld\n", offset_); } const long &offset() const { return offset_; } private: HX711 hx711_; long offset_ = 0; };