之前写的乱七八糟一大堆2
rt_kprintf()
不能打印浮点数!
//RT官方预留的打印功能rt_kprintf无法输出小数(不知道是不是全部版本都这样,我这里使用的是3.1.4的版本出现这种情况,使用 MCU为stm32。 即 使用类似下方打印输出时,
?
float num = 10.0f;
rt_kprintf("float %.2f\n", num);
//输出的结果并不是
float 10.00
//而是
float %f
/* 查看了下rt_kprintf这个函数的实现方式后发现问题 官方对于这个函数的实现如下 */
void rt_kprintf(const char *fmt, ...)
{
va_list args;
rt_size_t length;
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
va_start(args, fmt);
/* the return value of vsnprintf is the number of bytes that would be
* written to buffer had if the size of the buffer been sufficiently
* large excluding the terminating null byte. If the output string
* would be larger than the rt_log_buf, we have to adjust the output
* length. */
length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
if (length > RT_CONSOLEBUF_SIZE - 1)
length = RT_CONSOLEBUF_SIZE - 1;
关于ulog
其一可以解决打印浮点数的问题
LOG_I("sm9541 fetch pressure is %f, %d\r\n",
sm9541_p / 1000,
sm95_data[0].timestamp);
LOG_I("sm9541 fetch temperature is %f, %d\r\n",
sm9541_t / 100,
sm95_data[1].timestamp);
输出不同等级的log信息 [ output different level log by LOG_X API ]
#define LOG_TAG "example"
#define LOG_LVL LOG_LVL_DBG
#include
LOG_E()
LOG_W()
LOG_D()
/*
* output different level log by LOG_X API
*
* NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the when you want to use LOG_X API.
*
* #define LOG_TAG "example"
* #define LOG_LVL LOG_LVL_DBG
* #include
*
* Then you can using LOG_X API to output log
*
* LOG_D("this is a debug log!");
* LOG_E("this is a error log!");
*/
?
关于编写 .md /markdown文档 (英文输入法下)
markdown ---- 文本标记语言
-
(“ -” + “ ” + 回车)
插入图片
分隔线 “---” + 回车
表格 “|” + “ ” + “|” + “ ” + “|” 等 + 回车
插入代码块 “```” + 回车