aboutsummaryrefslogtreecommitdiff
path: root/co2.h
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2022-03-27 12:48:36 +0100
committerdakkar <dakkar@thenautilus.net>2022-03-27 12:48:36 +0100
commit3443edf23337fb5d9ce63075ead80c4779cf823a (patch)
tree7010ca3559702ab816686d4fbc9c26f51a3b10c2 /co2.h
parentbattery voltage, move display around (diff)
downloadenv-sensor-3443edf23337fb5d9ce63075ead80c4779cf823a.tar.gz
env-sensor-3443edf23337fb5d9ce63075ead80c4779cf823a.tar.bz2
env-sensor-3443edf23337fb5d9ce63075ead80c4779cf823a.zip
break code into logical components
Diffstat (limited to 'co2.h')
-rw-r--r--co2.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/co2.h b/co2.h
new file mode 100644
index 0000000..ac963f4
--- /dev/null
+++ b/co2.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <Arduino.h>
+
+#include <SensirionI2CScd4x.h>
+#include <Wire.h>
+
+#include "data.h"
+
+class CO2 {
+private:
+ SensirionI2CScd4x scd4x;
+
+public:
+ CO2() : scd4x() {}
+
+ void start() {
+ uint16_t error;
+ char errorMessage[256];
+
+ scd4x.begin(Wire);
+
+ // stop potentially previously started measurement
+ error = scd4x.stopPeriodicMeasurement();
+ if (error) {
+ Serial.print("CO2 stopPeriodicMeasurement() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+
+ error = scd4x.setAutomaticSelfCalibration(1);
+ if (error) {
+ Serial.print("CO2 setAutomaticSelfCalibration() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+
+ // Start Measurement
+ error = scd4x.startPeriodicMeasurement();
+ if (error) {
+ Serial.print("CO2 startPeriodicMeasurement() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+ }
+
+ bool dataReady() {
+ return true;
+ }
+
+ void read(SensorData *data) {
+ uint16_t error;
+ char errorMessage[256];
+
+ error = scd4x.readMeasurement(data->co2, data->temperature, data->humidity);
+ if (error) {
+ Serial.print("CO2 readMeasurement() error: ");
+ errorToString(error, errorMessage, 256);
+ Serial.println(errorMessage);
+ }
+ }
+};