optical/EMBOS/Users/App/workctrl/error.c
2025-09-04 09:45:08 +08:00

82 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "error.h"
#include "console.h"
#ifdef USE_FULL_ASSERT
/*
printf("/033[1;40;32m%s/033[0m",” Hello,world!/n”);
/033 声明了转义序列的开始,然后是 [ 开始定义颜色。后面的 1 定义了高亮显示字符。然后是背景颜色这里面是40表示黑色背景。接着是前景颜色这里面是32表示绿色。我们用 /033[0m 关闭转义序列, /033[0m 是终端默认颜色。
通过上面的介绍,就知道了如何输出彩色字符了。
下面是对于彩色字符颜色的一些定义:
前景 背景 颜色
---------------------------------------
30 40 黑色
31 41 紅色
32 42 綠色
33 43 黃色
34 44 藍色
35 45 紫紅色
36 46 青藍色
37 47 白色
代码 意义
-------------------------
0 终端默认设置
1 高亮显示
4 使用下划线
5 闪烁
7 反白显示
8 不可见
*/
void assert_failed(u8* file, u32 line)
{
#define ERR_OUT_DL (5000*1000) // 等待1秒
int count;
int flag, exit;
flag = 0;
exit = 0;
printf("\r\n");
while(1)
{
count = ERR_OUT_DL;
while(count != 0)
{
count--;
}
if (flag == 0)
{
printf("\033[1;41;32m"); // 回车,设置超级终端背景为红色,字符为绿色
flag = 1;
}
else
{
printf("\033[1;42;31m"); // 设置超级终端背景为黑色,字符为红色
flag = 0;
}
printf(" Wrong parameters value: file %s on line %d\r", file, line);
if (exit != 0)
{
break;
}
}
}
#endif