Added restart/tare to API and various fixes
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <functional>
|
||||
#include "Dtypes.h"
|
||||
|
||||
constexpr int MAX_URI_HANDLERS = 10;
|
||||
constexpr int MAX_URI_HANDLERS = 20;
|
||||
|
||||
esp_err_t rawCallback(httpd_req_t *req);
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
void begin();
|
||||
|
||||
void tare();
|
||||
long tareOffset() const { return scale_.offset(); };
|
||||
void startMeasurements();
|
||||
void stopMeasurements();
|
||||
bool isMeasuring() const { return measuring_; }
|
||||
@@ -51,6 +52,8 @@ SessionManager<SessionT>::SessionManager(int scaleDoutPin, int scaleSckPin, uint
|
||||
template <typename SessionT>
|
||||
void SessionManager<SessionT>::tare()
|
||||
{
|
||||
if(measuring_)
|
||||
stopMeasurements();
|
||||
Serial.println("Beginning tare");
|
||||
scale_.begin(scaleDoutPin_, scaleSckPin_);
|
||||
scale_.tare(CONFIG_TARE_AVG_COUNT);
|
||||
@@ -69,6 +72,8 @@ void SessionManager<SessionT>::begin()
|
||||
template <typename SessionT>
|
||||
void SessionManager<SessionT>::startMeasurements()
|
||||
{
|
||||
if(measuring_ == true)
|
||||
return;
|
||||
measuring_ = true;
|
||||
lastCallTime_ = 0;
|
||||
session_.init(timeClient_.getEpochTime());
|
||||
@@ -77,6 +82,8 @@ void SessionManager<SessionT>::startMeasurements()
|
||||
template <typename SessionT>
|
||||
void SessionManager<SessionT>::stopMeasurements()
|
||||
{
|
||||
if(measuring_ == false)
|
||||
return;
|
||||
session_.finalize();
|
||||
measuring_ = false;
|
||||
}
|
||||
@@ -88,8 +95,11 @@ void SessionManager<SessionT>::iteration()
|
||||
return;
|
||||
|
||||
uint16_t measurement = -1;
|
||||
scale_.measure(measurement);
|
||||
bool measurementDone = false;
|
||||
while(!measurementDone)
|
||||
measurementDone = scale_.measure(measurement);
|
||||
bool addPointSuccessful = session_.addPoint(measurement);
|
||||
Serial.printf("Measured: %d\n", measurement);
|
||||
if (!addPointSuccessful)
|
||||
{
|
||||
Serial.println("Maximum time of session reached - stopping");
|
||||
|
||||
@@ -77,6 +77,10 @@ private:
|
||||
if (portablefs::exists(filename.c_str()))
|
||||
{
|
||||
auto file = portablefs::open(filename.c_str(), "a");
|
||||
file.seek(0, SeekSet);
|
||||
StreamingMsgPackEncoder<portablefs::File> encoder(&file);
|
||||
chunk->sendHeader(encoder, chunk->getStartTime(), 0);
|
||||
|
||||
file.seek(0, SeekEnd);
|
||||
size_t existingMeasurements = (file.size() - ChunkT::valueOffset()) / sizeof(Measurement_T);
|
||||
Serial.printf("Incremental save, existing %d\n", existingMeasurements);
|
||||
|
||||
Reference in New Issue
Block a user