Commits (5)
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
namespace config { namespace config {
// Values should be defined in config.h // Values should be defined in config.h
uint16_t measurement_timestep = MEASUREMENT_TIMESTEP; // [s] Value between 2 and 1800 (range for SCD30 sensor) uint16_t measurement_timestep = MEASUREMENT_TIMESTEP; // [s] Value between 2 and 1800 (range for SCD30 sensor)
const uint16_t measurement_timestep_accl = 2; // [s] Measurement timestep during acclimatization const uint16_t measurement_timestep_bootup = 2; // [s] Measurement timestep during acclimatization
const uint16_t altitude_above_sea_level = ALTITUDE_ABOVE_SEA_LEVEL; // [m] const uint16_t altitude_above_sea_level = ALTITUDE_ABOVE_SEA_LEVEL; // [m]
uint16_t co2_calibration_level = ATMOSPHERIC_CO2_CONCENTRATION; // [ppm] uint16_t co2_calibration_level = ATMOSPHERIC_CO2_CONCENTRATION; // [ppm]
int8_t max_deviation_during_calibration = 30; // [ppm] int8_t max_deviation_during_calibration = 30; // [ppm]
int8_t enough_stable_measurements = 60; int8_t enough_stable_measurements = 60;
const uint8_t max_deviation_during_accl = 20; // [%] const uint8_t max_deviation_during_bootup = 20; // [%]
#ifdef TEMPERATURE_OFFSET #ifdef TEMPERATURE_OFFSET
// Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset? // Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset?
// NOTE: Sign isn't relevant. The returned temperature will always be shifted down. // NOTE: Sign isn't relevant. The returned temperature will always be shifted down.
...@@ -36,7 +36,6 @@ namespace sensor { ...@@ -36,7 +36,6 @@ namespace sensor {
* INVALID -> sensor does output invalid CO2 measurements (== 0 ppm) * INVALID -> sensor does output invalid CO2 measurements (== 0 ppm)
* NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm) * NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm)
* PREPARE_CALIBRATION -> forced calibration was initiated, waiting for stable measurements * PREPARE_CALIBRATION -> forced calibration was initiated, waiting for stable measurements
* CALIBRATION -> the sensor does calibrate itself
*/ */
enum state { enum state {
INITIAL, INITIAL,
...@@ -45,8 +44,7 @@ namespace sensor { ...@@ -45,8 +44,7 @@ namespace sensor {
INVALID, INVALID,
NEEDS_CALIBRATION, NEEDS_CALIBRATION,
PREPARE_CALIBRATION_UNSTABLE, PREPARE_CALIBRATION_UNSTABLE,
PREPARE_CALIBRATION_STABLE, PREPARE_CALIBRATION_STABLE
CALIBRATION
}; };
const char *state_names[] = { const char *state_names[] = {
"INITIAL", "INITIAL",
...@@ -55,8 +53,7 @@ namespace sensor { ...@@ -55,8 +53,7 @@ namespace sensor {
"INVALID", "INVALID",
"NEEDS_CALIBRATION", "NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE", "PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE", "PREPARE_CALIBRATION_STABLE" };
"CALIBRATION" };
state current_state = INITIAL; state current_state = INITIAL;
void switchState(state); void switchState(state);
...@@ -106,9 +103,9 @@ namespace sensor { ...@@ -106,9 +103,9 @@ namespace sensor {
//NOTE: The timer seems to be inaccurate, though, possibly depending on voltage. Should it be offset? //NOTE: The timer seems to be inaccurate, though, possibly depending on voltage. Should it be offset?
Serial.println(); Serial.println();
Serial.print(F("Setting SCD30 timestep to ")); Serial.print(F("Setting SCD30 timestep to "));
Serial.print(config::measurement_timestep_accl); Serial.print(config::measurement_timestep_bootup);
Serial.println(" s during acclimatization."); Serial.println(" s during acclimatization.");
scd30.setMeasurementInterval(config::measurement_timestep_accl); // [s] scd30.setMeasurementInterval(config::measurement_timestep_bootup); // [s]
sensor_console::defineIntCommand("co2", setCO2forDebugging, F(" 1500 (Sets co2 level, for debugging purposes)")); sensor_console::defineIntCommand("co2", setCO2forDebugging, F(" 1500 (Sets co2 level, for debugging purposes)"));
sensor_console::defineIntCommand("timer", setTimer, F(" 30 (Sets measurement interval, in s)")); sensor_console::defineIntCommand("timer", setTimer, F(" 30 (Sets measurement interval, in s)"));
...@@ -138,9 +135,7 @@ namespace sensor { ...@@ -138,9 +135,7 @@ namespace sensor {
last_co2 = co2; last_co2 = co2;
// We assume the sensor has acclimated to the environment if measurements // We assume the sensor has acclimated to the environment if measurements
// change less than a specified percentage of the current value. // change less than a specified percentage of the current value.
if (co2 > 0 && (100 * delta / config::max_deviation_during_accl) < co2) { return (co2 > 0 && delta < ((uint32_t)co2 * config::max_deviation_during_bootup / 100));
return true;
} else return false;
} }
bool countStableMeasurements() { bool countStableMeasurements() {
...@@ -173,7 +168,6 @@ namespace sensor { ...@@ -173,7 +168,6 @@ namespace sensor {
} }
void calibrateAndRestart() { void calibrateAndRestart() {
switchState(CALIBRATION);
Serial.print(F("Calibrating SCD30 now...")); Serial.print(F("Calibrating SCD30 now..."));
scd30.setAltitudeCompensation(config::altitude_above_sea_level); scd30.setAltitudeCompensation(config::altitude_above_sea_level);
scd30.setForcedRecalibrationFactor(config::co2_calibration_level); scd30.setForcedRecalibrationFactor(config::co2_calibration_level);
...@@ -215,7 +209,6 @@ namespace sensor { ...@@ -215,7 +209,6 @@ namespace sensor {
Serial.print(config::measurement_timestep); Serial.print(config::measurement_timestep);
Serial.println(" s."); Serial.println(" s.");
scd30.setMeasurementInterval(config::measurement_timestep); // [s] scd30.setMeasurementInterval(config::measurement_timestep); // [s]
switchStateForCurrentPPM(); // Check all other conditions again
} }
// These 'else if' constructs are, strictly speaking, unnecessary, // These 'else if' constructs are, strictly speaking, unnecessary,
// because they are not reached if the previous condition was fulfilled. // because they are not reached if the previous condition was fulfilled.
...@@ -280,8 +273,6 @@ namespace sensor { ...@@ -280,8 +273,6 @@ namespace sensor {
case PREPARE_CALIBRATION_STABLE: case PREPARE_CALIBRATION_STABLE:
led_effects::showWaitingLED(color::green); led_effects::showWaitingLED(color::green);
break; break;
case CALIBRATION: // Nothing to do, will restart soon.
break;
default: default:
Serial.println(F("Encountered unknown sensor state")); // This should not happen. Serial.println(F("Encountered unknown sensor state")); // This should not happen.
} }
......