From 7ece72b39a003c9793a77628e93235964c8cfd57 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 2 Apr 2022 12:46:36 +0100 Subject: simple serial command protocol tagged responses, just because --- co2.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'co2.h') 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; + } }; -- cgit v1.2.3