- 在lv_conf.h中定义LV_USE_DEBUG为1
#define LV_USE_DEBUG 1
- 在lv_conf.h中定义LV_USE_LOG为1
#define LV_USE_LOG 1
- 配置打印等级
如果要打印所有的级别,将LV_LOG_LEVEL设成LV_LOG_LEVEL_TRACE,以下是警告及错误级别的信息会打印
* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print_cb`*/
# define LV_LOG_PRINTF 0
五个等级的打印都是调用函数lv_log_add函数,函数实现如下
/**
* 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, int line, const char * dsc)
{
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
if(level >= LV_LOG_LEVEL) {
#if LV_LOG_PRINTF
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
#else
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
#endif
}
}
LV_LOG_PRINTF为0时,调用了函数指针custom_print_cb
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
那么这个函数指针需要指向用户注册的打印接口函数,使用lv_log_register_print_cb函数来注册,函数实现
如下
/**
* Register custom print/write function to call when a log is added.
* It can format its "File path", "Line number" and "Description" as required
* and send the formatted log message to a consol or serial port.
* @param print_cb a function pointer to print a log
*/
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
{
custom_print_cb = print_cb;
}
准备RTT打印相关文件配置,具体可参考https://blog.csdn.net/mygod2008ok/article/details/102926458
- 注册自己的打印函数
lv_log_register_print_cb(my_printf);
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
自己的打印函数
void my_printf(lv_log_level_t level, const char *file, uint32_t line, const char *dsc)
{
NRF_LOG_INFO("level:%d,file:%s,line:%d,dsc:%s",level,file,line,dsc);
}
测试验证,故意将用户数据传入NULL,等下在lv定时器回调操作空指针,引发的一个打印测试
/*Create a line meter*/
lv_obj_t* lmeter;
lmeter = lv_lmeter_create(lv_scr_act(), NULL);
lv_lmeter_set_range(lmeter, 0, 60);
lv_lmeter_set_value(lmeter, 10);
lv_lmeter_set_scale(lmeter, 360, 15);
lv_lmeter_set_style(lmeter, LV_LMETER_STYLE_MAIN,&style_lmeter);
lv_obj_set_size(lmeter, 80, 80);
lv_obj_align(lmeter, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_task_t* t = lv_task_create(line_meter_task, 200, LV_TASK_PRIO_MID, NULL);
lv_task_ready(t);
回调引用空指针引发异常
void line_meter_task(lv_task_t* t)
{
static uint8_t progress;
lv_obj_t* lmeter = t->user_data;
progress += 10;
if (progress == 60)
{
progress = 0;
}
lv_lmeter_set_value(lmeter, progress);
}
烧录并运行,打开RTT Viewer
/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/
#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
#define LV_LOG_LEVEL_NONE 4 /**< Do not log anything*/
#define _LV_LOG_LEVEL_NUM 5 /**< Number of log levels */
找到出错文件lv_debug.c的167行



