Commit 3ace1b61 authored by Eric Duminil's avatar Eric Duminil
Browse files

Inside sensor namespace

parent 8fa41c6a
...@@ -89,6 +89,7 @@ namespace sensor { ...@@ -89,6 +89,7 @@ namespace sensor {
stable_measurements = 0; stable_measurements = 0;
waiting_color = color::red; waiting_color = color::red;
} }
previous_co2 = co2;
} }
bool updateDataIfAvailable() { bool updateDataIfAvailable() {
...@@ -128,10 +129,10 @@ namespace sensor { ...@@ -128,10 +129,10 @@ namespace sensor {
} }
void getAndSendData() { void getAndSendData() {
bool freshData = sensor::updateDataIfAvailable(); bool freshData = updateDataIfAvailable();
//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 (co2 <= 0) {
// No measurement yet. Waiting. // No measurement yet. Waiting.
LedEffects::showWaitingLED(color::blue); LedEffects::showWaitingLED(color::blue);
return; return;
...@@ -142,20 +143,20 @@ namespace sensor { ...@@ -142,20 +143,20 @@ namespace sensor {
*/ */
if (freshData) { if (freshData) {
countStableMeasurements(); countStableMeasurements();
sensor::timestamp = ntp::getLocalTime(); timestamp = ntp::getLocalTime();
Serial.println(sensor::timestamp); Serial.println(timestamp);
Serial.print(F("co2(ppm): ")); Serial.print(F("co2(ppm): "));
Serial.print(sensor::co2); Serial.print(co2);
Serial.print(F(" temp(C): ")); Serial.print(F(" temp(C): "));
Serial.print(sensor::temperature); Serial.print(temperature);
Serial.print(F(" humidity(%): ")); Serial.print(F(" humidity(%): "));
Serial.println(sensor::humidity); Serial.println(humidity);
csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); csv_writer::logIfTimeHasCome(timestamp, co2, temperature, humidity);
#ifdef MQTT #ifdef MQTT
mqtt::publishIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); mqtt::publishIfTimeHasCome(timestamp, co2, temperature, humidity);
#endif #endif
} }
...@@ -167,7 +168,7 @@ namespace sensor { ...@@ -167,7 +168,7 @@ namespace sensor {
return; return;
} }
if (sensor::co2 < 250) { if (co2 < 250) {
// Sensor should be calibrated. // Sensor should be calibrated.
LedEffects::showWaitingLED(color::magenta); LedEffects::showWaitingLED(color::magenta);
return; return;
...@@ -178,9 +179,9 @@ namespace sensor { ...@@ -178,9 +179,9 @@ namespace sensor {
* Those effects include a short delay. * Those effects include a short delay.
*/ */
if (sensor::co2 < 2000) { if (co2 < 2000) {
LedEffects::displayCO2color(sensor::co2); LedEffects::displayCO2color(co2);
LedEffects::breathe(sensor::co2); LedEffects::breathe(co2);
} else { // >= 2000: entire ring blinks red } else { // >= 2000: entire ring blinks red
LedEffects::redAlert(); LedEffects::redAlert();
} }
......
Supports Markdown
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