From 5a02050680266b62640db0da2e8ab2354defa589 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 18 Jun 2019 18:13:37 +0200 Subject: [PATCH] Log using printf with a String stored in PROGMEM. Always. --- include/config.sample.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/include/config.sample.h b/include/config.sample.h index 0bf0f96..4ef2c94 100644 --- a/include/config.sample.h +++ b/include/config.sample.h @@ -72,21 +72,39 @@ #define EFFECT_GOL_START_PERCENTAGE 90 #define EFFECT_GOL_BLEND_SPEED 10 #define EFFECT_GOL_RESTART_AFTER_STEPS 100 - + // Stop editing here #ifdef DEBUG #ifdef MQTT_ENABLE #include "my_mqtt.h" - #define LOG(x) mqtt_log(x); Serial.print(x); - #define LOGln(x) mqtt_log_ln(x); Serial.println(x); + #define LOG(msg, ...) do { \ + char buffer[128]; \ + snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\ + mqtt_log(buffer);\ + Serial.print(buffer);\ + } while (0); + #define LOGln(msg, ...) do {\ + char buffer[128]; \ + snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\ + mqtt_log_ln(buffer);\ + Serial.println(buffer);\ + } while (0); #else - #define LOG(x) Serial.print(x); - #define LOGln(x) Serial.println(x); + #define LOG(msg, ...) do { \ + char buffer[128]; \ + snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\ + Serial.print(buffer);\ + } while (0); + #define LOGln(msg, ...) do { \ + char buffer[128]; \ + snprintf_P(buffer, 128, PSTR(msg), ##__VA_ARGS__);\ + Serial.println(buffer);\ + } while (0); #endif #else - #define LOG(x) do {} while(0); - #define LOGln(x) do {} while(0); + #define LOG(msg, ...) do {} while(0); + #define LOGln(msg, ...) do {} while(0); #endif #if !defined( ESP8266 ) && !defined( ESP32 )