-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscd30_sensor.cpp
42 lines (36 loc) · 1.07 KB
/
scd30_sensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "scd30_sensor.h"
#include "debug.h"
#include <Wire.h>
#include <Arduino.h>
#include <SparkFun_SCD30_Arduino_Library.h>
#define TOLERATED_NROF_CONSECUTIVE_ERRORS 3
Scd30Sensor::Scd30Sensor() {
errorCounter = 0;
}
bool Scd30Sensor::setup() {
bool result = scd30.begin();
// make sure SCD30 has data available
delay(2000);
return result;
}
clair_sample_t Scd30Sensor::sampleMeasurements() {
// we're assuming that sampleMeasurements isn't called more often than once
// per 2 s, i.e., data should always be available
if (!scd30.dataAvailable()) {
errorCounter += 1;
PRINT(F("WARNING: no SCD30 data avvailable ("));
PRINT(errorCounter);
PRINTLN(F(")"));
} else {
errorCounter = 0;
}
// the SCD30 library always returns the latest measurement from its cache
clair_sample_t newSample;
newSample.co2ppm = scd30.getCO2();
newSample.temperature = scd30.getTemperature();
newSample.humidity = scd30.getHumidity();
return newSample;
}
bool Scd30Sensor::measurementFailed() {
return errorCounter > TOLERATED_NROF_CONSECUTIVE_ERRORS;
}