Added restart/tare to API and various fixes
This commit is contained in:
@@ -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