mirror of https://github.com/arendst/Tasmota.git
Merge pull request #14462 from s-hadinger/lv_vararg
LVGL add support for set_text_fmt
This commit is contained in:
commit
cd4bf215a2
|
@ -830,7 +830,7 @@ const be_ntv_func_def_t lv_label_func[] = {
|
||||||
{ "set_long_mode", (void*) &lv_label_set_long_mode, "", "(lv.lv_obj)i" },
|
{ "set_long_mode", (void*) &lv_label_set_long_mode, "", "(lv.lv_obj)i" },
|
||||||
{ "set_recolor", (void*) &lv_label_set_recolor, "", "(lv.lv_obj)b" },
|
{ "set_recolor", (void*) &lv_label_set_recolor, "", "(lv.lv_obj)b" },
|
||||||
{ "set_text", (void*) &lv_label_set_text, "", "(lv.lv_obj)s" },
|
{ "set_text", (void*) &lv_label_set_text, "", "(lv.lv_obj)s" },
|
||||||
{ "set_text_fmt", (void*) &lv_label_set_text_fmt, "", "(lv.lv_obj)s" },
|
{ "set_text_fmt", (void*) &lv_label_set_text_fmt, "", "(lv.lv_obj)s[......]" },
|
||||||
{ "set_text_sel_end", (void*) &lv_label_set_text_sel_end, "", "(lv.lv_obj)i" },
|
{ "set_text_sel_end", (void*) &lv_label_set_text_sel_end, "", "(lv.lv_obj)i" },
|
||||||
{ "set_text_sel_start", (void*) &lv_label_set_text_sel_start, "", "(lv.lv_obj)i" },
|
{ "set_text_sel_start", (void*) &lv_label_set_text_sel_start, "", "(lv.lv_obj)i" },
|
||||||
{ "set_text_static", (void*) &lv_label_set_text_static, "", "(lv.lv_obj)s" },
|
{ "set_text_static", (void*) &lv_label_set_text_static, "", "(lv.lv_obj)s" },
|
||||||
|
@ -893,7 +893,7 @@ const be_ntv_func_def_t lv_table_func[] = {
|
||||||
{ "get_selected_cell", (void*) &lv_table_get_selected_cell, "", "(lv.lv_obj)(lv.uint16)(lv.uint16)" },
|
{ "get_selected_cell", (void*) &lv_table_get_selected_cell, "", "(lv.lv_obj)(lv.uint16)(lv.uint16)" },
|
||||||
{ "has_cell_ctrl", (void*) &lv_table_has_cell_ctrl, "b", "(lv.lv_obj)ii(lv.lv_table_cell_ctrl)" },
|
{ "has_cell_ctrl", (void*) &lv_table_has_cell_ctrl, "b", "(lv.lv_obj)ii(lv.lv_table_cell_ctrl)" },
|
||||||
{ "set_cell_value", (void*) &lv_table_set_cell_value, "", "(lv.lv_obj)iis" },
|
{ "set_cell_value", (void*) &lv_table_set_cell_value, "", "(lv.lv_obj)iis" },
|
||||||
{ "set_cell_value_fmt", (void*) &lv_table_set_cell_value_fmt, "", "(lv.lv_obj)iis" },
|
{ "set_cell_value_fmt", (void*) &lv_table_set_cell_value_fmt, "", "(lv.lv_obj)iis[......]" },
|
||||||
{ "set_col_cnt", (void*) &lv_table_set_col_cnt, "", "(lv.lv_obj)i" },
|
{ "set_col_cnt", (void*) &lv_table_set_col_cnt, "", "(lv.lv_obj)i" },
|
||||||
{ "set_col_width", (void*) &lv_table_set_col_width, "", "(lv.lv_obj)ii" },
|
{ "set_col_width", (void*) &lv_table_set_col_width, "", "(lv.lv_obj)ii" },
|
||||||
{ "set_row_cnt", (void*) &lv_table_set_row_cnt, "", "(lv.lv_obj)i" },
|
{ "set_row_cnt", (void*) &lv_table_set_row_cnt, "", "(lv.lv_obj)i" },
|
||||||
|
|
|
@ -211,6 +211,7 @@ with open(lv_widgets_file) as f:
|
||||||
|
|
||||||
g = parse_func_def.search(l_raw)
|
g = parse_func_def.search(l_raw)
|
||||||
if g:
|
if g:
|
||||||
|
# print(l_raw, g.group(3))
|
||||||
# if match, we parse the line
|
# if match, we parse the line
|
||||||
# Ex: 'void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent);'
|
# Ex: 'void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent);'
|
||||||
ret_type = g.group(1) # return type of the function
|
ret_type = g.group(1) # return type of the function
|
||||||
|
@ -230,37 +231,43 @@ with open(lv_widgets_file) as f:
|
||||||
# convert arguments
|
# convert arguments
|
||||||
c_args = ""
|
c_args = ""
|
||||||
args_raw = [ x.strip(" \t\n\r") for x in g.group(3).split(",") ] # split by comma and strip
|
args_raw = [ x.strip(" \t\n\r") for x in g.group(3).split(",") ] # split by comma and strip
|
||||||
|
# print(args_raw)
|
||||||
for arg_raw in args_raw:
|
for arg_raw in args_raw:
|
||||||
# Ex: 'const lv_obj_t * parent' -> 'const ', 'lv_obj_t', ' * ', 'parent', ''
|
# Ex: 'const lv_obj_t * parent' -> 'const ', 'lv_obj_t', ' * ', 'parent', ''
|
||||||
# Ex: 'bool auto_fit' -> '', 'bool', ' ', 'auto_fit', ''
|
# Ex: 'bool auto_fit' -> '', 'bool', ' ', 'auto_fit', ''
|
||||||
# Ex: 'const lv_coord_t value[]' -> 'const', 'lv_coord_t', '', 'value', '[]'
|
# Ex: 'const lv_coord_t value[]' -> 'const', 'lv_coord_t', '', 'value', '[]'
|
||||||
ga = parse_arg.search(arg_raw)
|
ga = parse_arg.search(arg_raw)
|
||||||
if ga: # parsing ok?
|
# print(f"g={g} ga={ga}")
|
||||||
ga_type = ga.group(2)
|
if ga or arg_raw == '...': # parsing ok? Special case for '...' which can't be captured easily in regex
|
||||||
ga_ptr = ( ga.group(3).strip(" \t\n\r") == "*" ) # boolean
|
if arg_raw != '...':
|
||||||
ga_name = ga.group(4)
|
ga_type = ga.group(2)
|
||||||
ga_array = ga.group(5)
|
ga_ptr = ( ga.group(3).strip(" \t\n\r") == "*" ) # boolean
|
||||||
ga_type_ptr = ga_type
|
ga_name = ga.group(4)
|
||||||
if ga_ptr: ga_type_ptr += " *"
|
ga_array = ga.group(5)
|
||||||
if ga_array: ga_type_ptr += " []"
|
ga_type_ptr = ga_type
|
||||||
if ga_type_ptr in return_types:
|
if ga_ptr: ga_type_ptr += " *"
|
||||||
ga_type = return_types[ga_type_ptr]
|
if ga_array: ga_type_ptr += " []"
|
||||||
else:
|
if ga_type_ptr in return_types:
|
||||||
# remove the trailing '_t' of type name if any
|
ga_type = return_types[ga_type_ptr]
|
||||||
ga_type = re.sub(r"_t$", "", ga_type)
|
|
||||||
|
|
||||||
# if the type is a single letter, we just add it
|
|
||||||
if len(ga_type) == 1 and ga_type != 'c': # callbacks are different
|
|
||||||
c_args += ga_type
|
|
||||||
else:
|
|
||||||
if ga_type.endswith("_cb"):
|
|
||||||
# it's a callback type, we encode it differently
|
|
||||||
if ga_type not in lv_cb_types:
|
|
||||||
lv_cb_types.append(ga_type)
|
|
||||||
c_args += "^" + ga_type + "^"
|
|
||||||
else:
|
else:
|
||||||
# we have a high-level type that we treat as a class name, enclose in parenthesis
|
# remove the trailing '_t' of type name if any
|
||||||
c_args += "(" + "lv." + ga_type + ")"
|
ga_type = re.sub(r"_t$", "", ga_type)
|
||||||
|
|
||||||
|
# if the type is a single letter, we just add it
|
||||||
|
if len(ga_type) == 1 and ga_type != 'c': # callbacks are different
|
||||||
|
c_args += ga_type
|
||||||
|
else:
|
||||||
|
if ga_type.endswith("_cb"):
|
||||||
|
# it's a callback type, we encode it differently
|
||||||
|
if ga_type not in lv_cb_types:
|
||||||
|
lv_cb_types.append(ga_type)
|
||||||
|
c_args += "^" + ga_type + "^"
|
||||||
|
else:
|
||||||
|
# we have a high-level type that we treat as a class name, enclose in parenthesis
|
||||||
|
c_args += "(" + "lv." + ga_type + ")"
|
||||||
|
else:
|
||||||
|
# '...'
|
||||||
|
c_args += "[......]" # allow 6 additional parameters
|
||||||
|
|
||||||
# analyze function name and determine if it needs to be assigned to a specific class
|
# analyze function name and determine if it needs to be assigned to a specific class
|
||||||
func_name = g.group(2)
|
func_name = g.group(2)
|
||||||
|
|
Loading…
Reference in New Issue