aboutsummaryrefslogtreecommitdiff
path: root/co2.h
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2022-04-02 12:46:36 +0100
committerdakkar <dakkar@thenautilus.net>2022-04-02 12:46:36 +0100
commit7ece72b39a003c9793a77628e93235964c8cfd57 (patch)
tree5c4442b7f4b23ff1287e8c53443a33610ee84046 /co2.h
parentprefix for Serial prints (diff)
downloadenv-sensor-7ece72b39a003c9793a77628e93235964c8cfd57.tar.gz
env-sensor-7ece72b39a003c9793a77628e93235964c8cfd57.tar.bz2
env-sensor-7ece72b39a003c9793a77628e93235964c8cfd57.zip
simple serial command protocol
tagged responses, just because
Diffstat (limited to 'co2.h')
-rw-r--r--co2.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/co2.h b/co2.h
index f75c94c..a6a1480 100644
--- a/co2.h
+++ b/co2.h
@@ -72,4 +72,42 @@ public:
Serial.println(errorMessage);
}
}
+
+ bool serialCommand(const String &tag, const String &command) {
+ if (command.startsWith("setco ")) {
+ uint16_t error;
+ char errorMessage[256];
+
+ uint16_t target = command.substring(6).toInt();
+ uint16_t correction;
+
+ scd4x.stopPeriodicMeasurement();
+ delay(500);
+ error = scd4x.performForcedRecalibration(target, correction);
+ if (error) {
+ Serial.print("! CO2 performForcedRecalibration() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+
+ Serial.print(tag);Serial.print(" setco ");
+ if (correction == 0xFFFF) {
+ Serial.println("failed");
+ }
+ else {
+ Serial.println(correction - 0x8000);
+ }
+
+ error = scd4x.startLowPowerPeriodicMeasurement();
+ if (error) {
+ Serial.print("! CO2 startLowPowerPeriodicMeasurement() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
};