Files
Smart-granary-code/main/main.cpp
Wang Beihong 30e95387e5 添加 UI 变量管理并重构主应用程序结构
引入 vars.c 和 vars.h 用于管理与 UI 相关的全局变量。

新增 get_var_weigt_ui 和 set_var_weigt_ui 函数,用于访问和修改 UI 重量变量。

更新 CMakeLists.txt 以包含新的 UI 和 LVGL 依赖项。

将 main.c 转换为 main.cpp 以支持 C++ 特性,并重构了应用程序入口点。

实现了使用 FreeRTOS 定期更新 UI 的 UI 任务。

在 partitions.csv 中创建自定义分区表,用于管理闪存空间。

添加 update_sdkconfig.sh 脚本,自动更新 SDK 配置中的闪存大小和 SPIRAM 设置。

移除旧的 main.c 文件以精简项目结构。
2026-04-20 21:13:00 +08:00

41 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <stdio.h>
#include "wifi-connect.h"
#include "esp_lvgl_port.h" // 包含 LVGL 端口头文件,提供 LVGL 相关的类型定义和函数声明
#include "lvgl_st7789_use.h" // 使用EEZStudio提供的LVGL和ST7789驱动便于后续扩展
#include "ui.h" // 使用EEZStudio提供的ui组件便于后续扩展
#include "vars.h" // 包含全局变量定义和访问函数
/**
* @brief UI 任务函数
*
* 负责定期驱动 UI 刷新,并实现屏幕自动轮播。
*
* @param arg 任务参数(未使用)
*/
static void ui_task(void *arg)
{
(void)arg;
for (;;)
{
lvgl_port_lock(0);
ui_tick();
lvgl_port_unlock();
vTaskDelay(pdMS_TO_TICKS(20));
}
}
extern "C" void app_main(void)
{
ESP_ERROR_CHECK(wifi_connect_init()); // 初始化 Wi-Fi 配网模块
start_lvgl_demo(); // 初始化 LVGL 和 LCD 显示
// 初始化 UI 组件(需在 LVGL 锁内进行对象创建)
lvgl_port_lock(0);
ui_init();
lvgl_port_unlock();
// 创建一个 FreeRTOS 任务来更新 UI 显示(字符串拼接需要更多栈空间)
xTaskCreate(ui_task, "ui_task", 4096, NULL, 10, NULL);
}