1,环境说明
芯片:ESP32S3
开发环境:arduino IDE
固件版本:esp32 3.0.3
语言:C\C++
2,移植工程
由于arduino 原生使用C++语言,所以在引用C语言文件时应当做声明。需要在ino文件中,引用letter shell的头文件时使用extern "c"
声明其为C代码。
例如:
cpp
extern “C”
{
#include “shell.h”
#include “shell_cfg.h”
#include “shell_ext.h”
}
不然ino文件无法编译到.c文件。
### 3,在shell中注册函数
在`shell_cmd_list.c`文件下,`#if SHELL_USING_CMD_EXPORT != 1`选择编译语句后声明extern 函数。
例如:
```c ```
#if SHELL_USING_CMD_EXPORT != 1
\\\
extern void func(void);
\\\
#endif
在shell 命令表中注册,函数信息。
在shellCommandList[]
中添加注册信息
c
const ShellCommand shellCommandList[]
{
\
SHELL_CMD_ITEM(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_DISABLE_RETURN,
_cmd, _func, _explain),
\
}
_cmd为命令名称,_func为函数名称,_explain为cmd的解释说明
4,API使用
shellWriteString(Shell*, const char *)
打印信息