Commit fa480706 authored by Eric Duminil's avatar Eric Duminil
Browse files

Variable check timestep

parent e7139c91
......@@ -8,7 +8,7 @@
#include "src/lib/S8_UART/s8_uart.h"
namespace config {
const uint16_t measurement_timestep_bootup = 5; // [s] Measurement timestep during acclimatization.
const uint16_t measurement_timestep_bootup = 4; // [s] Measurement timestep during acclimatization.
const uint8_t max_deviation_during_bootup = 20; // [%]
const int8_t max_deviation_during_calibration = 30; // [ppm]
const int16_t timestep_during_calibration = 10; // [s] WARNING: Measurements can be unreliable for timesteps shorter than 10s.
......@@ -33,6 +33,8 @@ namespace sensor {
float humidity = 0;
char timestamp[23];
int16_t stable_measurements = 0;
// I'm not sure it's possible to change S8 measurement interval (constant 4s). But we can check every check_timestep seconds.
uint16_t check_timestep = 0;
/**
* Define sensor states
......@@ -56,7 +58,7 @@ namespace sensor {
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE" };
state current_state = READY;
state current_state = BOOTUP;
void switchState(state);
void setCO2forDebugging(int32_t fakeCo2);
void calibrateSensorToSpecificPPM(int32_t calibrationLevel);
......@@ -92,6 +94,13 @@ namespace sensor {
Serial.print(F("Auto-calibration is "));
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
// S8 has its own timer (constant 4s)
Serial.println();
Serial.print(F("Setting S8 timestep to "));
Serial.print(config::measurement_timestep_bootup);
Serial.println(F(" s during acclimatization."));
check_timestep = config::measurement_timestep_bootup;
sensor_console::defineIntCommand("co2", setCO2forDebugging, F("1500 (Sets co2 level, for debugging)"));
// sensor_console::defineIntCommand("timer", setTimer, F("30 (Sets measurement interval, in s)"));
// sensor_console::defineCommand("calibrate", startCalibrationProcess, F("(Starts calibration process)"));
......@@ -169,6 +178,10 @@ namespace sensor {
}
switchState(READY);
Serial.println(F("Sensor acclimatization finished."));
Serial.print(F("Setting S8 timestep to "));
Serial.print(config::measurement_timestep);
Serial.println(F(" s."));
check_timestep = config::measurement_timestep; // [s]
}
// Check for pre-calibration states first, because we do not want to
......@@ -228,16 +241,11 @@ namespace sensor {
bool processData() {
static unsigned long last_measurement = 0;
unsigned long now = seconds();
// bool freshData = now - last_measurement > config::measurement_timestep;
bool freshData = now - last_measurement > 4;
bool freshData = now - last_measurement > check_timestep;
if (freshData) {
Serial.println("FRESH!");
last_measurement = now;
ntp::getLocalTime(timestamp);
s8.co2 = sensor_S8->get_co2();
Serial.print(s8.co2);
Serial.println(" ppm.");
co2 = s8.co2;
co2 = sensor_S8->get_co2();
temperature = 0.0;
humidity = 0.0;
......
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