diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 5155cf09587411c3cacf2e795fa28de3b5f174d0..39c90baab92ec423fc28e0c68963924791557bda 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -71,14 +71,15 @@ namespace sensor { Serial.print(F("Auto-calibration is ")); Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); - sensor_console::defineIntCommand("co2", setCO2forDebugging, " 1500 (Sets co2 level, for debugging purposes)"); - sensor_console::defineIntCommand("timer", setTimer, " 30 (Sets measurement interval, in s)"); - sensor_console::defineCommand("calibrate", startCalibrationProcess, " (Starts calibration process)"); + sensor_console::defineIntCommand("co2", setCO2forDebugging, F(" 1500 (Sets co2 level, for debugging purposes)")); + sensor_console::defineIntCommand("timer", setTimer, F(" 30 (Sets measurement interval, in s)")); + sensor_console::defineCommand("calibrate", startCalibrationProcess, F(" (Starts calibration process)")); sensor_console::defineIntCommand("calibrate", calibrateSensorToSpecificPPM, - " 600 (Starts calibration process, to given ppm)"); + F(" 600 (Starts calibration process, to given ppm)")); sensor_console::defineIntCommand("calibrate!", calibrateSensorRightNow, - " 600 (Calibrates right now, to given ppm)"); - sensor_console::defineIntCommand("auto_calibrate", setAutoCalibration, " 0/1 (Disables/enables autocalibration)"); + F(" 600 (Calibrates right now, to given ppm)")); + sensor_console::defineIntCommand("auto_calibrate", setAutoCalibration, + F(" 0/1 (Disables/enables autocalibration)")); } //NOTE: should timer deviation be used to adjust measurement_timestep? diff --git a/ampel-firmware/csv_writer.cpp b/ampel-firmware/csv_writer.cpp index 96042ab6ad5f341950177ac790a7d1cd3327b4df..199d9f39f38e99cd6e641a42e5690e07439522f0 100644 --- a/ampel-firmware/csv_writer.cpp +++ b/ampel-firmware/csv_writer.cpp @@ -115,9 +115,9 @@ namespace csv_writer { showFilesystemContent(); Serial.println(); - sensor_console::defineIntCommand("csv", setCSVinterval, " 60 (Sets CSV writing interval, in s)"); - sensor_console::defineCommand("format_filesystem", formatFilesystem, " (Deletes the whole filesystem)"); - sensor_console::defineCommand("show_csv", showCSVContent, " (Displays the complete CSV file on Serial)"); + sensor_console::defineIntCommand("csv", setCSVinterval, F(" 60 (Sets CSV writing interval, in s)")); + sensor_console::defineCommand("format_filesystem", formatFilesystem, F(" (Deletes the whole filesystem)")); + sensor_console::defineCommand("show_csv", showCSVContent, F(" (Displays the complete CSV file on Serial)")); } File openOrCreate() { diff --git a/ampel-firmware/led_effects.cpp b/ampel-firmware/led_effects.cpp index 54db0ac0684d366d4bc15c3f23e72629a181ce48..ee0fccde5222ecf935dc444d86ed8663d5291a77 100644 --- a/ampel-firmware/led_effects.cpp +++ b/ampel-firmware/led_effects.cpp @@ -74,7 +74,7 @@ namespace led_effects { pixels.begin(); pixels.setBrightness(config::max_brightness); LEDsOff(); - sensor_console::defineCommand("night_mode", toggleNightMode, " (Toggles night mode on/off)"); + sensor_console::defineCommand("night_mode", toggleNightMode, F(" (Toggles night mode on/off)")); } void toggleNightMode() { diff --git a/ampel-firmware/mqtt.cpp b/ampel-firmware/mqtt.cpp index 1037aa5c64a1701bbda39e984ee8ed0904f5cf27..fda75272a905792d62cb38f1e43b53c6bfd464b7 100644 --- a/ampel-firmware/mqtt.cpp +++ b/ampel-firmware/mqtt.cpp @@ -36,9 +36,9 @@ namespace mqtt { // mqttClient.setSocketTimeout(config::mqtt_timeout); //NOTE: somehow doesn't seem to have any effect on connect() mqttClient.setServer(config::mqtt_server, config::mqtt_port); - sensor_console::defineIntCommand("mqtt", setMQTTinterval, " 60 (Sets MQTT sending interval, in s)"); + sensor_console::defineIntCommand("mqtt", setMQTTinterval, F(" 60 (Sets MQTT sending interval, in s)")); sensor_console::defineCommand("local_ip", sendInfoAboutLocalNetwork, - " (Sends local IP and SSID via MQTT. Can be useful to find sensor)"); + F(" (Sends local IP and SSID via MQTT. Can be useful to find sensor)")); } void publish(const char *timestamp, int16_t co2, float temperature, float humidity) { diff --git a/ampel-firmware/sensor_console.cpp b/ampel-firmware/sensor_console.cpp index 92cca5397b84a03db728c8bf0fb6d99a073528d3..fd29d4acc03cfe3bf55cb90ce26d8b245bbccc69 100644 --- a/ampel-firmware/sensor_console.cpp +++ b/ampel-firmware/sensor_console.cpp @@ -19,8 +19,8 @@ namespace sensor_console { Command commands[MAX_COMMANDS]; //NOTE: Probably possible to DRY (with templates?) - //TODO: Allow F-Strings - void defineCommand(const char *name, void (*function)(void), const char *doc) { + void defineCommand(const char *name, void (*function)(void), const __FlashStringHelper *doc_fstring) { + const char *doc = (const char PROGMEM*) doc_fstring; if (commands_count < MAX_COMMANDS) { commands[commands_count].name = name; commands[commands_count].voidFunction = function; @@ -32,7 +32,8 @@ namespace sensor_console { } } - void defineIntCommand(const char *name, void (*function)(int32_t), const char *doc) { + void defineIntCommand(const char *name, void (*function)(int32_t), const __FlashStringHelper *doc_fstring) { + const char *doc = (const char PROGMEM*) doc_fstring; if (commands_count < MAX_COMMANDS) { commands[commands_count].name = name; commands[commands_count].intFunction = function; diff --git a/ampel-firmware/sensor_console.h b/ampel-firmware/sensor_console.h index 0434d484efef93a7c603b63e00bf42f0dc1553b7..e15241416c4ca45d6ad83992cf9609af51f0dc43 100644 --- a/ampel-firmware/sensor_console.h +++ b/ampel-firmware/sensor_console.h @@ -10,8 +10,8 @@ namespace sensor_console { void processSerialInput(const byte in_byte); void runCommand(const char *command); - void defineIntCommand(const char *command, void (*function)(int32_t), const char *doc); - void defineCommand(const char *command, void (*function)(void), const char *doc); + void defineIntCommand(const char *command, void (*function)(int32_t), const __FlashStringHelper *ifsh); + void defineCommand(const char *command, void (*function)(void), const __FlashStringHelper *ifsh); } #endif diff --git a/ampel-firmware/util.cpp b/ampel-firmware/util.cpp index 5ec1556bdb636e409b30ec55fc0941f68e6f8c5e..cc2967b71bb9889de00354db6a6b2bf31812dd3b 100644 --- a/ampel-firmware/util.cpp +++ b/ampel-firmware/util.cpp @@ -67,11 +67,11 @@ void Ampel::showFreeSpace() { Ampel::Ampel() : board(current_board), sensorId("ESP" + macToID()), max_loop_duration(0) { - sensor_console::defineIntCommand("set_time", ntp::setLocalTime, " 1618829570 (Sets time to the given UNIX time)"); - sensor_console::defineCommand("free", Ampel::showFreeSpace, " (Displays available heap space)"); + sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F(" 1618829570 (Sets time to the given UNIX time)")); + sensor_console::defineCommand("free", Ampel::showFreeSpace, F(" (Displays available heap space)")); sensor_console::defineCommand("reset", []() { ESP.restart(); - }, " (Restarts the sensor)"); + }, F(" (Restarts the sensor)")); } Ampel ampel;