From 0dad245798792a69f3a8a4dfa801351ec2f6fc3a Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Fri, 16 Apr 2021 22:45:27 +0200 Subject: [PATCH] Timer --- ampel-firmware/co2_sensor.cpp | 12 ++++++++++++ ampel-firmware/mqtt.cpp | 27 +-------------------------- ampel-firmware/sensor_commands.cpp | 2 -- ampel-firmware/sensor_commands.h | 1 + 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 436b36b..05c4ffc 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -31,6 +31,17 @@ namespace sensor { 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() { #if defined(ESP8266) Wire.begin(12, 14); // ESP8266 - D6, D5; @@ -76,6 +87,7 @@ namespace sensor { Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); sensor_commands::defineCallback("co2", setCO2forDebugging); + sensor_commands::defineCallback("timer", setTimer); } //NOTE: should timer deviation be used to adjust measurement_timestep? diff --git a/ampel-firmware/mqtt.cpp b/ampel-firmware/mqtt.cpp index 62c597e..6427647 100644 --- a/ampel-firmware/mqtt.cpp +++ b/ampel-firmware/mqtt.cpp @@ -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) { messageString.replace("mqtt ", ""); config::sending_interval = messageString.toInt(); @@ -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() { char info_topic[60]; // Should be enough for "CO2sensors/ESPd03cc5/info" snprintf(info_topic, sizeof(info_topic), "%s/info", publish_topic.c_str()); @@ -146,11 +125,7 @@ namespace mqtt { //TODO: Move this logic to a separate class, which could be used by Serial/MQTT/WebServer - if (messageString.startsWith("co2 ")) { - setCO2forDebugging(messageString); - } else if (messageString.startsWith("timer ")) { - setTimer(messageString); - } else if (messageString == "calibrate") { + if (messageString == "calibrate") { sensor::startCalibrationProcess(); } else if (messageString.startsWith("calibrate ")) { calibrateSensorToSpecificPPM(messageString); diff --git a/ampel-firmware/sensor_commands.cpp b/ampel-firmware/sensor_commands.cpp index 868f37e..fd04e47 100644 --- a/ampel-firmware/sensor_commands.cpp +++ b/ampel-firmware/sensor_commands.cpp @@ -5,8 +5,6 @@ namespace sensor_commands { const uint8_t MAX_COMMAND_SIZE = 30; 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 { Callback(const char *s = 0, void (*f)(int32_t) = 0) : name(s), function(f) { diff --git a/ampel-firmware/sensor_commands.h b/ampel-firmware/sensor_commands.h index cecbcf3..11d06ae 100644 --- a/ampel-firmware/sensor_commands.h +++ b/ampel-firmware/sensor_commands.h @@ -7,5 +7,6 @@ namespace sensor_commands { void run(const char *command); + //TODO: Add defineIntCallback? void defineCallback(const char *command, void (*f)(int32_t)); } -- GitLab