diff options
author | dakkar <dakkar@thenautilus.net> | 2022-03-27 12:48:36 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2022-03-27 12:48:36 +0100 |
commit | 3443edf23337fb5d9ce63075ead80c4779cf823a (patch) | |
tree | 7010ca3559702ab816686d4fbc9c26f51a3b10c2 /co2.h | |
parent | battery voltage, move display around (diff) | |
download | env-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.h | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -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); + } + } +}; |