Commit 2af2eeab authored by Eric Duminil's avatar Eric Duminil
Browse files

Small refactor

parent b28542b7
...@@ -121,16 +121,7 @@ void loop() { ...@@ -121,16 +121,7 @@ void loop() {
/** /**
* GET DATA * GET DATA
*/ */
bool freshData = sensor::scd30.dataAvailable(); // Alternative : close to time-step AND dataAvailable, to avoid asking the sensor too often. bool freshData = sensor::updateDataIfAvailable();
if (freshData) {
//TODO: Move to co2_sensor.cpp
//TODO: Save count of stable measurements
//TODO: Compare time to previous measurements, check that it's not too far away from config::measurement_interval
sensor::co2 = sensor::scd30.getCO2();
sensor::temperature = sensor::scd30.getTemperature();
sensor::humidity = sensor::scd30.getHumidity();
}
//NOTE: Data is available, but it's sometimes erroneous: the sensor outputs zero ppm but non-zero temperature and non-zero humidity. //NOTE: Data is available, but it's sometimes erroneous: the sensor outputs zero ppm but non-zero temperature and non-zero humidity.
if (sensor::co2 <= 0) { if (sensor::co2 <= 0) {
......
...@@ -66,6 +66,18 @@ namespace sensor { ...@@ -66,6 +66,18 @@ namespace sensor {
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
} }
bool updateDataIfAvailable() {
//TODO: Save count of stable measurements
//TODO: Compare time to previous measurements, check that it's not too far away from config::measurement_interval
if (scd30.dataAvailable()) {
co2 = scd30.getCO2();
temperature = scd30.getTemperature();
humidity = scd30.getHumidity();
return true;
}
return false;
}
void waitUntilMeasurementsAreStable() { void waitUntilMeasurementsAreStable() {
//TODO: Refactor completely, in order to avoid very long loop? //TODO: Refactor completely, in order to avoid very long loop?
/** From the sensor documentation: /** From the sensor documentation:
......
...@@ -24,6 +24,7 @@ namespace sensor { ...@@ -24,6 +24,7 @@ namespace sensor {
extern String timestamp; extern String timestamp;
void initialize(); void initialize();
bool updateDataIfAvailable();
void startCalibrationProcess(); void startCalibrationProcess();
} }
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment