Commit 0dad2457 authored by Eric Duminil's avatar Eric Duminil
Browse files

Timer

parent 32f8968b
...@@ -31,6 +31,17 @@ namespace sensor { ...@@ -31,6 +31,17 @@ namespace sensor {
Serial.println(co2); Serial.println(co2);
} }
void setTimer(int32_t timestep) {
if (timestep >= 2 && timestep <= 1800) {
Serial.print(F("Setting Measurement Interval to : "));
Serial.print(timestep);
Serial.println("s.");
sensor::scd30.setMeasurementInterval(timestep);
config::measurement_timestep = timestep;
led_effects::showKITTWheel(color::green, 1);
}
}
void initialize() { void initialize() {
#if defined(ESP8266) #if defined(ESP8266)
Wire.begin(12, 14); // ESP8266 - D6, D5; Wire.begin(12, 14); // ESP8266 - D6, D5;
...@@ -76,6 +87,7 @@ namespace sensor { ...@@ -76,6 +87,7 @@ namespace sensor {
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
sensor_commands::defineCallback("co2", setCO2forDebugging); sensor_commands::defineCallback("co2", setCO2forDebugging);
sensor_commands::defineCallback("timer", setTimer);
} }
//NOTE: should timer deviation be used to adjust measurement_timestep? //NOTE: should timer deviation be used to adjust measurement_timestep?
......
...@@ -55,20 +55,6 @@ namespace mqtt { ...@@ -55,20 +55,6 @@ namespace mqtt {
} }
} }
//TODO: Move all those setters to a separate class, which could be used by Serial/MQTT/WebServer
void setTimer(String messageString) {
messageString.replace("timer ", "");
int timestep = messageString.toInt();
if (timestep >= 2 && timestep <= 1800) {
Serial.print(F("Setting Measurement Interval to : "));
Serial.print(timestep);
Serial.println("s.");
sensor::scd30.setMeasurementInterval(messageString.toInt());
config::measurement_timestep = messageString.toInt();
led_effects::showKITTWheel(color::green, 1);
}
}
void setMQTTinterval(String messageString) { void setMQTTinterval(String messageString) {
messageString.replace("mqtt ", ""); messageString.replace("mqtt ", "");
config::sending_interval = messageString.toInt(); config::sending_interval = messageString.toInt();
...@@ -101,13 +87,6 @@ namespace mqtt { ...@@ -101,13 +87,6 @@ namespace mqtt {
} }
} }
void setCO2forDebugging(String messageString) {
Serial.print(F("DEBUG. Setting CO2 to "));
messageString.replace("co2 ", "");
sensor::co2 = messageString.toInt();
Serial.println(sensor::co2);
}
void sendInfoAboutLocalNetwork() { void sendInfoAboutLocalNetwork() {
char info_topic[60]; // Should be enough for "CO2sensors/ESPd03cc5/info" char info_topic[60]; // Should be enough for "CO2sensors/ESPd03cc5/info"
snprintf(info_topic, sizeof(info_topic), "%s/info", publish_topic.c_str()); snprintf(info_topic, sizeof(info_topic), "%s/info", publish_topic.c_str());
...@@ -146,11 +125,7 @@ namespace mqtt { ...@@ -146,11 +125,7 @@ namespace mqtt {
//TODO: Move this logic to a separate class, which could be used by Serial/MQTT/WebServer //TODO: Move this logic to a separate class, which could be used by Serial/MQTT/WebServer
if (messageString.startsWith("co2 ")) { if (messageString == "calibrate") {
setCO2forDebugging(messageString);
} else if (messageString.startsWith("timer ")) {
setTimer(messageString);
} else if (messageString == "calibrate") {
sensor::startCalibrationProcess(); sensor::startCalibrationProcess();
} else if (messageString.startsWith("calibrate ")) { } else if (messageString.startsWith("calibrate ")) {
calibrateSensorToSpecificPPM(messageString); calibrateSensorToSpecificPPM(messageString);
......
...@@ -5,8 +5,6 @@ namespace sensor_commands { ...@@ -5,8 +5,6 @@ namespace sensor_commands {
const uint8_t MAX_COMMAND_SIZE = 30; const uint8_t MAX_COMMAND_SIZE = 30;
uint8_t callbacks_count = 0; uint8_t callbacks_count = 0;
// A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function.
struct Callback { struct Callback {
Callback(const char *s = 0, void (*f)(int32_t) = 0) : Callback(const char *s = 0, void (*f)(int32_t) = 0) :
name(s), function(f) { name(s), function(f) {
......
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
namespace sensor_commands { namespace sensor_commands {
void run(const char *command); void run(const char *command);
//TODO: Add defineIntCallback?
void defineCallback(const char *command, void (*f)(int32_t)); void defineCallback(const char *command, void (*f)(int32_t));
} }
Supports Markdown
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