feat: 添加 console_simple_init 组件支持,提供可交互控制台功能

This commit is contained in:
Wang Beihong
2026-03-06 12:41:08 +08:00
parent 88a56d541a
commit ae294c0b6a
6 changed files with 364 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES wifi-connect esp_lvgl_port lvgl_st7735s_use i2c_master_messager io_device_control
REQUIRES wifi-connect esp_lvgl_port lvgl_st7735s_use i2c_master_messager io_device_control console_simple_init console
)

View File

@@ -17,3 +17,4 @@ dependencies:
espressif/esp_lvgl_port: ^2.7.2
espressif/bh1750: ^2.0.0
k0i05/esp_ahtxx: ^1.2.7
espressif/console_simple_init: ^1.1.0

View File

@@ -9,6 +9,7 @@
#include "lvgl_st7735s_use.h"
#include "i2c_master_messager.h"
#include "io_device_control.h"
#include "console_simple_init.h" // 提供 console_cmd_user_register 和 console_cmd_all_register
#ifndef CONFIG_I2C_MASTER_MESSAGER_BH1750_ENABLE
#define CONFIG_I2C_MASTER_MESSAGER_BH1750_ENABLE 0
@@ -41,12 +42,23 @@
static const char *TAG = "main";
static int cmd_hello(int argc, char **argv)
{
printf("hello from BotanicalBuddy\n");
return 0;
}
void app_main(void)
{
// 初始化 Wi-Fi 配网组件,支持长按按键进入配网
ESP_ERROR_CHECK(wifi_connect_init());
printf("设备启动完成:长按按键进入配网模式,手机连接 ESP32-* 后访问 http://192.168.4.1\n");
ESP_ERROR_CHECK(console_cmd_init());
ESP_ERROR_CHECK(console_cmd_user_register("hello", cmd_hello));
ESP_ERROR_CHECK(console_cmd_all_register()); // 可选:自动注册插件命令
ESP_ERROR_CHECK(console_cmd_start());
// 启动 LVGL 演示程序,显示简单的界面
ESP_ERROR_CHECK(start_lvgl_demo());
@@ -120,7 +132,6 @@ void app_main(void)
{
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text("Sensor waiting..."));
}
}
else if (i2c_ready)
{