feat: 优化用户命令注册方式,添加帮助信息和用法提示
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_check.h"
|
||||
#include "console_simple_init.h"
|
||||
#include "console_user_cmds.h"
|
||||
#include "i2c_master_messager.h"
|
||||
@@ -183,32 +184,43 @@ static int cmd_wifi(int argc, char **argv)
|
||||
|
||||
esp_err_t console_user_cmds_register(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
const esp_console_cmd_t hello_cmd = {
|
||||
.command = "hello",
|
||||
.help = "打印欢迎信息。用法: hello",
|
||||
.func = cmd_hello,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&hello_cmd), "console_user_cmds", "register hello failed");
|
||||
|
||||
ret = console_cmd_user_register("hello", cmd_hello);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
const esp_console_cmd_t sensor_cmd = {
|
||||
.command = "sensor",
|
||||
.help = "打印当前传感器缓存数据。用法: sensor",
|
||||
.func = cmd_sensor,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&sensor_cmd), "console_user_cmds", "register sensor failed");
|
||||
|
||||
ret = console_cmd_user_register("sensor", cmd_sensor);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
const esp_console_cmd_t pump_cmd = {
|
||||
.command = "pump",
|
||||
.help = "控制水泵。用法: pump <on|off>",
|
||||
.hint = "<on|off>",
|
||||
.func = cmd_pump,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&pump_cmd), "console_user_cmds", "register pump failed");
|
||||
|
||||
ret = console_cmd_user_register("pump", cmd_pump);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
const esp_console_cmd_t light_cmd = {
|
||||
.command = "light",
|
||||
.help = "控制补光灯。用法: light <on|off>",
|
||||
.hint = "<on|off>",
|
||||
.func = cmd_light,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&light_cmd), "console_user_cmds", "register light failed");
|
||||
|
||||
ret = console_cmd_user_register("light", cmd_light);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = console_cmd_user_register("wifi", cmd_wifi);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
const esp_console_cmd_t wifi_cmd = {
|
||||
.command = "wifi",
|
||||
.help = "Wi-Fi 状态与控制。用法: wifi <status|start|stop|clear>",
|
||||
.hint = "<status|start|stop|clear>",
|
||||
.func = cmd_wifi,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&wifi_cmd), "console_user_cmds", "register wifi failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user