diff options
author | dakkar <dakkar@thenautilus.net> | 2022-04-02 12:46:36 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2022-04-02 12:46:36 +0100 |
commit | 7ece72b39a003c9793a77628e93235964c8cfd57 (patch) | |
tree | 5c4442b7f4b23ff1287e8c53443a33610ee84046 /co2.h | |
parent | prefix for Serial prints (diff) | |
download | env-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.h | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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; + } }; |