Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 96 additions & 73 deletions packages/project-editor/lvgl/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ export class LVGLBuild extends Build {
fromPage: LVGLWidget[];
fromUserWidgets: Map<Page, LVGLWidget[]>;
} = {
fromPage: [], // all pages share the same Set
fromUserWidgets: new Map() // different Set for each user widget
};
fromPage: [], // all pages share the same Set
fromUserWidgets: new Map() // different Set for each user widget
};

lvglObjectIdentifiers: {
fromPage: Identifiers;
fromUserWidgets: Map<Page, Identifiers>;
} = {
fromPage: {
identifiers: [],
widgetToIdentifier: new Map(),
widgetToAccessor: new Map(),
widgetToIndex: new Map()
},
fromUserWidgets: new Map()
};
fromPage: {
identifiers: [],
widgetToIdentifier: new Map(),
widgetToAccessor: new Map(),
widgetToIndex: new Map()
},
fromUserWidgets: new Map()
};

fileStaticVars: {
id: string;
Expand Down Expand Up @@ -190,7 +190,7 @@ export class LVGLBuild extends Build {
} else {
identifier =
this.assets.map.lvglWidgetGeneratedIdentifiers[
widget.objID
widget.objID
];

if (!identifier) {
Expand All @@ -210,9 +210,8 @@ export class LVGLBuild extends Build {
pageIdentifiers.widgetToAccessor.set(
widget,
isUserWidget
? `((lv_obj_t **)&objects)[startWidgetIndex + ${
pageIdentifiers.identifiers.length - startIndex
}]`
? `((lv_obj_t **)&objects)[startWidgetIndex + ${pageIdentifiers.identifiers.length - startIndex
}]`
: `objects.${prefix + identifier}`
);

Expand All @@ -228,8 +227,8 @@ export class LVGLBuild extends Build {
if (page) {
addIdentifiersForUserWidget(
prefix +
identifier +
USER_WIDGET_IDENTIFIER_SEPARATOR,
identifier +
USER_WIDGET_IDENTIFIER_SEPARATOR,
page,
pageIdentifiers
);
Expand Down Expand Up @@ -1545,14 +1544,12 @@ export class LVGLBuild extends Build {

if (flag) {
build.line(
`int startWidgetIndex = ${
this.getWidgetObjectIndex(lvglWidget) + 1
`int startWidgetIndex = ${this.getWidgetObjectIndex(lvglWidget) + 1
};`
);
} else {
build.line(
`startWidgetIndex += ${
this.getWidgetObjectIndex(lvglWidget) + 1
`startWidgetIndex += ${this.getWidgetObjectIndex(lvglWidget) + 1
};`
);
}
Expand Down Expand Up @@ -1809,8 +1806,7 @@ export class LVGLBuild extends Build {
}
if (font.lvglFallbackFont) {
build.line(
`${this.getFontVariableName(font)}->fallback = &${
font.lvglFallbackFont
`${this.getFontVariableName(font)}->fallback = &${font.lvglFallbackFont
};`
);
}
Expand Down Expand Up @@ -1872,8 +1868,7 @@ export class LVGLBuild extends Build {

build.line("lv_disp_t *dispp = lv_disp_get_default();");
build.line(
`lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), ${
this.project.settings.general.darkTheme ? "true" : "false"
`lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), ${this.project.settings.general.darkTheme ? "true" : "false"
}, LV_FONT_DEFAULT);`
);
build.line("lv_disp_set_theme(dispp, theme);");
Expand Down Expand Up @@ -1912,11 +1907,10 @@ export class LVGLBuild extends Build {
#define EXT_IMG_DESC_T
typedef struct _ext_img_desc_t {
const char *name;
const ${
this.project.settings.build.imageExportMode == "binary"
? "void"
: "lv_img_dsc_t"
} *img_dsc;
const ${this.project.settings.build.imageExportMode == "binary"
? "void"
: "lv_img_dsc_t"
} *img_dsc;
} ext_img_desc_t;
#endif

Expand Down Expand Up @@ -2101,10 +2095,9 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
variable.native
) {
build.line(
`{ NATIVE_VAR_TYPE_${
isEnumType(variable.type)
? "INTEGER"
: variable.type.toUpperCase()
`{ NATIVE_VAR_TYPE_${isEnumType(variable.type)
? "INTEGER"
: variable.type.toUpperCase()
}, ${this.getVariableGetterFunctionName(
variable.name
)}, ${this.getVariableSetterFunctionName(
Expand Down Expand Up @@ -2189,7 +2182,7 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];

if (
lvglStyle.parentStyle?.fullDefinition?.[part]?.[
state
state
]
) {
build.line(
Expand Down Expand Up @@ -2420,13 +2413,13 @@ extern const ext_img_desc_t images[${this.bitmaps.length || 1}];
this.project._store.getAbsoluteFilePath(
destinationFolder
) +
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "images/"
: "") +
output +
".bin",
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "images/"
: "") +
output +
".bin",
Buffer.from(source)
);
} catch (err) {
Expand Down Expand Up @@ -2465,13 +2458,13 @@ ${source}`;
this.project._store.getAbsoluteFilePath(
destinationFolder
) +
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "images/"
: "") +
output +
".c",
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "images/"
: "") +
output +
".c",
source
);
} catch (err) {
Expand Down Expand Up @@ -2522,13 +2515,13 @@ ${source}`;
this.project._store.getAbsoluteFilePath(
destinationFolder
) +
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "fonts/"
: "") +
output +
".bin",
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "fonts/"
: "") +
output +
".bin",
lvglBinaryFile
);
} catch (err) {
Expand All @@ -2553,13 +2546,13 @@ ${source}`;
this.project._store.getAbsoluteFilePath(
destinationFolder
) +
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "fonts/"
: "") +
output +
".c",
"/" +
(this.project.settings.build
.separateFolderForImagesAndFonts
? "fonts/"
: "") +
output +
".c",
lvglSourceFile
);
} catch (err) {
Expand All @@ -2584,27 +2577,27 @@ export async function generateSourceCodeForEezFramework(
) {
try {
await fs.promises.rm(destinationFolderPath + "/eez-flow.cpp");
} catch (err) {}
} catch (err) { }

try {
await fs.promises.rm(destinationFolderPath + "/eez-flow.h");
} catch (err) {}
} catch (err) { }

try {
await fs.promises.rm(destinationFolderPath + "/eez-flow-lz4.c");
} catch (err) {}
} catch (err) { }

try {
await fs.promises.rm(destinationFolderPath + "/eez-flow-lz4.h");
} catch (err) {}
} catch (err) { }

try {
await fs.promises.rm(destinationFolderPath + "/eez-flow-sha256.c");
} catch (err) {}
} catch (err) { }

try {
await fs.promises.rm(destinationFolderPath + "/eez-flow-sha256.h");
} catch (err) {}
} catch (err) { }

if (
!(
Expand All @@ -2628,7 +2621,7 @@ export async function generateSourceCodeForEezFramework(
structs_H,
"utf-8"
);
} catch (err) {}
} catch (err) { }

// post fix ui.h
try {
Expand All @@ -2645,7 +2638,7 @@ export async function generateSourceCodeForEezFramework(
ui_H,
"utf-8"
);
} catch (err) {}
} catch (err) { }

const eezframeworkAmalgamationPath = isDev
? resolve(`${sourceRootDir()}/../resources/eez-framework-amalgamation`)
Expand All @@ -2661,6 +2654,36 @@ export async function generateSourceCodeForEezFramework(
destinationFolderPath + "/eez-flow.h"
);

// Post-fix eez-flow.cpp for LVGL 9.40+ API changes where part is lv_part_t
try {
let eezCPP = await fs.promises.readFile(
destinationFolderPath + "/eez-flow.cpp",
"utf-8"
);

// Replace lv_obj_get_style_* calls that pass integer 0 as part with LV_PART_MAIN
// Example: lv_obj_get_style_opa(obj, 0) -> lv_obj_get_style_opa(obj, LV_PART_MAIN)
eezCPP = eezCPP.replace(
/lv_obj_get_style_([a-zA-Z0-9_]+)\s*\(([^,]+),\s*0\s*\)/g,
(match, prop, objExpr) => `lv_obj_get_style_${prop}(${objExpr}, LV_PART_MAIN)`
);

// Replace lv_obj_set_style_* calls that pass integer 0 as part with LV_PART_MAIN
// Example: lv_obj_set_style_bg_opa(obj, value, 0) -> lv_obj_set_style_bg_opa(obj, value, LV_PART_MAIN)
eezCPP = eezCPP.replace(
/lv_obj_set_style_([a-zA-Z0-9_]+)\s*\(([^,]+),\s*([^,]+),\s*0\s*\)/g,
(match, prop, objExpr, valExpr) => `lv_obj_set_style_${prop}(${objExpr}, ${valExpr}, LV_PART_MAIN)`
);

await fs.promises.writeFile(
destinationFolderPath + "/eez-flow.cpp",
eezCPP,
"utf-8"
);
} catch (err) {
// If anything goes wrong, leave the original as-is
}

let eezH = await fs.promises.readFile(
destinationFolderPath + "/eez-flow.h",
"utf-8"
Expand Down Expand Up @@ -2703,13 +2726,13 @@ export async function generateSourceCodeForEezFramework(
eezH = eezH.replace(
"#define EEZ_FLOW_QUEUE_SIZE 1000",
"#define EEZ_FLOW_QUEUE_SIZE " +
project.settings.build.executionQueueSize
project.settings.build.executionQueueSize
);

eezH = eezH.replace(
"#define EEZ_FLOW_EVAL_STACK_SIZE 20",
"#define EEZ_FLOW_EVAL_STACK_SIZE " +
project.settings.build.expressionEvaluatorStackSize
project.settings.build.expressionEvaluatorStackSize
);

eezH = eezH.replace(
Expand Down