Berrry web button demo

- demo of a simple button on the main page and associated value as sensor
- fixed a bug in event dispatcher that would stop the event to the first driver to handle it
- cleaned directories in Berry examples
This commit is contained in:
Stephan Hadinger 2021-05-29 14:27:01 +02:00
parent 0b12e8880c
commit c4bf4e0401
23 changed files with 1628 additions and 2014 deletions

View File

@ -86,6 +86,7 @@ void be_load_driverlib(bvm *vm) {
static const bnfuncinfo members[] = {
{ "every_second", NULL },
{ "every_100ms", NULL },
{ "web_add_handler", NULL },
{ "web_add_button", NULL },
{ "web_add_main_button", NULL },
{ "save_before_restart", NULL },
@ -113,6 +114,7 @@ void be_load_driverlib(bvm *vm) {
class be_class_tasmota_driver (scope: global, name: Driver) {
every_second, var
every_100ms, var
web_add_handler, var
web_add_button, var
web_add_main_button, var
save_before_restart, var

View File

@ -1474,10 +1474,10 @@ be_define_local_const_str(event_str_10, "every_100ms", 1546407804, 11);
be_define_local_const_str(event_str_11, "web_add_button", -757092238, 14);
be_define_local_const_str(event_str_12, "web_add_main_button", -334599632, 19);
be_define_local_const_str(event_str_13, "save_before_restart", 1253239338, 19);
be_define_local_const_str(event_str_14, "web_sensor", -1394870324, 10);
be_define_local_const_str(event_str_15, "json_append", -1292948012, 11);
be_define_local_const_str(event_str_16, "button_pressed", 1694209616, 14);
be_define_local_const_str(event_str_17, "web_add_handler", -304792334, 15);
be_define_local_const_str(event_str_14, "web_add_handler", -304792334, 15);
be_define_local_const_str(event_str_15, "web_sensor", -1394870324, 10);
be_define_local_const_str(event_str_16, "json_append", -1292948012, 11);
be_define_local_const_str(event_str_17, "button_pressed", 1694209616, 14);
be_define_local_const_str(event_str_18, "display", 1164572437, 7);
be_define_local_const_str(event_str_19, "string", 398550328, 6);
be_define_local_const_str(event_str_20, "log", 1062293841, 3);
@ -1513,7 +1513,7 @@ static const bvalue event_ktab[25] = {
{ { .s=be_local_const_str(event_str_24) }, BE_STRING},
};
static const uint32_t event_code[149] = {
static const uint32_t event_code[136] = {
0x1C140300, // 0000 EQ R5 R1 R256
0x78160006, // 0001 JMPF R5 #0009
0x8C140101, // 0002 GETMET R5 R0 R257
@ -1522,147 +1522,134 @@ static const uint32_t event_code[149] = {
0x5C240800, // 0005 MOVE R9 R4
0x7C140800, // 0006 CALL R5 4
0x80040A00, // 0007 RET 1 R5
0x7002008A, // 0008 JMP #0094
0x7002007D, // 0008 JMP #0087
0x1C140302, // 0009 EQ R5 R1 R258
0x78160004, // 000A JMPF R5 #0010
0x8C140103, // 000B GETMET R5 R0 R259
0x5C1C0800, // 000C MOVE R7 R4
0x7C140400, // 000D CALL R5 2
0x80040A00, // 000E RET 1 R5
0x70020083, // 000F JMP #0094
0x70020076, // 000F JMP #0087
0x1C140304, // 0010 EQ R5 R1 R260
0x78160002, // 0011 JMPF R5 #0015
0x4C140000, // 0012 LDNIL 5
0x80040A00, // 0013 RET 1 R5
0x7002007E, // 0014 JMP #0094
0x70020071, // 0014 JMP #0087
0x1C140305, // 0015 EQ R5 R1 R261
0x78160003, // 0016 JMPF R5 #001B
0x8C140105, // 0017 GETMET R5 R0 R261
0x7C140200, // 0018 CALL R5 1
0x80040A00, // 0019 RET 1 R5
0x70020078, // 001A JMP #0094
0x7002006B, // 001A JMP #0087
0x1C140306, // 001B EQ R5 R1 R262
0x78160003, // 001C JMPF R5 #0021
0x8C140107, // 001D GETMET R5 R0 R263
0x7C140200, // 001E CALL R5 1
0x80040A00, // 001F RET 1 R5
0x70020072, // 0020 JMP #0094
0x70020065, // 0020 JMP #0087
0x88140108, // 0021 GETMBR R5 R0 R264
0x78160070, // 0022 JMPF R5 #0094
0x78160063, // 0022 JMPF R5 #0087
0x60140000, // 0023 GETGBL R5 G0
0x88180108, // 0024 GETMBR R6 R0 R264
0x7C140200, // 0025 CALL R5 1
0xA8020069, // 0026 EXBLK 0 #0091
0xA802005C, // 0026 EXBLK 0 #0084
0x5C180A00, // 0027 MOVE R6 R5
0x7C180000, // 0028 CALL R6 0
0xA802005A, // 0029 EXBLK 0 #0085
0xA802004D, // 0029 EXBLK 0 #0078
0x1C1C0309, // 002A EQ R7 R1 R265
0x781E0006, // 002B JMPF R7 #0033
0x781E0004, // 002B JMPF R7 #0031
0x881C0D09, // 002C GETMBR R7 R6 R265
0x781E0004, // 002D JMPF R7 #0033
0x781E0002, // 002D JMPF R7 #0031
0x8C1C0D09, // 002E GETMET R7 R6 R265
0x7C1C0200, // 002F CALL R7 1
0xA8040002, // 0030 EXBLK 1 2
0x80040E00, // 0031 RET 1 R7
0x7002004F, // 0032 JMP #0083
0x1C1C030A, // 0033 EQ R7 R1 R266
0x781E0006, // 0034 JMPF R7 #003C
0x881C0D0A, // 0035 GETMBR R7 R6 R266
0x781E0004, // 0036 JMPF R7 #003C
0x8C1C0D0A, // 0037 GETMET R7 R6 R266
0x7C1C0200, // 0038 CALL R7 1
0xA8040002, // 0039 EXBLK 1 2
0x80040E00, // 003A RET 1 R7
0x70020046, // 003B JMP #0083
0x1C1C030B, // 003C EQ R7 R1 R267
0x781E0006, // 003D JMPF R7 #0045
0x881C0D0B, // 003E GETMBR R7 R6 R267
0x781E0004, // 003F JMPF R7 #0045
0x8C1C0D0B, // 0040 GETMET R7 R6 R267
0x7C1C0200, // 0041 CALL R7 1
0xA8040002, // 0042 EXBLK 1 2
0x80040E00, // 0043 RET 1 R7
0x7002003D, // 0044 JMP #0083
0x1C1C030C, // 0045 EQ R7 R1 R268
0x781E0006, // 0046 JMPF R7 #004E
0x881C0D0C, // 0047 GETMBR R7 R6 R268
0x781E0004, // 0048 JMPF R7 #004E
0x8C1C0D0C, // 0049 GETMET R7 R6 R268
0x7C1C0200, // 004A CALL R7 1
0xA8040002, // 004B EXBLK 1 2
0x80040E00, // 004C RET 1 R7
0x70020034, // 004D JMP #0083
0x1C1C030D, // 004E EQ R7 R1 R269
0x781E0006, // 004F JMPF R7 #0057
0x881C0D0D, // 0050 GETMBR R7 R6 R269
0x781E0004, // 0051 JMPF R7 #0057
0x8C1C0D0D, // 0052 GETMET R7 R6 R269
0x7C1C0200, // 0053 CALL R7 1
0xA8040002, // 0054 EXBLK 1 2
0x80040E00, // 0055 RET 1 R7
0x7002002B, // 0056 JMP #0083
0x1C1C030E, // 0057 EQ R7 R1 R270
0x781E0006, // 0058 JMPF R7 #0060
0x881C0D0E, // 0059 GETMBR R7 R6 R270
0x781E0004, // 005A JMPF R7 #0060
0x8C1C0D0E, // 005B GETMET R7 R6 R270
0x7C1C0200, // 005C CALL R7 1
0xA8040002, // 005D EXBLK 1 2
0x80040E00, // 005E RET 1 R7
0x70020022, // 005F JMP #0083
0x1C1C030F, // 0060 EQ R7 R1 R271
0x781E0006, // 0061 JMPF R7 #0069
0x881C0D0F, // 0062 GETMBR R7 R6 R271
0x70020044, // 0030 JMP #0076
0x1C1C030A, // 0031 EQ R7 R1 R266
0x781E0004, // 0032 JMPF R7 #0038
0x881C0D0A, // 0033 GETMBR R7 R6 R266
0x781E0002, // 0034 JMPF R7 #0038
0x8C1C0D0A, // 0035 GETMET R7 R6 R266
0x7C1C0200, // 0036 CALL R7 1
0x7002003D, // 0037 JMP #0076
0x1C1C030B, // 0038 EQ R7 R1 R267
0x781E0004, // 0039 JMPF R7 #003F
0x881C0D0B, // 003A GETMBR R7 R6 R267
0x781E0002, // 003B JMPF R7 #003F
0x8C1C0D0B, // 003C GETMET R7 R6 R267
0x7C1C0200, // 003D CALL R7 1
0x70020036, // 003E JMP #0076
0x1C1C030C, // 003F EQ R7 R1 R268
0x781E0004, // 0040 JMPF R7 #0046
0x881C0D0C, // 0041 GETMBR R7 R6 R268
0x781E0002, // 0042 JMPF R7 #0046
0x8C1C0D0C, // 0043 GETMET R7 R6 R268
0x7C1C0200, // 0044 CALL R7 1
0x7002002F, // 0045 JMP #0076
0x1C1C030D, // 0046 EQ R7 R1 R269
0x781E0004, // 0047 JMPF R7 #004D
0x881C0D0D, // 0048 GETMBR R7 R6 R269
0x781E0002, // 0049 JMPF R7 #004D
0x8C1C0D0D, // 004A GETMET R7 R6 R269
0x7C1C0200, // 004B CALL R7 1
0x70020028, // 004C JMP #0076
0x1C1C030E, // 004D EQ R7 R1 R270
0x781E0004, // 004E JMPF R7 #0054
0x881C0D0E, // 004F GETMBR R7 R6 R270
0x781E0002, // 0050 JMPF R7 #0054
0x8C1C0D0E, // 0051 GETMET R7 R6 R270
0x7C1C0200, // 0052 CALL R7 1
0x70020021, // 0053 JMP #0076
0x1C1C030F, // 0054 EQ R7 R1 R271
0x781E0004, // 0055 JMPF R7 #005B
0x881C0D0F, // 0056 GETMBR R7 R6 R271
0x781E0002, // 0057 JMPF R7 #005B
0x8C1C0D0F, // 0058 GETMET R7 R6 R271
0x7C1C0200, // 0059 CALL R7 1
0x7002001A, // 005A JMP #0076
0x1C1C0310, // 005B EQ R7 R1 R272
0x781E0004, // 005C JMPF R7 #0062
0x881C0D10, // 005D GETMBR R7 R6 R272
0x781E0002, // 005E JMPF R7 #0062
0x8C1C0D10, // 005F GETMET R7 R6 R272
0x7C1C0200, // 0060 CALL R7 1
0x70020013, // 0061 JMP #0076
0x1C1C0311, // 0062 EQ R7 R1 R273
0x781E0004, // 0063 JMPF R7 #0069
0x8C1C0D0F, // 0064 GETMET R7 R6 R271
0x7C1C0200, // 0065 CALL R7 1
0xA8040002, // 0066 EXBLK 1 2
0x80040E00, // 0067 RET 1 R7
0x70020019, // 0068 JMP #0083
0x1C1C0310, // 0069 EQ R7 R1 R272
0x781E0006, // 006A JMPF R7 #0072
0x881C0D10, // 006B GETMBR R7 R6 R272
0x781E0004, // 006C JMPF R7 #0072
0x8C1C0D10, // 006D GETMET R7 R6 R272
0x881C0D11, // 0064 GETMBR R7 R6 R273
0x781E0002, // 0065 JMPF R7 #0069
0x8C1C0D11, // 0066 GETMET R7 R6 R273
0x7C1C0200, // 0067 CALL R7 1
0x7002000C, // 0068 JMP #0076
0x1C1C030E, // 0069 EQ R7 R1 R270
0x781E0004, // 006A JMPF R7 #0070
0x881C0D12, // 006B GETMBR R7 R6 R274
0x781E0002, // 006C JMPF R7 #0070
0x8C1C0D12, // 006D GETMET R7 R6 R274
0x7C1C0200, // 006E CALL R7 1
0xA8040002, // 006F EXBLK 1 2
0x80040E00, // 0070 RET 1 R7
0x70020010, // 0071 JMP #0083
0x1C1C0311, // 0072 EQ R7 R1 R273
0x781E0006, // 0073 JMPF R7 #007B
0x881C0D12, // 0074 GETMBR R7 R6 R274
0x781E0004, // 0075 JMPF R7 #007B
0x8C1C0D12, // 0076 GETMET R7 R6 R274
0x7C1C0200, // 0077 CALL R7 1
0xA8040002, // 0078 EXBLK 1 2
0x80040E00, // 0079 RET 1 R7
0x70020007, // 007A JMP #0083
0x1C1C0312, // 007B EQ R7 R1 R274
0x781E0005, // 007C JMPF R7 #0083
0x881C0D12, // 007D GETMBR R7 R6 R274
0x781E0003, // 007E JMPF R7 #0083
0x8C1C0D12, // 007F GETMET R7 R6 R274
0x7C1C0200, // 0080 CALL R7 1
0xA8040002, // 0081 EXBLK 1 2
0x80040E00, // 0082 RET 1 R7
0xA8040001, // 0083 EXBLK 1 1
0x7002000A, // 0084 JMP #0090
0xAC1C0002, // 0085 CATCH R7 0 2
0x70020007, // 0086 JMP #008F
0xA4262600, // 0087 IMPORT R9 R275
0x8C280114, // 0088 GETMET R10 R0 R276
0x8C301315, // 0089 GETMET R12 R9 R277
0x58380016, // 008A LDCONST R14 K22
0x583C0017, // 008B LDCONST R15 K23
0x7C300600, // 008C CALL R12 3
0x7C280400, // 008D CALL R10 2
0x70020000, // 008E JMP #0090
0xB0080000, // 008F RAISE 2 R0 R0
0x7001FF95, // 0090 JMP #0027
0x58140018, // 0091 LDCONST R5 K24
0xAC140200, // 0092 CATCH R5 1 0
0xB0080000, // 0093 RAISE 2 R0 R0
0x80000000, // 0094 RET 0 R0
0x70020005, // 006F JMP #0076
0x1C1C0312, // 0070 EQ R7 R1 R274
0x781E0003, // 0071 JMPF R7 #0076
0x881C0D12, // 0072 GETMBR R7 R6 R274
0x781E0001, // 0073 JMPF R7 #0076
0x8C1C0D12, // 0074 GETMET R7 R6 R274
0x7C1C0200, // 0075 CALL R7 1
0xA8040001, // 0076 EXBLK 1 1
0x7002000A, // 0077 JMP #0083
0xAC1C0002, // 0078 CATCH R7 0 2
0x70020007, // 0079 JMP #0082
0xA4262600, // 007A IMPORT R9 R275
0x8C280114, // 007B GETMET R10 R0 R276
0x8C301315, // 007C GETMET R12 R9 R277
0x58380016, // 007D LDCONST R14 K22
0x583C0017, // 007E LDCONST R15 K23
0x7C300600, // 007F CALL R12 3
0x7C280400, // 0080 CALL R10 2
0x70020000, // 0081 JMP #0083
0xB0080000, // 0082 RAISE 2 R0 R0
0x7001FFA2, // 0083 JMP #0027
0x58140018, // 0084 LDCONST R5 K24
0xAC140200, // 0085 CATCH R5 1 0
0xB0080000, // 0086 RAISE 2 R0 R0
0x80000000, // 0087 RET 0 R0
};
be_define_local_proto(event, 16, 5, 1, 0, 0);

View File

@ -11,16 +11,17 @@ class Tasmota
elif self._drivers
for d:self._drivers
try
if type=='every_second' && d.every_second return d.every_second()
elif type=='every_100ms' && d.every_100ms return d.every_100ms()
elif type=='web_add_button' && d.web_add_button return d.web_add_button()
elif type=='web_add_main_button' && d.web_add_main_button return d.web_add_main_button()
elif type=='save_before_restart' && d.save_before_restart return d.save_before_restart()
elif type=='web_sensor' && d.web_sensor return d.web_sensor()
elif type=='json_append' && d.json_append return d.json_append()
elif type=='button_pressed' && d.button_pressed return d.button_pressed()
elif type=='web_add_handler' && d.display return d.display()
elif type=='display' && d.display return d.display()
if type=='every_second' && d.every_second d.every_second()
elif type=='every_100ms' && d.every_100ms d.every_100ms()
elif type=='web_add_button' && d.web_add_button d.web_add_button()
elif type=='web_add_main_button' && d.web_add_main_button d.web_add_main_button()
elif type=='save_before_restart' && d.save_before_restart d.save_before_restart()
elif type=='web_add_handler' && d.web_add_handler d.web_add_handler()
elif type=='web_sensor' && d.web_sensor d.web_sensor()
elif type=='json_append' && d.json_append d.json_append()
elif type=='button_pressed' && d.button_pressed d.button_pressed()
elif type=='web_add_handler' && d.display d.display()
elif type=='display' && d.display d.display()
end
except .. as e,m
import string

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,28 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_driver_map) {
{ be_const_key(button_pressed, 1), be_const_int(0) },
{ be_const_key(web_add_main_button, 5), be_const_int(1) },
{ be_const_key(every_100ms, -1), be_const_int(0) },
{ be_const_key(display, -1), be_const_int(1) },
{ be_const_key(web_add_handler, -1), be_const_int(2) },
{ be_const_key(save_before_restart, -1), be_const_int(3) },
{ be_const_key(web_add_main_button, 10), be_const_int(4) },
{ be_const_key(json_append, -1), be_const_int(5) },
{ be_const_key(web_add_button, 3), be_const_int(6) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
{ be_const_key(web_add_button, 4), be_const_int(2) },
{ be_const_key(web_sensor, -1), be_const_int(3) },
{ be_const_key(json_append, -1), be_const_int(4) },
{ be_const_key(display, -1), be_const_int(5) },
{ be_const_key(every_100ms, -1), be_const_int(6) },
{ be_const_key(save_before_restart, -1), be_const_int(7) },
{ be_const_key(button_pressed, 4), be_const_int(7) },
{ be_const_key(every_second, -1), be_const_int(8) },
{ be_const_key(web_sensor, 5), be_const_int(9) },
{ be_const_key(get_tasmota, -1), be_const_func(d_getTasmotaGlob) },
{ be_const_key(every_second, 8), be_const_int(8) },
};
static be_define_const_map(
be_class_tasmota_driver_map,
11
12
);
BE_EXPORT_VARIABLE be_define_const_class(
be_class_tasmota_driver,
9,
10,
NULL,
Driver
);

View File

@ -1 +0,0 @@
load('denky.be')

View File

@ -1,372 +0,0 @@
import re
in_file = "lv_widgets.txt"
out_file = "out.c"
m = re.compile("(.*?)\s(\w+)\((.*?)\);")
return_types = {
"void": "",
"bool": "b",
"uint8_t": "i",
"uint16_t": "i",
"int16_t": "i",
"uint32_t": "i",
"void *": "i",
"const void *": "i",
"char *": "s",
"const char *": "s",
"lv_obj_user_data_t": "i",
"lv_coord_t": "i",
"lv_res_t": "i",
"lv_style_int_t": "i",
"lv_opa_t": "i",
"lv_drag_dir_t": "i",
"lv_bidi_dir_t": "i",
"lv_state_t": "i",
"lv_label_long_mode_t": "i",
"lv_label_align_t": "i",
"lv_arc_type_t":"i",
"lv_chart_axis_t":"i",
"lv_bar_type_t":"i",
"lv_btn_state_t":"i",
"lv_point_t":"i",
"lv_obj_t *": "lv_obj",
"lv_color_t": "lv_color",
"lv_style_t *": "lv_style",
#"lv_disp_t*": "lv_disp",
#"lv_style_list_t*": "",
}
lv = {}
lvs = [] # special case for case for lv_style
lv0 = [] # function in lvlg module
lv_prefix = ['obj', 'label', 'group', 'arc', 'bar', 'btn', 'btnmatrix', 'calendar', 'canvas', 'chart', 'checkbox']
# convert a C return type to the string representation for the Berry parser
# using return_types
def c_convert_ret_type(c_ret):
return return_types.get(c_ret, "")
with open(in_file) as f, open(out_file,"w") as out:
for l_raw in f:
l_raw = re.sub('static ', '', l_raw)
l_raw = re.sub('inline ', '', l_raw)
l_raw = l_raw.strip(" \t\n\r") # remove leading or trailing spaces
l_raw = re.sub('//.*$', '', l_raw) # replace any multi-space with a single space
if (len(l_raw) == 0): continue
g = m.search(l_raw)
if g:
# if match, we parse the line
ret_type = g.group(1)
ret_type = re.sub('\s+', ' ', ret_type) # replace any multi-space with a single space
if ret_type not in return_types:
print(f" // Skipping unsupported return type: {ret_type}")
continue
# convert return type
c_ret = c_convert_ret_type(ret_type)
# convert arguments
# TODO
c_args = None
# analyze function name and determine if it needs to be assigned to a specific class
func_name = g.group(2)
if func_name.startswith("_"): continue # skip low-level
if func_name.startswith("lv_debug_"): continue # skip debug
c_func_name = ""
found = False
for subtype in lv_prefix:
if func_name.startswith("lv_" + subtype + "_"):
be_name = re.sub("^lv_" + subtype + "_", '', func_name)
c_func_name = "lvbe_" + subtype + "_" + be_name
if subtype not in lv: lv[subtype] = [] # add entry
# special case if the function is create, we change the return type to macth the class
if be_name == 'create':
c_ret = "lv_" + subtype
lv[subtype].append( [ c_func_name, c_ret, c_args, func_name, be_name ] )
found = True
break
if found: continue
# if func_name.startswith("lv_obj_"):
# c_func_name = "lvo_" + re.sub('^lv_obj_', '', func_name)
# lvo.append( [ c_func_name, c_ret, c_args, func_name ] )
# elif func_name.startswith("lv_label_"):
# c_func_name = "lvo_label_" + re.sub('^lv_label_', '', func_name)
# lvo.append( [ c_func_name, c_ret, c_args, func_name ] )
# elif func_name.startswith("lv_group_"):
# c_func_name = "lvg_" + re.sub('^lv_group_', '', func_name)
# lvg.append( [ c_func_name, c_ret, c_args, func_name ] )
# elif func_name.startswith("lv_arc_"):
# c_func_name = "lvg_" + re.sub('^lv_arc_', '', func_name)
# lvg.append( [ c_func_name, c_ret, c_args, func_name ] )
if func_name.startswith("lv_style_"):
be_name = re.sub('^lv_style_', '', func_name)
c_func_name = "lvs_" + be_name
lvs.append( [ c_func_name, c_ret, c_args, func_name, be_name ] )
else:
be_name = re.sub('^lv_', '', func_name)
c_func_name = "lvbe0_" + be_name
lv0.append( [ c_func_name, c_ret, c_args, func_name, be_name ] )
print(lv)
#print(f"orig {func_name} berry {c_func_name}")
#print(g.group(1))
#print(g.group(2))
#print(g.group(3))
print("/********************************************************************")
print(" * Generated code, don't edit")
print(" *******************************************************************/")
for subtype, flv in lv.items():
print(f" /* `lv_{subtype}` methods */")
for f in flv:
c_func_name = f[0]
c_ret_type = f[1]
c_argc = f[2]
if c_argc is not None: c_argc = "\"" + c_argc + "\""
orig_func_name = f[3]
#print(f" int {c_func_name}(bvm *vm) \{ return (vm, be_call_c_func(void*) &")
print(f" int {c_func_name}(bvm *vm) {{ return be_call_c_func(vm, (void*) &{orig_func_name}, \"{c_ret_type}\", { c_argc if c_argc else 'nullptr'}); }}")
print()
print("/********************************************************************/")
print()
print("/********************************************************************")
print(" * Generated code, don't edit")
print(" *******************************************************************/")
for subtype, flv in lv.items():
print(f"/* `lv_{subtype}` external functions definitions */")
for f in flv:
c_func_name = f[0]
print(f"extern int {c_func_name}(bvm *vm);")
print()
# class definitions
print(f"void be_load_lv_{subtype}_lib(bvm *vm) {{")
print(f" static const bnfuncinfo members[] = {{")
print(f" {{ \".p\", NULL }},")
print(f" {{ \"init\", lvx_init_2 }},")
print(f" {{ \"tostring\", lvx_tostring }},")
print()
for f in flv:
c_func_name = f[0]
be_name = f[4]
print(f" {{ \"{be_name}\", {c_func_name} }},")
print()
print(f" // {{ NULL, (bntvfunc) BE_CLOSURE }}, /* mark section for berry closures */")
print()
print(f" {{ NULL, NULL }}")
print(f" }};")
print(f" be_regclass(vm, \"lv_{subtype}\", members);")
print(f"}};")
print()
print(f"/* @const_object_info_begin")
print(f"class be_class_lv_{subtype} (scope: global, name: lv_{subtype}, super: lv_obj) {{")
print(f" .p, var")
print(f" init, func(lvx_init_2)")
print(f" tostring, func(lvx_tostring)")
for f in flv:
c_func_name = f[0]
be_name = f[4]
print(f" {be_name}, func({c_func_name})")
print(f"}}")
print(f"@const_object_info_end */")
print(f"//#include \"../generate/be_fixed_be_class_lv_{subtype}.h\"")
print()
print()
print(f"void be_load_lv_all_lib(bvm *vm) {{")
for subtype in lv:
print(f" be_load_lv_{subtype}_lib(vm);")
print(f"}};")
# for f in lvo:
# c_func_name = f[0]
# print(f"extern int {c_func_name}(bvm *vm);")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_object` methods */")
# print()
# for f in lvo:
# c_func_name = f[0]
# berry_name = c_func_name
# berry_name = re.sub('^lvo_label_', '', berry_name)
# berry_name = re.sub('^lvo_', '', berry_name)
# print(f" {{ \"{berry_name}\", {c_func_name} }},")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_group methods */")
# print()
# for f in lvg:
# c_func_name = f[0]
# c_ret_type = f[1]
# c_argc = f[2]
# if c_argc is not None: c_argc = "\"" + c_argc + "\""
# orig_func_name = f[3]
# #print(f" int {c_func_name}(bvm *vm) \{ return (vm, be_call_c_func(void*) &")
# print(f" int {c_func_name}(bvm *vm) {{ return be_call_c_func(vm, (void*) &{orig_func_name}, \"{c_ret_type}\", { c_argc if c_argc else 'nullptr'}); }}")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_group external functions definitions */")
# print()
# for f in lvg:
# c_func_name = f[0]
# print(f"extern int {c_func_name}(bvm *vm);")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_group` methods */")
# print()
# for f in lvg:
# c_func_name = f[0]
# berry_name = c_func_name
# berry_name = re.sub('^lvg_', '', berry_name)
# print(f" {{ \"{berry_name}\", {c_func_name} }},")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_style methods */")
# print()
# for f in lvs:
# c_func_name = f[0]
# c_ret_type = f[1]
# c_argc = f[2]
# if c_argc is not None: c_argc = "\"" + c_argc + "\""
# orig_func_name = f[3]
# #print(f" int {c_func_name}(bvm *vm) \{ return (vm, be_call_c_func(void*) &")
# print(f" int {c_func_name}(bvm *vm) {{ return be_call_c_func(vm, (void*) &{orig_func_name}, \"{c_ret_type}\", { c_argc if c_argc else 'nullptr'}); }}")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_style external functions definitions */")
# print()
# for f in lvs:
# c_func_name = f[0]
# print(f"extern int {c_func_name}(bvm *vm);")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lv_style` methods */")
# print()
# for f in lvs:
# c_func_name = f[0]
# berry_name = c_func_name
# berry_name = re.sub('^lvs_', '', berry_name)
# print(f" {{ \"{berry_name}\", {c_func_name} }},")
# print("/********************************************************************/")
# print()
# print("/********************************************************************")
# print(" * Generated code, don't edit")
# print(" *******************************************************************/")
# print("/* `lvgl` functions */")
# print()
# for f in lv:
# c_func_name = f[0]
# c_ret_type = f[1]
# c_argc = f[2]
# if c_argc is not None: c_argc = "\"" + c_argc + "\""
# orig_func_name = f[3]
# #print(f" int {c_func_name}(bvm *vm) \{ return (vm, be_call_c_func(void*) &")
# print(f" int {c_func_name}(bvm *vm) {{ return be_call_c_func(vm, (void*) &{orig_func_name}, \"{c_ret_type}\", { c_argc if c_argc else 'nullptr'}); }}")
# print("/********************************************************************/")
# print()
#int lv0_label_create(bvm *vm) { return be_call_c_func(vm, (void*) &lv_label_create, LV_OBJ_CLASS); }
#print(lvo)

View File

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -0,0 +1,40 @@
#-----------------------------------------------------------------------
- Demo of custom web button
-
- Creates a button on the main page that increments a counter each
- time the button is pressed, and display the Counter value like
- a sensor (not included in teleperiod, or implement also 'json_append()')
-
- Copy the following in `autoexec.be` in Tasmota file system
-----------------------------------------------------------------------#
import webserver
class Button_counter_demo : Driver
var counter
def init()
self.counter = 0 #- initialize the counter -#
end
#- this method receives events from buttons and displays values on main page -#
def web_sensor()
#- is 'incr_counter' included in the request -#
if webserver.has_arg("incr_counter")
var incr_counter = int(webserver.arg("incr_counter"))
self.counter += incr_counter
end
#- display the counter in its own line -#
import string
webserver.content_send(string.format("{s}Counter{m}%i{e}", self.counter))
end
#- display button for Increase Counter and trigger 'incr_counter=1' when pressed -#
def web_add_main_button()
webserver.content_send("<p></p><button onclick='la(\"&incr_counter=1\");'>Increment Counter</button>")
end
end
#- create and register driver in Tasmota -#
counter_demo_instance = Button_counter_demo()
tasmota.add_driver(counter_demo_instance)

View File

@ -0,0 +1,42 @@
#-----------------------------------------------------------------------
- Demo of custom web handler
-
- Registers a custom web hanlder for URI prefix `/hello`
- and displays a Tasmota styled web page
-
- Copy the following in `autoexec.be` in Tasmota file system
-----------------------------------------------------------------------#
import webserver
class Web_page_demo : Driver
#- this method displays the web page -#
def page_say_hello()
if !webserver.check_privileged_access() return nil end
webserver.content_start("Hello page") #- title of the web page -#
webserver.content_send_style() #- send standard Tasmota styles -#
webserver.content_send("Tasmota says hello!") #- send any html -#
webserver.content_button(webserver.BUTTON_MAIN) #- button back to main page -#
webserver.content_stop() #- end of web page -#
end
#- this is called at Tasmota start-up, as soon as Wifi/Eth is up and web server running -#
def web_add_handler()
#- we need to register a closure, not just a function, that captures the current instance -#
webserver.on("/hello", / -> self.page_say_hello())
end
end
#- create and register driver in Tasmota -#
web_page_demo_instance = Web_page_demo()
tasmota.add_driver(web_page_demo_instance)
#- For debugging purposes, you can manually call the following to register the web handler -#
#- as it is automatically called only if the instance was registered at startup, for example
#- in `autoexec.be` -#
#-
web_page_demo_instance.web_add_handler()
-#

View File

@ -1,87 +0,0 @@
#-
- Internal representation of LVGL
-
-#
class lv_screen_ntv # this one is embedded
def init() end
end
class lv_screen : lv_screen_ntv # screen type and configuration
var type, sub_type
var width, height
var rotation
var opt
def init(type, sub_type)
super(self).init()
self.type = type
self.sub_type = int(sub_type)
# default values
self.width = 120
self.height = 80
self.rotation = 0
self.opt = nil
end
def set_size(width, height)
self.width = int(width)
self.height = int(height)
end
def set_rotation(rotation)
self.rotation = rotation
end
def set_opt(r0,r1,r2,r3)
self.opt=[r0,r1,r2,r3]
end
end
####################
class lv_connect_ntv def init() end end # this one is embedded in code
class lv_connect : lv_connect_ntv # connection scheme for the screen
var type, sub_type
def init()
super(self).init()
self.type = "" # unknown type
self.sub_type = ""
end
end
class lv_connect_spi : lv_connect # spi connection
def init()
super(self).init()
self.type = "spi"
end
end
class lv_connect_hspi : lv_connect_spi # hardware spi
var cs, dc, rst
def init(cs, dc, rst)
super(self).init()
self.sub_type = "hspi"
self.cs = int(cs)
self.dc = int(dc)
self.rst = int(rst)
end
end
##############################################
class lvlg_ntv
def scr_act() end
end
class lvlg : lvlg_ntv
def init(screen, connect)
# do some stuff
end
end
sc = lv_screen('ili934x', 1)
sp = lv_connect_hspi(1,2,3)

View File

@ -515,6 +515,7 @@ const WebServerDispatch_t WebServerDispatch[] PROGMEM = {
};
void WebServer_on(const char * prefix, void (*func)(void), uint8_t method = HTTP_ANY) {
if (Webserver == nullptr) { return; }
#ifdef ESP8266
Webserver->on((const __FlashStringHelper *) prefix, (HTTPMethod) method, func);
#endif // ESP8266

View File

@ -78,9 +78,6 @@ extern "C" {
//
int32_t w_webserver_on(struct bvm *vm);
int32_t w_webserver_on(struct bvm *vm) {
if (!Web.state) {
be_raise(vm, kInternalError, "Web.state is 'HTTP_OFF'");
}
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 2 && be_isstring(vm, 1) && be_isclosure(vm, 2) &&
(argc < 3 || be_isint(vm, 3)) ) { // optional third argument must be int