Fixed scale tare
This commit is contained in:
@@ -4,14 +4,16 @@
|
||||
class MockScale
|
||||
{
|
||||
public:
|
||||
MockScale( uint16_t valueMin=0, uint16_t valueMax=50)
|
||||
MockScale( uint16_t valueMin=0, uint16_t valueMax=10)
|
||||
: valueMin_(valueMin), valueMax_(valueMax), currentValue_(valueMin), direction(1)
|
||||
{}
|
||||
|
||||
bool measure(uint16_t & measurementOut) {
|
||||
currentValue_ += direction;
|
||||
if ( currentValue_ >= valueMax_)
|
||||
if ( currentValue_ >= valueMax_) {
|
||||
direction = -1;
|
||||
valueMax_ += 2;
|
||||
}
|
||||
else if ( currentValue_ <= valueMin_ )
|
||||
direction = +1;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "HX711.h"
|
||||
#include "ConfigHardware.h"
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
@@ -9,8 +10,11 @@ public:
|
||||
bool measure(uint16_t & measurementOut) {
|
||||
if (hx711_.is_ready())
|
||||
{
|
||||
uint32_t value = hx711_.get_value(MEASUREMENT_AVG_COUNT);
|
||||
measurementOut = (int16_t)(value / DIVIDER);
|
||||
long value = hx711_.read_average(CONFIG_MEASUREMENT_AVG_COUNT) - offset_;
|
||||
if(value > 0)
|
||||
measurementOut = (int16_t)(value / DIVIDER);
|
||||
else
|
||||
measurementOut = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -22,9 +26,10 @@ public:
|
||||
};
|
||||
|
||||
void tare(uint32_t numMeasurementsToAverage=50) {
|
||||
hx711_.tare(numMeasurementsToAverage);
|
||||
offset_ = hx711_.read_average(numMeasurementsToAverage);
|
||||
}
|
||||
|
||||
private:
|
||||
HX711 hx711_;
|
||||
long offset_ = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user