add log interface (lv_log) but still there are no log messages added

This commit is contained in:
Gabor Kiss-Vamosi
2018-07-07 08:54:40 +02:00
parent 48375bb780
commit c4eaa1359d
5 changed files with 173 additions and 0 deletions
+10
View File
@@ -86,6 +86,16 @@
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
/*Log settings*/
#define USE_LV_LOG 1 /*Enable/disable the log module*/
#if USE_LV_LOG
#define LV_LOG_INFO 0 /*1: Log a lot of runtime information*/
#define LV_LOG_WARN 0 /*1: Log is something unexpected happens but succesfully handled*/
#define LV_LOG_ERROR 1 /*1: Log critical error*/
#define LV_LOG_USER 1 /*1: Log user defined/user level things */
#define LV_LOG_PRINTF 0 /*1: Print the log with 'printf'; 0: user need to register a callback*/
#endif /*USE_LV_LOG*/
/*================
* THEME USAGE
*================*/
+8
View File
@@ -62,6 +62,10 @@ static lv_ll_t scr_ll; /*Linked list of screens*/
*/
void lv_init(void)
{
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "lv_init called");
#endif
/*Initialize the lv_misc modules*/
lv_mem_init();
lv_task_init();
@@ -101,6 +105,10 @@ void lv_init(void)
/*Init the input device handling*/
lv_indev_init();
#endif
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "lv_init finished");
#endif
}
/*--------------------
+1
View File
@@ -21,6 +21,7 @@ extern "C" {
#include "../lv_misc/lv_mem.h"
#include "../lv_misc/lv_ll.h"
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_log.h"
/*********************
* DEFINES
+80
View File
@@ -0,0 +1,80 @@
/**
* @file lv_log.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_log.h"
#if USE_LV_LOG
#if LV_LOG_PRINTF
#include <string.h>
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static void (*print_cb)(lv_log_level_t , const char *, uint32_t , const char *);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Register custom print (or anything else) function to call when log is added
* @param f a function pointer:
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
*/
void lv_log_register_print(void f(lv_log_level_t , const char *, uint32_t , const char *))
{
print_cb = f;
}
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param dsc description of the log
*/
void lv_log_add(lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
{
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
if((level == LV_LOG_LEVEL_INFO && LV_LOG_INFO) ||
(level == LV_LOG_LEVEL_WARN && LV_LOG_WARN) ||
(level == LV_LOG_LEVEL_ERROR && LV_LOG_ERROR) ||
(level == LV_LOG_LEVEL_USER && LV_LOG_USER))
{
#if LV_LOG_PRINTF
static const char * lvl_prefix[] = {"Info", "Warn", "Error", "User"};
printf("%s %s:%d: %s\n", lvl_prefix[level], file, line, dsc);
#else
if(print_cb) print_cb(level, file, line, dsc);
#endif
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*USE_LV_LOG*/
+74
View File
@@ -0,0 +1,74 @@
/**
* @file lv_log.h
*
*/
#ifndef LV_LOG_H
#define LV_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../lv_conf.h"
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/
typedef enum
{
LV_LOG_LEVEL_INFO = 0,
LV_LOG_LEVEL_WARN,
LV_LOG_LEVEL_ERROR,
LV_LOG_LEVEL_USER,
_LV_LOG_LEVEL_NUM
}lv_log_level_t;
#if USE_LV_LOG
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Register custom print (or anything else) function to call when log is added
* @param f a function pointer:
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
*/
void lv_log_register_print(void f(lv_log_level_t , const char *, uint32_t , const char *));
/**
* Add a log
* @param level the level of log. (From `lv_log_level_t` enum)
* @param file name of the file when the log added
* @param line line number in the source code where the log added
* @param dsc description of the log
*/
void lv_log_add(lv_log_level_t level, const char * file, uint32_t line, const char * dsc);
/**********************
* MACROS
**********************/
#else /*USE_LV_LOG*/
/*Do nothing if `USE_LV_LOG 0`*/
#define lv_log_add(level, file, line, dsc) {;}
#endif /*USE_LV_LOG*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LOG_H*/