aboutsummaryrefslogtreecommitdiff
path: root/co2.h
diff options
context:
space:
mode:
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);
+ }
+ }
+};