Restructured full repo

This commit is contained in:
Martin Bauer
2020-06-05 21:41:16 +02:00
parent daa2454e71
commit 9bf3287944
46 changed files with 1913 additions and 107 deletions

View File

@@ -0,0 +1,34 @@
#include <cstdint>
class MockScale
{
public:
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_) {
direction = -1;
valueMax_ += 2;
}
else if ( currentValue_ <= valueMin_ )
direction = +1;
measurementOut = currentValue_;
return true;
}
void begin(uint32_t , uint32_t ) {
};
void tare(uint32_t ) {
}
private:
uint16_t valueMin_;
uint16_t valueMax_;
uint16_t currentValue_;
int direction;
};

View File

@@ -0,0 +1,35 @@
#include "HX711.h"
#include "ConfigHardware.h"
#include <cstdint>
template<int DIVIDER=128>
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
return false;
}
void begin(uint32_t pinDOUT, uint32_t pinSCK) {
hx711_.begin(pinDOUT, pinSCK);
};
void tare(uint32_t numMeasurementsToAverage=50) {
offset_ = hx711_.read_average(numMeasurementsToAverage);
}
private:
HX711 hx711_;
long offset_ = 0;
};