Merge pull request #15615 from s-hadinger/openhasp_dropdown

OpenHASP support for dropdown attributes
This commit is contained in:
s-hadinger 2022-05-13 22:48:07 +02:00 committed by GitHub
commit 078f44eed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 457 additions and 2 deletions

View File

@ -222,6 +222,7 @@ intptr_t be_convert_single_elt(bvm *vm, int idx, const char * arg_type, int *buf
type_ok = (arg_type[0] == '.'); // any type is accepted type_ok = (arg_type[0] == '.'); // any type is accepted
type_ok = type_ok || (arg_type[0] == provided_type && arg_type[1] == 0); // or type is a match (single char only) type_ok = type_ok || (arg_type[0] == provided_type && arg_type[1] == 0); // or type is a match (single char only)
type_ok = type_ok || (ret == 0 && arg_type_len != 1); // or NULL is accepted for an instance type_ok = type_ok || (ret == 0 && arg_type_len != 1); // or NULL is accepted for an instance
type_ok = type_ok || (ret == 0 && arg_type[0] == 's' && arg_type[1] == 0); // accept nil for string, can be dangerous
if (!type_ok) { if (!type_ok) {
be_raisef(vm, "type_error", "Unexpected argument type '%c', expected '%s'", provided_type, arg_type); be_raisef(vm, "type_error", "Unexpected argument type '%c', expected '%s'", provided_type, arg_type);

View File

@ -5144,6 +5144,370 @@ void be_load_lvh_textarea_class(bvm *vm) {
be_pop(vm, 1); be_pop(vm, 1);
} }
/********************************************************************
** Solidified function: get_val
********************************************************************/
be_local_closure(lvh_dropdown_get_val, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("get_selected"),
}),
be_str_literal("get_val"),
&be_const_str_solidified,
( &(const binstruction[ 4]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x7C040200, // 0002 CALL R1 1
0x80040200, // 0003 RET 1 R1
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_direction
********************************************************************/
be_local_closure(lvh_dropdown_set_direction, /* name */
be_nested_proto(
6, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("set_dir"),
/* K2 */ be_nested_str_literal("_dir"),
}),
be_str_literal("set_direction"),
&be_const_str_solidified,
( &(const binstruction[ 9]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x60100009, // 0002 GETGBL R4 G9
0x5C140200, // 0003 MOVE R5 R1
0x7C100200, // 0004 CALL R4 1
0x88140102, // 0005 GETMBR R5 R0 K2
0x94100A04, // 0006 GETIDX R4 R5 R4
0x7C080400, // 0007 CALL R2 2
0x80000000, // 0008 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_options
********************************************************************/
be_local_closure(lvh_dropdown_set_options, /* name */
be_nested_proto(
6, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 4]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("set_options"),
/* K2 */ be_nested_str_literal("lv"),
/* K3 */ be_nested_str_literal("ROLLER_MODE_NORMAL"),
}),
be_str_literal("set_options"),
&be_const_str_solidified,
( &(const binstruction[ 7]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0xB8160400, // 0003 GETNGBL R5 K2
0x88140B03, // 0004 GETMBR R5 R5 K3
0x7C080600, // 0005 CALL R2 3
0x80000000, // 0006 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_val
********************************************************************/
be_local_closure(lvh_dropdown_set_val, /* name */
be_nested_proto(
6, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("set_selected"),
/* K2 */ be_const_int(0),
}),
be_str_literal("set_val"),
&be_const_str_solidified,
( &(const binstruction[ 6]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x58140002, // 0003 LDCONST R5 K2
0x7C080600, // 0004 CALL R2 3
0x80000000, // 0005 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_text
********************************************************************/
be_local_closure(lvh_dropdown_get_text, /* name */
be_nested_proto(
7, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 7]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("get_text"),
/* K2 */ be_nested_str_literal("resize"),
/* K3 */ be_nested_str_literal("get_selected_str"),
/* K4 */ be_nested_str_literal("_buffer"),
/* K5 */ be_nested_str_literal("remove_trailing_zeroes"),
/* K6 */ be_nested_str_literal("asstring"),
}),
be_str_literal("get_text"),
&be_const_str_solidified,
( &(const binstruction[27]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x7C040200, // 0002 CALL R1 1
0x4C080000, // 0003 LDNIL R2
0x1C080202, // 0004 EQ R2 R1 R2
0x780A0012, // 0005 JMPF R2 #0019
0x60080015, // 0006 GETGBL R2 G21
0x7C080000, // 0007 CALL R2 0
0x8C080502, // 0008 GETMET R2 R2 K2
0x541200FF, // 0009 LDINT R4 256
0x7C080400, // 000A CALL R2 2
0x880C0100, // 000B GETMBR R3 R0 K0
0x8C0C0703, // 000C GETMET R3 R3 K3
0x8C140504, // 000D GETMET R5 R2 K4
0x7C140200, // 000E CALL R5 1
0x541A00FF, // 000F LDINT R6 256
0x7C0C0600, // 0010 CALL R3 3
0x8C0C0105, // 0011 GETMET R3 R0 K5
0x5C140400, // 0012 MOVE R5 R2
0x7C0C0400, // 0013 CALL R3 2
0x5C080600, // 0014 MOVE R2 R3
0x8C0C0506, // 0015 GETMET R3 R2 K6
0x7C0C0200, // 0016 CALL R3 1
0x80040600, // 0017 RET 1 R3
0x70020000, // 0018 JMP #001A
0x80040200, // 0019 RET 1 R1
0x80000000, // 001A RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_direction
********************************************************************/
be_local_closure(lvh_dropdown_get_direction, /* name */
be_nested_proto(
5, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 5]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("get_dir"),
/* K2 */ be_const_int(0),
/* K3 */ be_nested_str_literal("_dir"),
/* K4 */ be_const_int(1),
}),
be_str_literal("get_direction"),
&be_const_str_solidified,
( &(const binstruction[18]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x7C040200, // 0002 CALL R1 1
0x58080002, // 0003 LDCONST R2 K2
0x600C000C, // 0004 GETGBL R3 G12
0x88100103, // 0005 GETMBR R4 R0 K3
0x7C0C0200, // 0006 CALL R3 1
0x140C0403, // 0007 LT R3 R2 R3
0x780E0006, // 0008 JMPF R3 #0010
0x880C0103, // 0009 GETMBR R3 R0 K3
0x940C0602, // 000A GETIDX R3 R3 R2
0x1C0C0203, // 000B EQ R3 R1 R3
0x780E0000, // 000C JMPF R3 #000E
0x80040400, // 000D RET 1 R2
0x00080504, // 000E ADD R2 R2 K4
0x7001FFF3, // 000F JMP #0004
0x540DFFFE, // 0010 LDINT R3 -1
0x80040600, // 0011 RET 1 R3
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_show_selected
********************************************************************/
be_local_closure(lvh_dropdown_set_show_selected, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("set_text"),
}),
be_str_literal("set_show_selected"),
&be_const_str_solidified,
( &(const binstruction[ 6]) { /* code */
0x78060003, // 0000 JMPF R1 #0005
0x88080100, // 0001 GETMBR R2 R0 K0
0x8C080501, // 0002 GETMET R2 R2 K1
0x4C100000, // 0003 LDNIL R4
0x7C080400, // 0004 CALL R2 2
0x80000000, // 0005 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_text
********************************************************************/
be_local_closure(lvh_dropdown_set_text, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("set_text"),
}),
be_str_literal("set_text"),
&be_const_str_solidified,
( &(const binstruction[ 5]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x7C080400, // 0003 CALL R2 2
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_options
********************************************************************/
be_local_closure(lvh_dropdown_get_options, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("get_options"),
}),
be_str_literal("get_options"),
&be_const_str_solidified,
( &(const binstruction[ 4]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x7C040200, // 0002 CALL R1 1
0x80040200, // 0003 RET 1 R1
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_show_selected
********************************************************************/
be_local_closure(lvh_dropdown_get_show_selected, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("_lv_obj"),
/* K1 */ be_nested_str_literal("get_text"),
}),
be_str_literal("get_show_selected"),
&be_const_str_solidified,
( &(const binstruction[ 6]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x7C040200, // 0002 CALL R1 1
0x4C080000, // 0003 LDNIL R2
0x1C080202, // 0004 EQ R2 R1 R2
0x80040400, // 0005 RET 1 R2
})
)
);
/*******************************************************************/
/******************************************************************** /********************************************************************
** Solidified class: lvh_dropdown ** Solidified class: lvh_dropdown
********************************************************************/ ********************************************************************/
@ -5151,9 +5515,27 @@ extern const bclass be_class_lvh_obj;
be_local_class(lvh_dropdown, be_local_class(lvh_dropdown,
0, 0,
&be_class_lvh_obj, &be_class_lvh_obj,
be_nested_map(1, be_nested_map(12,
( (struct bmapnode*) &(const bmapnode[]) { ( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key_literal("get_show_selected", 8), be_const_closure(lvh_dropdown_get_show_selected_closure) },
{ be_const_key_literal("set_direction", -1), be_const_closure(lvh_dropdown_set_direction_closure) },
{ be_const_key_literal("set_options", -1), be_const_closure(lvh_dropdown_set_options_closure) },
{ be_const_key_literal("set_val", 4), be_const_closure(lvh_dropdown_set_val_closure) },
{ be_const_key_literal("get_text", -1), be_const_closure(lvh_dropdown_get_text_closure) },
{ be_const_key_literal("get_direction", 9), be_const_closure(lvh_dropdown_get_direction_closure) },
{ be_const_key_literal("_lv_class", -1), be_const_class(be_class_lv_dropdown) }, { be_const_key_literal("_lv_class", -1), be_const_class(be_class_lv_dropdown) },
{ be_const_key_literal("set_show_selected", 6), be_const_closure(lvh_dropdown_set_show_selected_closure) },
{ be_const_key_literal("set_text", -1), be_const_closure(lvh_dropdown_set_text_closure) },
{ be_const_key_literal("_dir", -1), be_const_simple_instance(be_nested_simple_instance(&be_class_list, {
be_const_list( * be_nested_list(4,
( (struct bvalue*) &(const bvalue[]) {
be_const_int(8),
be_const_int(4),
be_const_int(1),
be_const_int(2),
})) ) } )) },
{ be_const_key_literal("get_options", -1), be_const_closure(lvh_dropdown_get_options_closure) },
{ be_const_key_literal("get_val", 0), be_const_closure(lvh_dropdown_get_val_closure) },
})), })),
be_str_literal("lvh_dropdown") be_str_literal("lvh_dropdown")
); );

Binary file not shown.

View File

@ -1022,6 +1022,9 @@ class lvh_qrcode : lvh_obj
def get_qr_text() end def get_qr_text() end
end end
#====================================================================
# slider
#====================================================================
class lvh_slider : lvh_obj class lvh_slider : lvh_obj
static _lv_class = lv.slider static _lv_class = lv.slider
@ -1030,6 +1033,9 @@ class lvh_slider : lvh_obj
end end
end end
#====================================================================
# roller
#====================================================================
class lvh_roller : lvh_obj class lvh_roller : lvh_obj
static _lv_class = lv.roller static _lv_class = lv.roller
@ -1059,6 +1065,73 @@ class lvh_roller : lvh_obj
end end
end end
#====================================================================
# dropdown
#====================================================================
class lvh_dropdown : lvh_obj
static _lv_class = lv.dropdown
static _dir = [ lv.DIR_BOTTOM, lv.DIR_TOP, lv.DIR_LEFT, lv.DIR_RIGHT ] # 0 = down, 1 = up, 2 = left, 3 = right
def set_val(t)
self._lv_obj.set_selected(t, 0) # add second parameter - no animation
end
def get_val()
return self._lv_obj.get_selected()
end
def set_options(t)
self._lv_obj.set_options(t, lv.ROLLER_MODE_NORMAL)
end
def get_options()
return self._lv_obj.get_options()
end
def set_text(t)
# set_text sets a static text displayed whatever the value
# use `nil` to set back the text of the selected value
self._lv_obj.set_text(t)
end
def get_text()
var static_text = self._lv_obj.get_text()
if static_text == nil
# allocate a bytes buffer
var b = bytes().resize(256) # force 256 bytes
self._lv_obj.get_selected_str(b._buffer(), 256)
b = self.remove_trailing_zeroes(b)
return b.asstring()
else
return static_text
end
end
# direction needs a conversion from OpenHASP numbers and LVGL's
def set_direction(t)
# 0 = down, 1 = up, 2 = left, 3 = right
self._lv_obj.set_dir(self._dir[int(t)])
end
def get_direction()
var dir = self._lv_obj.get_dir()
var i = 0
while i < size(self._dir)
if dir == self._dir[i] return i end
i += 1
end
return -1
end
# show_selected (bool) is a OpenHASP addition
# only meaningful if set to `true`, setting to false requires a call to `set_text`
def set_show_selected(t)
if t
self._lv_obj.set_text(nil) # undo static text
end
end
def get_show_selected()
var static_text = self._lv_obj.get_text()
return (static_text == nil)
end
end
################################################################################# #################################################################################
# #
# All other subclasses than just map the LVGL object # All other subclasses than just map the LVGL object
@ -1069,7 +1142,6 @@ class lvh_bar : lvh_obj static _lv_class = lv.bar end
class lvh_btn : lvh_obj static _lv_class = lv.btn end class lvh_btn : lvh_obj static _lv_class = lv.btn end
class lvh_btnmatrix : lvh_obj static _lv_class = lv.btnmatrix end class lvh_btnmatrix : lvh_obj static _lv_class = lv.btnmatrix end
class lvh_checkbox : lvh_obj static _lv_class = lv.checkbox end class lvh_checkbox : lvh_obj static _lv_class = lv.checkbox end
class lvh_dropdown : lvh_obj static _lv_class = lv.dropdown end
class lvh_line : lvh_obj static _lv_class = lv.line end class lvh_line : lvh_obj static _lv_class = lv.line end
class lvh_textarea : lvh_obj static _lv_class = lv.textarea end class lvh_textarea : lvh_obj static _lv_class = lv.textarea end
# special case for scr (which is actually lv_obj) # special case for scr (which is actually lv_obj)