Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
fa480706
Commit
fa480706
authored
Mar 22, 2022
by
Eric Duminil
Browse files
Variable check timestep
parent
e7139c91
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/co2_sensor.cpp
View file @
fa480706
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment