From ddb1eb7fea96d92b29e7cd42108ab468f6bda870 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 4 Oct 2021 19:15:27 +0200 Subject: [PATCH] Berry and LVGL fixes --- .../default/be_lvgl_ctypes_definitions.c | 78 +++++++++---------- lib/libesp32/Berry/default/be_lvgl_module.c | 2 +- lib/libesp32/Berry/src/be_introspectlib.c | 12 ++- lib/libesp32/Berry/src/be_object.c | 1 + lib/libesp32/Berry/src/be_object.h | 1 + lib/libesp32/Berry/src/be_parser.c | 3 +- lib/libesp32/Berry/src/be_vm.c | 2 +- .../LVGL8/src/extra/widgets/meter/lv_meter.h | 5 +- tasmota/berry/modules/lvgl_ctypes.be | 2 +- tools/lv_berry/convert.py | 1 + 10 files changed, 60 insertions(+), 47 deletions(-) diff --git a/lib/libesp32/Berry/default/be_lvgl_ctypes_definitions.c b/lib/libesp32/Berry/default/be_lvgl_ctypes_definitions.c index a964da83b..219e3e4df 100644 --- a/lib/libesp32/Berry/default/be_lvgl_ctypes_definitions.c +++ b/lib/libesp32/Berry/default/be_lvgl_ctypes_definitions.c @@ -330,77 +330,77 @@ const be_ctypes_structure_t be_lv_meter_scale = { }}; const be_ctypes_structure_t be_lv_meter_indicator = { - 20, /* size in bytes */ + 16, /* size in bytes */ 5, /* number of elements */ be_ctypes_instance_mappings, (const be_ctypes_structure_item_t[5]) { - { "end_value", 16, 0, 0, ctypes_i32, 0 }, - { "opa", 8, 0, 0, ctypes_u8, 0 }, + { "end_value", 12, 0, 0, ctypes_i32, 0 }, + { "opa", 5, 0, 0, ctypes_u8, 0 }, { "scale", 0, 0, 0, ctypes_ptr32, 0 }, - { "start_value", 12, 0, 0, ctypes_i32, 0 }, - { "type", 4, 0, 0, ctypes_i32, 0 }, + { "start_value", 8, 0, 0, ctypes_i32, 0 }, + { "type", 4, 0, 0, ctypes_u8, 0 }, }}; const be_ctypes_structure_t be_lv_meter_indicator_needle_img = { - 28, /* size in bytes */ + 24, /* size in bytes */ 8, /* number of elements */ be_ctypes_instance_mappings, (const be_ctypes_structure_item_t[8]) { - { "end_value", 16, 0, 0, ctypes_i32, 0 }, - { "opa", 8, 0, 0, ctypes_u8, 0 }, - { "pivot_x", 24, 0, 0, ctypes_i16, 0 }, - { "pivot_y", 26, 0, 0, ctypes_i16, 0 }, + { "end_value", 12, 0, 0, ctypes_i32, 0 }, + { "opa", 5, 0, 0, ctypes_u8, 0 }, + { "pivot_x", 20, 0, 0, ctypes_i16, 0 }, + { "pivot_y", 22, 0, 0, ctypes_i16, 0 }, { "scale", 0, 0, 0, ctypes_ptr32, 0 }, - { "src", 20, 0, 0, ctypes_ptr32, 0 }, - { "start_value", 12, 0, 0, ctypes_i32, 0 }, - { "type", 4, 0, 0, ctypes_i32, 0 }, + { "src", 16, 0, 0, ctypes_ptr32, 0 }, + { "start_value", 8, 0, 0, ctypes_i32, 0 }, + { "type", 4, 0, 0, ctypes_u8, 0 }, }}; const be_ctypes_structure_t be_lv_meter_indicator_needle_line = { - 26, /* size in bytes */ + 22, /* size in bytes */ 8, /* number of elements */ be_ctypes_instance_mappings, (const be_ctypes_structure_item_t[8]) { - { "color", 24, 0, 0, ctypes_u16, 1 }, - { "end_value", 16, 0, 0, ctypes_i32, 0 }, - { "opa", 8, 0, 0, ctypes_u8, 0 }, - { "r_mod", 22, 0, 0, ctypes_i16, 0 }, + { "color", 20, 0, 0, ctypes_u16, 1 }, + { "end_value", 12, 0, 0, ctypes_i32, 0 }, + { "opa", 5, 0, 0, ctypes_u8, 0 }, + { "r_mod", 18, 0, 0, ctypes_i16, 0 }, { "scale", 0, 0, 0, ctypes_ptr32, 0 }, - { "start_value", 12, 0, 0, ctypes_i32, 0 }, - { "type", 4, 0, 0, ctypes_i32, 0 }, - { "width", 20, 0, 0, ctypes_u16, 0 }, + { "start_value", 8, 0, 0, ctypes_i32, 0 }, + { "type", 4, 0, 0, ctypes_u8, 0 }, + { "width", 16, 0, 0, ctypes_u16, 0 }, }}; const be_ctypes_structure_t be_lv_meter_indicator_arc = { - 32, /* size in bytes */ + 28, /* size in bytes */ 9, /* number of elements */ be_ctypes_instance_mappings, (const be_ctypes_structure_item_t[9]) { - { "color", 28, 0, 0, ctypes_u16, 1 }, - { "end_value", 16, 0, 0, ctypes_i32, 0 }, - { "opa", 8, 0, 0, ctypes_u8, 0 }, - { "r_mod", 30, 0, 0, ctypes_i16, 0 }, + { "color", 24, 0, 0, ctypes_u16, 1 }, + { "end_value", 12, 0, 0, ctypes_i32, 0 }, + { "opa", 5, 0, 0, ctypes_u8, 0 }, + { "r_mod", 26, 0, 0, ctypes_i16, 0 }, { "scale", 0, 0, 0, ctypes_ptr32, 0 }, - { "src", 24, 0, 0, ctypes_ptr32, 0 }, - { "start_value", 12, 0, 0, ctypes_i32, 0 }, - { "type", 4, 0, 0, ctypes_i32, 0 }, - { "width", 20, 0, 0, ctypes_u16, 0 }, + { "src", 20, 0, 0, ctypes_ptr32, 0 }, + { "start_value", 8, 0, 0, ctypes_i32, 0 }, + { "type", 4, 0, 0, ctypes_u8, 0 }, + { "width", 16, 0, 0, ctypes_u16, 0 }, }}; const be_ctypes_structure_t be_lv_meter_indicator_scale_lines = { - 27, /* size in bytes */ + 23, /* size in bytes */ 9, /* number of elements */ be_ctypes_instance_mappings, (const be_ctypes_structure_item_t[9]) { - { "color_end", 24, 0, 0, ctypes_u16, 1 }, - { "color_start", 22, 0, 0, ctypes_u16, 1 }, - { "end_value", 16, 0, 0, ctypes_i32, 0 }, - { "local_grad", 26, 0, 1, ctypes_bf, 0 }, - { "opa", 8, 0, 0, ctypes_u8, 0 }, + { "color_end", 20, 0, 0, ctypes_u16, 1 }, + { "color_start", 18, 0, 0, ctypes_u16, 1 }, + { "end_value", 12, 0, 0, ctypes_i32, 0 }, + { "local_grad", 22, 0, 1, ctypes_bf, 0 }, + { "opa", 5, 0, 0, ctypes_u8, 0 }, { "scale", 0, 0, 0, ctypes_ptr32, 0 }, - { "start_value", 12, 0, 0, ctypes_i32, 0 }, - { "type", 4, 0, 0, ctypes_i32, 0 }, - { "width_mod", 20, 0, 0, ctypes_i16, 0 }, + { "start_value", 8, 0, 0, ctypes_i32, 0 }, + { "type", 4, 0, 0, ctypes_u8, 0 }, + { "width_mod", 16, 0, 0, ctypes_i16, 0 }, }}; const be_ctypes_structure_t be_lv_obj_class = { diff --git a/lib/libesp32/Berry/default/be_lvgl_module.c b/lib/libesp32/Berry/default/be_lvgl_module.c index 3e8c7fa4e..e4cb5c74a 100644 --- a/lib/libesp32/Berry/default/be_lvgl_module.c +++ b/lib/libesp32/Berry/default/be_lvgl_module.c @@ -86,7 +86,7 @@ const lvbe_call_c_t lv_func[] = { { "refr_now", (void*) &lv_refr_now, "", "(lv_disp)" }, { "scr_act", (void*) &lv_scr_act, "lv_obj", "" }, { "scr_load", (void*) &lv_scr_load, "", "(lv_obj)" }, - { "scr_load_anim", (void*) &lv_scr_load_anim, "", "(lv_obj)(lv_scr_load_anim)iib" }, + { "scr_load_anim", (void*) &lv_scr_load_anim, "", "(lv_obj)iiib" }, { "theme_apply", (void*) &lv_theme_apply, "", "(lv_obj)" }, { "theme_get_color_primary", (void*) &lv_theme_get_color_primary, "lv_color", "(lv_obj)" }, { "theme_get_color_secondary", (void*) &lv_theme_get_color_secondary, "lv_color", "(lv_obj)" }, diff --git a/lib/libesp32/Berry/src/be_introspectlib.c b/lib/libesp32/Berry/src/be_introspectlib.c index 067d9ca3a..cd6b95f55 100644 --- a/lib/libesp32/Berry/src/be_introspectlib.c +++ b/lib/libesp32/Berry/src/be_introspectlib.c @@ -58,12 +58,20 @@ static int m_attrlist(bvm *vm) be_return(vm); } +static void m_findmember_protected(bvm *vm, void* data) +{ + be_getmember(vm, 1, (const char*) data); +} + static int m_findmember(bvm *vm) { int top = be_top(vm); if (top >= 2 && (be_isinstance(vm, 1) || be_ismodule(vm, 1) || be_isclass(vm, 1)) && be_isstring(vm, 2)) { - be_getmember(vm, 1, be_tostring(vm, 2)); - be_return(vm); + int ret = be_execprotected(vm, &m_findmember_protected, (void*) be_tostring(vm, 2)); + if (ret == BE_OK) { + // be_getmember(vm, 1, be_tostring(vm, 2)); + be_return(vm); + } } be_return_nil(vm); } diff --git a/lib/libesp32/Berry/src/be_object.c b/lib/libesp32/Berry/src/be_object.c index c34df0e9a..6c246231c 100644 --- a/lib/libesp32/Berry/src/be_object.c +++ b/lib/libesp32/Berry/src/be_object.c @@ -30,6 +30,7 @@ const char* be_vtype2str(bvalue *v) case BE_INSTANCE: return "instance"; case BE_MODULE: return "module"; case BE_INDEX: return "var"; + case BE_COMPTR: return "ptr"; default: return "invalid type"; } } diff --git a/lib/libesp32/Berry/src/be_object.h b/lib/libesp32/Berry/src/be_object.h index b98718c76..49ac5dbc3 100644 --- a/lib/libesp32/Berry/src/be_object.h +++ b/lib/libesp32/Berry/src/be_object.h @@ -209,6 +209,7 @@ typedef const char* (*breader)(void*, size_t*); #define var_ismap(_v) var_istype(_v, BE_MAP) #define var_ismodule(_v) var_istype(_v, BE_MODULE) #define var_isindex(_v) var_istype(_v, BE_INDEX) +#define var_iscomptr(_v) var_istype(_v, BE_COMPTR) #define var_isnumber(_v) (var_isint(_v) || var_isreal(_v)) #define var_setnil(_v) var_settype(_v, BE_NIL) diff --git a/lib/libesp32/Berry/src/be_parser.c b/lib/libesp32/Berry/src/be_parser.c index 21d4e9ae2..fcef0165a 100644 --- a/lib/libesp32/Berry/src/be_parser.c +++ b/lib/libesp32/Berry/src/be_parser.c @@ -1420,11 +1420,12 @@ static void classdef_stmt(bparser *parser, bclass *c) static void class_inherit(bparser *parser, bexpdesc *e) { if (next_type(parser) == OptColon) { /* ':' */ + bexpdesc ec = *e; /* work on a copy because we preserve original class */ bexpdesc e1; scan_next_token(parser); /* skip ':' */ expr(parser, &e1); check_var(parser, &e1); - be_code_setsuper(parser->finfo, e, &e1); + be_code_setsuper(parser->finfo, &ec, &e1); } } diff --git a/lib/libesp32/Berry/src/be_vm.c b/lib/libesp32/Berry/src/be_vm.c index cbf9b3856..27cd4f685 100644 --- a/lib/libesp32/Berry/src/be_vm.c +++ b/lib/libesp32/Berry/src/be_vm.c @@ -77,7 +77,7 @@ res = var_tobool(a) op var_tobool(b); \ } else if (var_isstr(a)) { /* string op string */ \ res = 1 op be_eqstr(a->v.s, b->v.s); \ - } else if (var_isclass(a) || var_isfunction(a)) { \ + } else if (var_isclass(a) || var_isfunction(a) || var_iscomptr(a)) { \ res = var_toobj(a) op var_toobj(b); \ } else { \ binop_error(vm, #op, a, b); \ diff --git a/lib/libesp32_lvgl/LVGL8/src/extra/widgets/meter/lv_meter.h b/lib/libesp32_lvgl/LVGL8/src/extra/widgets/meter/lv_meter.h index 1151408d7..ccf9a1624 100644 --- a/lib/libesp32_lvgl/LVGL8/src/extra/widgets/meter/lv_meter.h +++ b/lib/libesp32_lvgl/LVGL8/src/extra/widgets/meter/lv_meter.h @@ -46,12 +46,13 @@ typedef struct { int16_t rotation; }lv_meter_scale_t; -typedef enum { +enum { LV_METER_INDICATOR_TYPE_NEEDLE_IMG, LV_METER_INDICATOR_TYPE_NEEDLE_LINE, LV_METER_INDICATOR_TYPE_SCALE_LINES, LV_METER_INDICATOR_TYPE_ARC, -}lv_meter_indicator_type_t; +}; +typedef uint8_t lv_meter_indicator_type_t; typedef struct { lv_meter_scale_t * scale; diff --git a/tasmota/berry/modules/lvgl_ctypes.be b/tasmota/berry/modules/lvgl_ctypes.be index 05615ec27..ee1a0e226 100644 --- a/tasmota/berry/modules/lvgl_ctypes.be +++ b/tasmota/berry/modules/lvgl_ctypes.be @@ -13,7 +13,7 @@ ctypes.print_types() lv_style_int = ctypes.i16 lv_color = [ctypes.u16, "lv_color"] # cast to the class instance, constructor is called with 2 args: (nil, value) lv_grad_dir = ctypes.u8 -lv_meter_indicator_type_t = ctypes.i32 # probablu an anomaly that needs to be fixed +lv_meter_indicator_type_t = ctypes.u8 lv_opa = ctypes.u8 lv_blend_mode = ctypes.u8 lv_align = ctypes.u8 diff --git a/tools/lv_berry/convert.py b/tools/lv_berry/convert.py index d1188ede0..43692d010 100644 --- a/tools/lv_berry/convert.py +++ b/tools/lv_berry/convert.py @@ -96,6 +96,7 @@ return_types = { "lv_style_value_t": "i", "lv_img_src_t": "i", "lv_colorwheel_mode_t": "i", + "lv_scr_load_anim_t": "i", "_lv_event_dsc_t *": "i",