Added restart/tare to API and various fixes

This commit is contained in:
Martin Bauer
2020-06-23 21:35:28 +02:00
parent 828e7b3405
commit 7ae434299f
6 changed files with 66 additions and 16 deletions

View File

@@ -8,17 +8,21 @@ class Scale
public:
bool measure(uint16_t &measurementOut)
{
if (hx711_.is_ready())
{
//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
return false;
//}
//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)
@@ -28,10 +32,12 @@ public:
void tare(uint32_t numMeasurementsToAverage = 50)
{
hx711_.read_average(3);
offset_ = hx711_.read_average(numMeasurementsToAverage);
Serial.printf("Tare offset %ld\n", offset_);
}
long &offset() const { return offset_; }
const long &offset() const { return offset_; }
private:
HX711 hx711_;