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

Inside sensor namespace

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