From a6e2cf0b261ffefa57a922650a4061e5255bd75b Mon Sep 17 00:00:00 2001 From: Ewoud Date: Fri, 7 Apr 2023 13:57:27 +0200 Subject: [PATCH] ARTI-FX: Fix printing to USER_PRINT (if !logToFile) --- usermods/artifx/arti.h | 91 +++++++++++++++++++----------------------- wled00/wled.h | 2 +- 2 files changed, 43 insertions(+), 50 deletions(-) diff --git a/usermods/artifx/arti.h b/usermods/artifx/arti.h index 6ee8420c..9dca7d58 100644 --- a/usermods/artifx/arti.h +++ b/usermods/artifx/arti.h @@ -96,59 +96,52 @@ void artiPrintf(char const * format, ...) va_start(argp, format); - if (!logToFile) - { - //WLEDMM: to be done, check if we can move to USER_PRINTF - #if ARTI_PLATFORM == ARTI_ARDUINO //defined in arti_definition.h e.g. arti_wled.h! - USER_PRINTF(format, argp); //WLEDMM also supporting netprint - #else - vprintf(format, argp); - #endif - - } - else - { - #if ARTI_PLATFORM == ARTI_ARDUINO - // rocket science here! As logfile.printf causes crashes/wrong output we create our own printf here - // logFile.printf(format, argp); - for (size_t i = 0; i < strlen(format); i++) + // if (!logToFile) + // { + // //WLEDMM: not working to use USER_PRINTF here in case of arduino so moving to rocket science part + // vprintf(format, argp); + // } + // else + #if ARTI_PLATFORM == ARTI_ARDUINO + // rocket science here! As logfile.printf causes crashes/wrong output we create our own printf here + // logFile.printf(format, argp); + for (size_t i = 0; i < strlen(format); i++) + { + if (format[i] == '%') { - if (format[i] == '%') + switch (format[i+1]) { - switch (format[i+1]) - { - case 's': - logFile.print(va_arg(argp, const char *)); - break; - case 'u': - logFile.print(va_arg(argp, unsigned int)); - break; - case 'c': - logFile.print((char)va_arg(argp, int)); - break; - case 'f': - logFile.print(va_arg(argp, double)); - break; - case '%': - logFile.print("%"); // in case of %% - break; - default: - va_arg(argp, int); - // logFile.print(x); - logFile.print(format[i]); - logFile.print(format[i+1]); - } - i++; - } - else - { - logFile.print(format[i]); + case 's': + if (logToFile) logFile.print(va_arg(argp, const char *)); else USER_PRINT(va_arg(argp, const char *)); + break; + case 'u': + if (logToFile) logFile.print(va_arg(argp, unsigned int)); else USER_PRINT(va_arg(argp, unsigned int)); + break; + case 'c': + if (logToFile) logFile.print((char)va_arg(argp, int)); else USER_PRINT(va_arg(argp, int)); + break; + case 'f': + if (logToFile) logFile.print(va_arg(argp, double)); else USER_PRINT(va_arg(argp, double)); + break; + case '%': + if (logToFile) logFile.print("%"); else USER_PRINT("%"); // in case of %% + break; + default: + va_arg(argp, int); + // logFile.print(x); + if (logToFile) logFile.print(format[i]); else USER_PRINT(format[i]); + if (logToFile) logFile.print(format[i+1]); else USER_PRINT(format[i+1]); } + i++; + } + else + { + if (logToFile) logFile.print(format[i]); else USER_PRINT(format[i]); } - #else - vfprintf(logFile, format, argp); - #endif - } + } + #else + vfprintf(logFile, format, argp); + #endif va_end(argp); } diff --git a/wled00/wled.h b/wled00/wled.h index 076ab6bd..ff2b0624 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2304070 +#define VERSION 2304071 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG