Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Käppler
ampel-firmware
Commits
d5eeba11
Commit
d5eeba11
authored
Dec 26, 2020
by
Eric Duminil
Browse files
Refactor : fewer dependencies
parent
a9ddfba0
Changes
3
Hide whitespace changes
Inline
Side-by-side
ampel-firmware.ino
View file @
d5eeba11
...
...
@@ -132,7 +132,19 @@ void loop() {
// Short press for night mode, Long press for calibration.
checkFlashButton
();
sensor
::
processData
();
if
(
sensor
::
processData
())
{
#ifdef CSV_WRITER
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#ifdef MQTT
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#if defined(LORAWAN) && defined(ESP32)
lorawan
::
preparePayloadIfTimehasCome
();
#endif
}
uint32_t
duration
=
millis
()
-
t0
;
if
(
duration
>
max_loop_duration
)
{
...
...
co2_sensor.cpp
View file @
d5eeba11
...
...
@@ -95,18 +95,6 @@ namespace sensor {
previous_co2
=
co2
;
}
bool
updateDataIfAvailable
()
{
if
(
scd30
.
dataAvailable
())
{
// checkTimerDeviation();
timestamp
=
ntp
::
getLocalTime
();
co2
=
scd30
.
getCO2
();
temperature
=
scd30
.
getTemperature
();
humidity
=
scd30
.
getHumidity
();
return
true
;
}
return
false
;
}
void
startCalibrationProcess
()
{
/** From the sensor documentation:
* For best results, the sensor has to be run in a stable environment in continuous mode at
...
...
@@ -157,14 +145,25 @@ namespace sensor {
}
}
void
processData
()
{
bool
freshData
=
updateDataIfAvailable
();
/** Gets fresh data if available, checks calibration status, displays CO2 levels.
* Returns true if fresh data is available, for further processing (MQTT)
*/
bool
processData
()
{
bool
freshData
=
scd30
.
dataAvailable
();
if
(
freshData
)
{
// checkTimerDeviation();
timestamp
=
ntp
::
getLocalTime
();
co2
=
scd30
.
getCO2
();
temperature
=
scd30
.
getTemperature
();
humidity
=
scd30
.
getHumidity
();
}
//NOTE: Data is available, but it's sometimes erroneous: the sensor outputs zero ppm but non-zero temperature and non-zero humidity.
if
(
co2
<=
0
)
{
// No measurement yet. Waiting.
LedEffects
::
showWaitingLED
(
color
::
blue
);
return
;
return
false
;
}
/**
...
...
@@ -174,22 +173,7 @@ namespace sensor {
if
(
should_calibrate
)
{
countStableMeasurements
();
}
logToSerial
();
//TODO: Move the 3 back to ampel-firmware.ino and remove headers from co2_sensor.h
#ifdef CSV_WRITER
csv_writer
::
logIfTimeHasCome
(
timestamp
,
co2
,
temperature
,
humidity
);
#endif
#ifdef MQTT
mqtt
::
publishIfTimeHasCome
(
timestamp
,
co2
,
temperature
,
humidity
);
#endif
#if defined(LORAWAN) && defined(ESP32)
lorawan
::
preparePayloadIfTimehasCome
();
#endif
}
if
(
should_calibrate
)
{
...
...
@@ -197,9 +181,10 @@ namespace sensor {
calibrateAndRestart
();
}
LedEffects
::
showWaitingLED
(
waiting_color
);
return
;
return
false
;
}
displayCO2OnLedRing
();
return
freshData
;
}
}
co2_sensor.h
View file @
d5eeba11
...
...
@@ -7,16 +7,8 @@
#include
"config.h"
#include
"led_effects.h"
#include
"util.h"
#include
"csv_writer.h"
// To close filesystem before restart.
#include
<Wire.h>
#ifdef MQTT
# include "mqtt.h"
#endif
#ifdef LORAWAN
# include "lorawan.h"
#endif
namespace
config
{
extern
uint16_t
measurement_timestep
;
// [s] Value between 2 and 1800 (range for SCD30 sensor)
extern
const
bool
auto_calibrate_sensor
;
// [true / false]
...
...
@@ -32,7 +24,7 @@ namespace sensor {
extern
String
timestamp
;
void
initialize
();
void
processData
();
bool
processData
();
void
startCalibrationProcess
();
}
#endif
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