From 8548d3e9f47857b97e1d1df0d3d65a8ecca8a6b5 Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Mon, 21 Oct 2024 00:43:04 +0700 Subject: [PATCH] Optional to debug every measurement update value --- src/AgValue.cpp | 14 ++++++++++---- src/AgValue.h | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/AgValue.cpp b/src/AgValue.cpp index ef89944..0b003c6 100644 --- a/src/AgValue.cpp +++ b/src/AgValue.cpp @@ -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; } @@ -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; } @@ -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; } @@ -724,4 +728,6 @@ JSONVar Measurements::buildPMS(AirGradient &ag, int ch, bool allCh, bool withTem } return pms; -} \ No newline at end of file +} + +void Measurements::setDebug(bool debug) { _debug = debug; } \ No newline at end of file diff --git a/src/AgValue.h b/src/AgValue.h index 3dd8f95..27d98b9 100644 --- a/src/AgValue.h +++ b/src/AgValue.h @@ -106,12 +106,20 @@ public: */ 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]; @@ -126,6 +134,8 @@ private: IntegerValue _pm_10[2]; IntegerValue _pm_03_pc[2]; // particle count 0.3 + bool _debug = false; + /** * @brief Get PMS5003 firmware version string *