diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 436b36b06f85da4a5c031c5d02a8eb31f3b66276..05c4ffc736a0b3b636632e2b1452fde25cfe641d 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 62c597ea82c577179c0814b70d00620df6d04de6..6427647d256696a54fba5b1098ad0205de119218 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 868f37ec30a9c91936c4a8d4305324452e681715..fd04e47280c42a2eea6605409905e49cbb34f4bf 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 cecbcf37a74f3f9d7163e6048a1618f9b58071e5..11d06aecd42cf9ca9f3704067583d592a5e4adce 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)); }