Move log to shared component
This commit is contained in:
parent
f83a7d80f7
commit
f4482706bc
14 changed files with 83 additions and 81 deletions
|
|
@ -4,12 +4,12 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef UL_CURSOR_H
|
||||
#define UL_CURSOR_H
|
||||
#ifndef BB_CURSOR_H
|
||||
#define BB_CURSOR_H
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/* Image description of the mouse cursor */
|
||||
extern const lv_img_dsc_t bb_cursor_img_dsc;
|
||||
|
||||
#endif /* UL_CURSOR_H */
|
||||
#endif /* BB_CURSOR_H */
|
||||
|
|
|
|||
48
shared/log.c
Normal file
48
shared/log.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright 2021 Johannes Marbach
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/**
|
||||
* Static variables
|
||||
*/
|
||||
|
||||
static bb_log_level log_level = BB_LOG_LEVEL_ERROR;
|
||||
|
||||
|
||||
/**
|
||||
* Public functions
|
||||
*/
|
||||
|
||||
void bb_log_set_level(bb_log_level level) {
|
||||
log_level = level;
|
||||
}
|
||||
|
||||
void bb_log(bb_log_level level, const char *format, ...) {
|
||||
if (level > log_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
|
||||
size_t l = strlen(format);
|
||||
if (l > 0 && format[l - 1] != '\n') {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void bb_log_print_cb(lv_log_level_t level, const char *msg) {
|
||||
LV_UNUSED(level);
|
||||
bb_log(BB_LOG_LEVEL_VERBOSE, msg);
|
||||
}
|
||||
48
shared/log.h
Normal file
48
shared/log.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright 2021 Johannes Marbach
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BB_LOG_H
|
||||
#define BB_LOG_H
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/**
|
||||
* Log levels
|
||||
*/
|
||||
typedef enum {
|
||||
/* Errors only */
|
||||
BB_LOG_LEVEL_ERROR = 0,
|
||||
/* Warnings and errors */
|
||||
BB_LOG_LEVEL_WARNING = 1,
|
||||
/* Include non-errors in log */
|
||||
BB_LOG_LEVEL_VERBOSE = 2
|
||||
} bb_log_level;
|
||||
|
||||
/**
|
||||
* Set the log level.
|
||||
*
|
||||
* @param level new log level value
|
||||
*/
|
||||
void bb_log_set_level(bb_log_level level);
|
||||
|
||||
/**
|
||||
* Log a message. A newline character is appended unless the message ends in one.
|
||||
*
|
||||
* @param level log level of the message
|
||||
* @param format message format string
|
||||
* @param ... parameters to fill into the format string
|
||||
*/
|
||||
void bb_log(bb_log_level level, const char *format, ...);
|
||||
|
||||
/**
|
||||
* Handle an LVGL log message.
|
||||
*
|
||||
* @param level LVGL log level
|
||||
* @param msg message to print
|
||||
*/
|
||||
void bb_log_print_cb(lv_log_level_t level, const char *msg);
|
||||
|
||||
#endif /* BB_LOG_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue