feat: 更新 README 和主程序,修正 GPIO 控制接口并优化 LCD 显示文本
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
- 串口中文状态日志,便于调试和现场维护
|
- 串口中文状态日志,便于调试和现场维护
|
||||||
- 支持 ST77xx SPI LCD 显示(LVGL)
|
- 支持 ST77xx SPI LCD 显示(LVGL)
|
||||||
- 支持方向/偏移参数化配置,便于后续适配不同屏幕
|
- 支持方向/偏移参数化配置,便于后续适配不同屏幕
|
||||||
- 支持水泵(GPIO1)与光照(GPIO0)控制接口
|
- 支持水泵(GPIO1)与光照(GPIO10)控制接口
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
|
|||||||
@@ -200,9 +200,14 @@ static void app_main_display(void)
|
|||||||
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
|
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
|
||||||
|
|
||||||
s_center_label = lv_label_create(scr);
|
s_center_label = lv_label_create(scr);
|
||||||
lv_label_set_text(s_center_label, "ESP32C3-LVGL1");
|
lv_label_set_text(s_center_label, "BotanicalBuddy\nloading...");
|
||||||
|
lv_label_set_recolor(s_center_label, false);
|
||||||
|
lv_label_set_long_mode(s_center_label, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_size(s_center_label, EXAMPLE_LCD_H_RES - 6, EXAMPLE_LCD_V_RES - 6);
|
||||||
lv_obj_set_style_text_color(s_center_label, lv_color_black(), 0);
|
lv_obj_set_style_text_color(s_center_label, lv_color_black(), 0);
|
||||||
lv_obj_set_style_text_font(s_center_label, &lv_font_unscii_8, 0);
|
lv_obj_set_style_text_font(s_center_label, &lv_font_unscii_16, 0);
|
||||||
|
lv_obj_set_style_text_align(s_center_label, LV_TEXT_ALIGN_CENTER, 0);
|
||||||
|
lv_obj_set_style_pad_all(s_center_label, 0, 0);
|
||||||
lv_obj_align(s_center_label, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(s_center_label, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
|
|||||||
139
main/main.c
139
main/main.c
@@ -44,6 +44,27 @@
|
|||||||
|
|
||||||
static const char *TAG = "main";
|
static const char *TAG = "main";
|
||||||
|
|
||||||
|
static const char *wifi_status_short_str(wifi_connect_status_t status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case WIFI_CONNECT_STATUS_IDLE:
|
||||||
|
return "IDLE";
|
||||||
|
case WIFI_CONNECT_STATUS_PROVISIONING:
|
||||||
|
return "PROV";
|
||||||
|
case WIFI_CONNECT_STATUS_CONNECTING:
|
||||||
|
return "CONN";
|
||||||
|
case WIFI_CONNECT_STATUS_CONNECTED:
|
||||||
|
return "UP";
|
||||||
|
case WIFI_CONNECT_STATUS_FAILED:
|
||||||
|
return "FAIL";
|
||||||
|
case WIFI_CONNECT_STATUS_TIMEOUT:
|
||||||
|
return "TIME";
|
||||||
|
default:
|
||||||
|
return "UNKN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void wait_for_wifi_connected(void)
|
static void wait_for_wifi_connected(void)
|
||||||
{
|
{
|
||||||
const uint32_t timeout_s = 120;
|
const uint32_t timeout_s = 120;
|
||||||
@@ -80,7 +101,7 @@ void app_main(void)
|
|||||||
// 启动 LVGL 演示程序,显示简单的界面
|
// 启动 LVGL 演示程序,显示简单的界面
|
||||||
ESP_ERROR_CHECK(start_lvgl_demo());
|
ESP_ERROR_CHECK(start_lvgl_demo());
|
||||||
|
|
||||||
// 初始化 IO 设备控制组件(GPIO1 水泵,GPIO0 光照,高电平有效)
|
// 初始化 IO 设备控制组件(GPIO1 水泵,GPIO10 光照,高电平有效)
|
||||||
ESP_ERROR_CHECK(io_device_control_init());
|
ESP_ERROR_CHECK(io_device_control_init());
|
||||||
|
|
||||||
i2c_master_messager_config_t i2c_cfg = {
|
i2c_master_messager_config_t i2c_cfg = {
|
||||||
@@ -146,125 +167,19 @@ void app_main(void)
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
cap_soil_sensor_data_t soil_data = {0};
|
cap_soil_sensor_data_t soil_data = {0};
|
||||||
bool soil_ok = false;
|
|
||||||
if (soil_ready && cap_soil_sensor_read(&soil_data) == ESP_OK)
|
if (soil_ready && cap_soil_sensor_read(&soil_data) == ESP_OK)
|
||||||
{
|
{
|
||||||
soil_ok = true;
|
// 读取成功,当前版本仅保留采样流程,显示逻辑由用户自定义。
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_master_messager_data_t sensor_data = {0};
|
i2c_master_messager_data_t sensor_data = {0};
|
||||||
if (i2c_ready && i2c_master_messager_get_data(&sensor_data) == ESP_OK)
|
if (i2c_ready && i2c_master_messager_get_data(&sensor_data) == ESP_OK)
|
||||||
{
|
{
|
||||||
char text[64] = {0};
|
// 读取成功,当前版本仅保留采样流程,显示逻辑由用户自定义。
|
||||||
|
}
|
||||||
|
|
||||||
if (BOTANY_BH1750_ENABLE && BOTANY_AHT30_ENABLE &&
|
// TODO: 在这里实现你自己的 LCD 显示内容与排版。
|
||||||
sensor_data.bh1750.valid && sensor_data.aht30.valid)
|
// ESP_ERROR_CHECK(lvgl_st7735s_set_center_text("custom text"));
|
||||||
{
|
|
||||||
if (soil_ok)
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"L:%.0f S:%.0f%%\nT:%.1f H:%.1f%%",
|
|
||||||
sensor_data.bh1750.lux,
|
|
||||||
soil_data.moisture_percent,
|
|
||||||
sensor_data.aht30.temperature_c,
|
|
||||||
sensor_data.aht30.humidity_rh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"L:%.0f T:%.1fC\nH:%.1f%%",
|
|
||||||
sensor_data.bh1750.lux,
|
|
||||||
sensor_data.aht30.temperature_c,
|
|
||||||
sensor_data.aht30.humidity_rh);
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else if (BOTANY_BH1750_ENABLE && sensor_data.bh1750.valid)
|
|
||||||
{
|
|
||||||
if (soil_ok)
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"Light:%.0f\nSoil:%.0f%%",
|
|
||||||
sensor_data.bh1750.lux,
|
|
||||||
soil_data.moisture_percent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(text, sizeof(text), "Light: %.1f lx", sensor_data.bh1750.lux);
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else if (BOTANY_AHT30_ENABLE && sensor_data.aht30.valid)
|
|
||||||
{
|
|
||||||
if (soil_ok)
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"T:%.1f H:%.1f%%\nSoil:%.0f%%",
|
|
||||||
sensor_data.aht30.temperature_c,
|
|
||||||
sensor_data.aht30.humidity_rh,
|
|
||||||
soil_data.moisture_percent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"T:%.1fC\nH:%.1f%%",
|
|
||||||
sensor_data.aht30.temperature_c,
|
|
||||||
sensor_data.aht30.humidity_rh);
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else if (soil_ok)
|
|
||||||
{
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"Soil:%.0f%%\nADC:%d",
|
|
||||||
soil_data.moisture_percent,
|
|
||||||
soil_data.raw);
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text("Sensor waiting..."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (i2c_ready)
|
|
||||||
{
|
|
||||||
if (soil_ok)
|
|
||||||
{
|
|
||||||
char text[64] = {0};
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"I2C read fail\nSoil:%.0f%%",
|
|
||||||
soil_data.moisture_percent);
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text("Sensor read fail"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (soil_ok)
|
|
||||||
{
|
|
||||||
char text[64] = {0};
|
|
||||||
snprintf(text,
|
|
||||||
sizeof(text),
|
|
||||||
"Soil:%.0f%%\nADC:%d",
|
|
||||||
soil_data.moisture_percent,
|
|
||||||
soil_data.raw);
|
|
||||||
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user