Skip to content

Commit

Permalink
Optional to debug every measurement update value
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbles07 committed Oct 20, 2024
1 parent f7e1363 commit 8548d3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/AgValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ bool Measurements::update(MeasurementType type, int val, int ch) {

// Calculate average based on how many elements on the list
temporary->update.avg = temporary->sumValues / (float)temporary->listValues.size();
Serial.printf("%s{%d}: %.2f\n", measurementTypeStr(type), ch, temporary->update.avg);
if (_debug) {
Serial.printf("%s{%d}: %.2f\n", measurementTypeStr(type), ch, temporary->update.avg);
}

return true;
}
Expand Down Expand Up @@ -193,7 +195,9 @@ bool Measurements::update(MeasurementType type, float val, int ch) {

// Calculate average based on how many elements on the list
temporary->update.avg = temporary->sumValues / (float)temporary->listValues.size();
Serial.printf("%s{%d}: %.2f\n", measurementTypeStr(type), ch, temporary->update.avg);
if (_debug) {
Serial.printf("%s{%d}: %.2f\n", measurementTypeStr(type), ch, temporary->update.avg);
}

return true;
}
Expand Down Expand Up @@ -398,7 +402,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
}

String result = JSON.stringify(root);
Serial.printf("\n----\n %s \n-----\n", result.c_str());
Serial.printf("\n---- PAYLOAD\n %s \n-----\n", result.c_str());
return result;
}

Expand Down Expand Up @@ -724,4 +728,6 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem
}

return pms;
}
}

void Measurements::setDebug(bool debug) { _debug = debug; }
16 changes: 13 additions & 3 deletions src/AgValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,20 @@ class Measurements {
*/
float getFloat(MeasurementType type, int ch = 1);

// TODO: update this to using setter
int bootCount;

/**
* build json payload for every measurements
*/
String toString(bool localServer, AgFirmwareMode fwMode, int rssi, AirGradient &ag,
Configuration &config);

/**
* Set to true if want to debug every update value
*/
void setDebug(bool debug);

// TODO: update this to use setter
int bootCount;

private:
// Some declared as an array (channel), because FW_MODE_O_1PPx has two PMS5003T
FloatValue _temperature[2];
Expand All @@ -126,6 +134,8 @@ class Measurements {
IntegerValue _pm_10[2];
IntegerValue _pm_03_pc[2]; // particle count 0.3

bool _debug = false;

/**
* @brief Get PMS5003 firmware version string
*
Expand Down

0 comments on commit 8548d3e

Please sign in to comment.