feat: 优化用户命令注册方式,添加帮助信息和用法提示
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "esp_check.h"
|
||||||
#include "console_simple_init.h"
|
#include "console_simple_init.h"
|
||||||
#include "console_user_cmds.h"
|
#include "console_user_cmds.h"
|
||||||
#include "i2c_master_messager.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 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);
|
const esp_console_cmd_t sensor_cmd = {
|
||||||
if (ret != ESP_OK) {
|
.command = "sensor",
|
||||||
return ret;
|
.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);
|
const esp_console_cmd_t pump_cmd = {
|
||||||
if (ret != ESP_OK) {
|
.command = "pump",
|
||||||
return ret;
|
.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);
|
const esp_console_cmd_t light_cmd = {
|
||||||
if (ret != ESP_OK) {
|
.command = "light",
|
||||||
return ret;
|
.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);
|
const esp_console_cmd_t wifi_cmd = {
|
||||||
if (ret != ESP_OK) {
|
.command = "wifi",
|
||||||
return ret;
|
.help = "Wi-Fi 状态与控制。用法: wifi <status|start|stop|clear>",
|
||||||
}
|
.hint = "<status|start|stop|clear>",
|
||||||
|
.func = cmd_wifi,
|
||||||
ret = console_cmd_user_register("wifi", cmd_wifi);
|
};
|
||||||
if (ret != ESP_OK) {
|
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&wifi_cmd), "console_user_cmds", "register wifi failed");
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user