添加 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 文件以精简项目结构。
This commit is contained in:
Wang Beihong
2026-04-20 21:13:00 +08:00
parent a1566f3dc6
commit 30e95387e5
33 changed files with 53977 additions and 27 deletions

View File

@@ -0,0 +1,22 @@
{
"files": [
"actions.h",
"eez-flow.cpp",
"eez-flow.h",
"fonts.h",
"images.c",
"images.h",
"screens.c",
"screens.h",
"structs.h",
"styles.c",
"styles.h",
"ui.c",
"ui.h",
"ui_font_chinese32.c",
"ui_font_chinese64.c",
"ui_font_num.c",
"ui_font_num2.c",
"vars.h"
]
}

View File

@@ -0,0 +1,6 @@
idf_component_register(
SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES lvgl esp_lvgl_port
)

14
components/ui/actions.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef EEZ_LVGL_UI_EVENTS_H
#define EEZ_LVGL_UI_EVENTS_H
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_EVENTS_H*/

9901
components/ui/eez-flow.cpp Normal file

File diff suppressed because it is too large Load Diff

4388
components/ui/eez-flow.h Normal file

File diff suppressed because it is too large Load Diff

29
components/ui/fonts.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef EEZ_LVGL_UI_FONTS_H
#define EEZ_LVGL_UI_FONTS_H
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const lv_font_t ui_font_num;
extern const lv_font_t ui_font_num2;
extern const lv_font_t ui_font_chinese64;
extern const lv_font_t ui_font_chinese32;
#ifndef EXT_FONT_DESC_T
#define EXT_FONT_DESC_T
typedef struct _ext_font_desc_t {
const char *name;
const void *font_ptr;
} ext_font_desc_t;
#endif
extern ext_font_desc_t fonts[];
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_FONTS_H*/

5
components/ui/images.c Normal file
View File

@@ -0,0 +1,5 @@
#include "images.h"
const ext_img_desc_t images[1] = {
0
};

24
components/ui/images.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef EEZ_LVGL_UI_IMAGES_H
#define EEZ_LVGL_UI_IMAGES_H
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef EXT_IMG_DESC_T
#define EXT_IMG_DESC_T
typedef struct _ext_img_desc_t {
const char *name;
const lv_img_dsc_t *img_dsc;
} ext_img_desc_t;
#endif
extern const ext_img_desc_t images[1];
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_IMAGES_H*/

189
components/ui/screens.c Normal file
View File

@@ -0,0 +1,189 @@
#include <string.h>
#include "screens.h"
#include "images.h"
#include "fonts.h"
#include "actions.h"
#include "vars.h"
#include "styles.h"
#include "ui.h"
#include <string.h>
objects_t objects;
static const char *screen_names[] = { "Main" };
static const char *object_names[] = { "main", "obj0", "obj1", "obj2" };
//
// Event handlers
//
lv_obj_t *tick_value_change_obj;
//
// Screens
//
void create_screen_main() {
void *flowState = getFlowState(0, 0);
(void)flowState;
lv_obj_t *obj = lv_obj_create(0);
objects.main = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 240, 240);
lv_obj_set_style_bg_color(obj, lv_color_hex(0xff000000), LV_PART_MAIN | LV_STATE_DEFAULT);
{
lv_obj_t *parent_obj = obj;
{
lv_obj_t *obj = lv_label_create(parent_obj);
objects.obj0 = obj;
lv_obj_set_pos(obj, 217, 123);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_style_text_font(obj, &ui_font_num, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(obj, lv_color_hex(0xffffffff), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(obj, "g");
}
{
lv_obj_t *obj = lv_label_create(parent_obj);
objects.obj1 = obj;
lv_obj_set_pos(obj, 5, 94);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_style_text_font(obj, &ui_font_num2, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(obj, lv_color_hex(0xffffe503), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_align(obj, LV_TEXT_ALIGN_RIGHT, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(obj, "");
}
{
lv_obj_t *obj = lv_label_create(parent_obj);
objects.obj2 = obj;
lv_obj_set_pos(obj, 40, 7);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_style_text_font(obj, &ui_font_chinese32, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(obj, lv_color_hex(0xffffffff), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(obj, "智能电子称");
}
}
tick_screen_main();
}
void tick_screen_main() {
void *flowState = getFlowState(0, 0);
(void)flowState;
{
const char *new_val = evalTextProperty(flowState, 2, 3, "Failed to evaluate Text in Label widget");
const char *cur_val = lv_label_get_text(objects.obj1);
if (strcmp(new_val, cur_val) != 0) {
tick_value_change_obj = objects.obj1;
lv_label_set_text(objects.obj1, new_val);
tick_value_change_obj = NULL;
}
}
}
typedef void (*tick_screen_func_t)();
tick_screen_func_t tick_screen_funcs[] = {
tick_screen_main,
};
void tick_screen(int screen_index) {
tick_screen_funcs[screen_index]();
}
void tick_screen_by_id(enum ScreensEnum screenId) {
tick_screen_funcs[screenId - 1]();
}
//
// Fonts
//
ext_font_desc_t fonts[] = {
{ "Num", &ui_font_num },
{ "Num2", &ui_font_num2 },
{ "chinese64", &ui_font_chinese64 },
{ "chinese32", &ui_font_chinese32 },
#if LV_FONT_MONTSERRAT_8
{ "MONTSERRAT_8", &lv_font_montserrat_8 },
#endif
#if LV_FONT_MONTSERRAT_10
{ "MONTSERRAT_10", &lv_font_montserrat_10 },
#endif
#if LV_FONT_MONTSERRAT_12
{ "MONTSERRAT_12", &lv_font_montserrat_12 },
#endif
#if LV_FONT_MONTSERRAT_14
{ "MONTSERRAT_14", &lv_font_montserrat_14 },
#endif
#if LV_FONT_MONTSERRAT_16
{ "MONTSERRAT_16", &lv_font_montserrat_16 },
#endif
#if LV_FONT_MONTSERRAT_18
{ "MONTSERRAT_18", &lv_font_montserrat_18 },
#endif
#if LV_FONT_MONTSERRAT_20
{ "MONTSERRAT_20", &lv_font_montserrat_20 },
#endif
#if LV_FONT_MONTSERRAT_22
{ "MONTSERRAT_22", &lv_font_montserrat_22 },
#endif
#if LV_FONT_MONTSERRAT_24
{ "MONTSERRAT_24", &lv_font_montserrat_24 },
#endif
#if LV_FONT_MONTSERRAT_26
{ "MONTSERRAT_26", &lv_font_montserrat_26 },
#endif
#if LV_FONT_MONTSERRAT_28
{ "MONTSERRAT_28", &lv_font_montserrat_28 },
#endif
#if LV_FONT_MONTSERRAT_30
{ "MONTSERRAT_30", &lv_font_montserrat_30 },
#endif
#if LV_FONT_MONTSERRAT_32
{ "MONTSERRAT_32", &lv_font_montserrat_32 },
#endif
#if LV_FONT_MONTSERRAT_34
{ "MONTSERRAT_34", &lv_font_montserrat_34 },
#endif
#if LV_FONT_MONTSERRAT_36
{ "MONTSERRAT_36", &lv_font_montserrat_36 },
#endif
#if LV_FONT_MONTSERRAT_38
{ "MONTSERRAT_38", &lv_font_montserrat_38 },
#endif
#if LV_FONT_MONTSERRAT_40
{ "MONTSERRAT_40", &lv_font_montserrat_40 },
#endif
#if LV_FONT_MONTSERRAT_42
{ "MONTSERRAT_42", &lv_font_montserrat_42 },
#endif
#if LV_FONT_MONTSERRAT_44
{ "MONTSERRAT_44", &lv_font_montserrat_44 },
#endif
#if LV_FONT_MONTSERRAT_46
{ "MONTSERRAT_46", &lv_font_montserrat_46 },
#endif
#if LV_FONT_MONTSERRAT_48
{ "MONTSERRAT_48", &lv_font_montserrat_48 },
#endif
};
//
//
//
void create_screens() {
eez_flow_init_fonts(fonts, sizeof(fonts) / sizeof(ext_font_desc_t));
// Set default LVGL theme
lv_display_t *dispp = lv_display_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), false, LV_FONT_DEFAULT);
lv_display_set_theme(dispp, theme);
// Initialize screens
eez_flow_init_screen_names(screen_names, sizeof(screen_names) / sizeof(const char *));
eez_flow_init_object_names(object_names, sizeof(object_names) / sizeof(const char *));
// Create screens
create_screen_main();
}

39
components/ui/screens.h Normal file
View File

@@ -0,0 +1,39 @@
#ifndef EEZ_LVGL_UI_SCREENS_H
#define EEZ_LVGL_UI_SCREENS_H
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
// Screens
enum ScreensEnum {
_SCREEN_ID_FIRST = 1,
SCREEN_ID_MAIN = 1,
_SCREEN_ID_LAST = 1
};
typedef struct _objects_t {
lv_obj_t *main;
lv_obj_t *obj0;
lv_obj_t *obj1;
lv_obj_t *obj2;
} objects_t;
extern objects_t objects;
void create_screen_main();
void tick_screen_main();
void tick_screen_by_id(enum ScreensEnum screenId);
void tick_screen(int screen_index);
void create_screens();
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_SCREENS_H*/

13
components/ui/structs.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef EEZ_LVGL_UI_STRUCTS_H
#define EEZ_LVGL_UI_STRUCTS_H
#include "eez-flow.h"
#include <stdint.h>
#include <stdbool.h>
#include "vars.h"
using namespace eez;
#endif /*EEZ_LVGL_UI_STRUCTS_H*/

6
components/ui/styles.c Normal file
View File

@@ -0,0 +1,6 @@
#include "styles.h"
#include "images.h"
#include "fonts.h"
#include "ui.h"
#include "screens.h"

14
components/ui/styles.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef EEZ_LVGL_UI_STYLES_H
#define EEZ_LVGL_UI_STYLES_H
#include <lvgl.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_STYLES_H*/

56
components/ui/ui.c Normal file
View File

@@ -0,0 +1,56 @@
#include "ui.h"
#include "screens.h"
#include "images.h"
#include "actions.h"
#include "vars.h"
// ASSETS DEFINITION
const uint8_t assets[460] = {
0x7E, 0x45, 0x45, 0x5A, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0x00, 0xF0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x54, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 0x00, 0x10, 0x00, 0x00, 0x00,
0x2C, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x30, 0x75, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x31, 0x75, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x30, 0x75, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x30, 0x75, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x00, 0x60, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
native_var_t native_vars[] = {
{ NATIVE_VAR_TYPE_NONE, 0, 0 },
{ NATIVE_VAR_TYPE_FLOAT, get_var_weigt_ui, set_var_weigt_ui },
};
ActionExecFunc actions[] = {
0
};
void ui_init() {
eez_flow_init(assets, sizeof(assets), (lv_obj_t **)&objects, sizeof(objects), images, sizeof(images), actions);
}
void ui_tick() {
eez_flow_tick();
tick_screen(g_currentScreen);
}

21
components/ui/ui.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef EEZ_LVGL_UI_GUI_H
#define EEZ_LVGL_UI_GUI_H
#include <lvgl.h>
#include "eez-flow.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const uint8_t assets[460];
void ui_init();
void ui_tick();
#ifdef __cplusplus
}
#endif
#endif // EEZ_LVGL_UI_GUI_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

3293
components/ui/ui_font_num.c Normal file

File diff suppressed because it is too large Load Diff

11151
components/ui/ui_font_num2.c Normal file

File diff suppressed because it is too large Load Diff

13
components/ui/vars.c Normal file
View File

@@ -0,0 +1,13 @@
#include <string.h>
#include <stdint.h>
#include "vars.h"
float weigt_ui;
float get_var_weigt_ui() {
return weigt_ui;
}
void set_var_weigt_ui(float value) {
weigt_ui = value;
}

28
components/ui/vars.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef EEZ_LVGL_UI_VARS_H
#define EEZ_LVGL_UI_VARS_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// enum declarations
// Flow global variables
enum FlowGlobalVariables {
FLOW_GLOBAL_VARIABLE_NONE
};
// Native global variables
extern float get_var_weigt_ui();
extern void set_var_weigt_ui(float value);
#ifdef __cplusplus
}
#endif
#endif /*EEZ_LVGL_UI_VARS_H*/