feat(log): add LV_LOG_PRINT_CB to set a default log print cb (#6095)

Co-authored-by: Neo Xu <xuxingliang@xiaomi.com>
This commit is contained in:
Gabor Kiss-Vamosi
2024-04-25 17:17:38 +02:00
committed by GitHub
parent 79b64c8bd8
commit addc3f0c73
4 changed files with 28 additions and 12 deletions

View File

@@ -130,7 +130,7 @@
/* Enable native helium assembly to be compiled */ /* Enable native helium assembly to be compiled */
#define LV_USE_NATIVE_HELIUM_ASM 0 #define LV_USE_NATIVE_HELIUM_ASM 0
/* 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only /* 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only
* 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too */ * 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too */
#define LV_DRAW_SW_COMPLEX 1 #define LV_DRAW_SW_COMPLEX 1
@@ -240,6 +240,11 @@
*0: User need to register a callback with `lv_log_register_print_cb()`*/ *0: User need to register a callback with `lv_log_register_print_cb()`*/
#define LV_LOG_PRINTF 0 #define LV_LOG_PRINTF 0
/*Set callback to print the logs.
*E.g `my_print`. The prototype should be `void my_print(lv_log_level_t level, const char * buf)`
*Can be overwritten by `lv_log_register_print_cb`*/
//#define LV_LOG_PRINT_CB
/*1: Enable print timestamp; /*1: Enable print timestamp;
*0: Disable print timestamp*/ *0: Disable print timestamp*/
#define LV_LOG_USE_TIMESTAMP 1 #define LV_LOG_USE_TIMESTAMP 1
@@ -248,6 +253,7 @@
*0: Do not print file and line number of the log*/ *0: Do not print file and line number of the log*/
#define LV_LOG_USE_FILE_LINE 1 #define LV_LOG_USE_FILE_LINE 1
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#define LV_LOG_TRACE_MEM 1 #define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1 #define LV_LOG_TRACE_TIMER 1
@@ -953,10 +959,10 @@
#endif #endif
/*Drivers for LCD devices connected via SPI/parallel port*/ /*Drivers for LCD devices connected via SPI/parallel port*/
#define LV_USE_ST7735 0 #define LV_USE_ST7735 0
#define LV_USE_ST7789 0 #define LV_USE_ST7789 0
#define LV_USE_ST7796 0 #define LV_USE_ST7796 0
#define LV_USE_ILI9341 0 #define LV_USE_ILI9341 0
#define LV_USE_GENERIC_MIPI (LV_USE_ST7735 | LV_USE_ST7789 | LV_USE_ST7796 | LV_USE_ILI9341) #define LV_USE_GENERIC_MIPI (LV_USE_ST7735 | LV_USE_ST7789 | LV_USE_ST7796 | LV_USE_ILI9341)

View File

@@ -360,7 +360,7 @@
#define LV_USE_NATIVE_HELIUM_ASM 0 #define LV_USE_NATIVE_HELIUM_ASM 0
#endif #endif
#endif #endif
/* 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only /* 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only
* 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too */ * 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too */
#ifndef LV_DRAW_SW_COMPLEX #ifndef LV_DRAW_SW_COMPLEX
@@ -616,6 +616,11 @@
#endif #endif
#endif #endif
/*Set callback to print the logs.
*E.g `my_print`. The prototype should be `void my_print(lv_log_level_t level, const char * buf)`
*Can be overwritten by `lv_log_register_print_cb`*/
//#define LV_LOG_PRINT_CB
/*1: Enable print timestamp; /*1: Enable print timestamp;
*0: Disable print timestamp*/ *0: Disable print timestamp*/
#ifndef LV_LOG_USE_TIMESTAMP #ifndef LV_LOG_USE_TIMESTAMP
@@ -644,6 +649,7 @@
#endif #endif
#endif #endif
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#ifndef LV_LOG_TRACE_MEM #ifndef LV_LOG_TRACE_MEM
#ifdef _LV_KCONFIG_PRESENT #ifdef _LV_KCONFIG_PRESENT
@@ -3115,28 +3121,28 @@
#ifdef CONFIG_LV_USE_ST7735 #ifdef CONFIG_LV_USE_ST7735
#define LV_USE_ST7735 CONFIG_LV_USE_ST7735 #define LV_USE_ST7735 CONFIG_LV_USE_ST7735
#else #else
#define LV_USE_ST7735 0 #define LV_USE_ST7735 0
#endif #endif
#endif #endif
#ifndef LV_USE_ST7789 #ifndef LV_USE_ST7789
#ifdef CONFIG_LV_USE_ST7789 #ifdef CONFIG_LV_USE_ST7789
#define LV_USE_ST7789 CONFIG_LV_USE_ST7789 #define LV_USE_ST7789 CONFIG_LV_USE_ST7789
#else #else
#define LV_USE_ST7789 0 #define LV_USE_ST7789 0
#endif #endif
#endif #endif
#ifndef LV_USE_ST7796 #ifndef LV_USE_ST7796
#ifdef CONFIG_LV_USE_ST7796 #ifdef CONFIG_LV_USE_ST7796
#define LV_USE_ST7796 CONFIG_LV_USE_ST7796 #define LV_USE_ST7796 CONFIG_LV_USE_ST7796
#else #else
#define LV_USE_ST7796 0 #define LV_USE_ST7796 0
#endif #endif
#endif #endif
#ifndef LV_USE_ILI9341 #ifndef LV_USE_ILI9341
#ifdef CONFIG_LV_USE_ILI9341 #ifdef CONFIG_LV_USE_ILI9341
#define LV_USE_ILI9341 CONFIG_LV_USE_ILI9341 #define LV_USE_ILI9341 CONFIG_LV_USE_ILI9341
#else #else
#define LV_USE_ILI9341 0 #define LV_USE_ILI9341 0
#endif #endif
#endif #endif

View File

@@ -96,6 +96,11 @@ static inline void lv_global_init(lv_global_t * global)
global->event_last_register_id = _LV_EVENT_LAST; global->event_last_register_id = _LV_EVENT_LAST;
lv_rand_set_seed(0x1234ABCD); lv_rand_set_seed(0x1234ABCD);
#ifdef LV_LOG_PRINT_CB
void LV_LOG_PRINT_CB(lv_log_level_t, const char * txt);
global->custom_log_print_cb = LV_LOG_PRINT_CB;
#endif
#if defined(LV_DRAW_SW_SHADOW_CACHE_SIZE) && LV_DRAW_SW_SHADOW_CACHE_SIZE > 0 #if defined(LV_DRAW_SW_SHADOW_CACHE_SIZE) && LV_DRAW_SW_SHADOW_CACHE_SIZE > 0
global->sw_shadow_cache.cache_size = -1; global->sw_shadow_cache.cache_size = -1;
global->sw_shadow_cache.cache_r = -1; global->sw_shadow_cache.cache_r = -1;

View File

@@ -102,7 +102,7 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
vprintf(format, args); vprintf(format, args);
printf(LOG_FILE_LINE_FMT "\n" LOG_FILE_LINE_EXPR); printf(LOG_FILE_LINE_FMT "\n" LOG_FILE_LINE_EXPR);
fflush(stdout); fflush(stdout);
#else #endif
if(custom_print_cb) { if(custom_print_cb) {
char buf[512]; char buf[512];
char msg[256]; char msg[256];
@@ -111,7 +111,6 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
lvl_prefix[level], LOG_TIMESTAMP_EXPR func, msg LOG_FILE_LINE_EXPR); lvl_prefix[level], LOG_TIMESTAMP_EXPR func, msg LOG_FILE_LINE_EXPR);
custom_print_cb(level, buf); custom_print_cb(level, buf);
} }
#endif
#if LV_LOG_USE_TIMESTAMP #if LV_LOG_USE_TIMESTAMP
last_log_time = t; last_log_time = t;