Merge pull request #12776 from s-hadinger/berry_driver_mqtt_data

Berry add support for mqtt_data in Driver
This commit is contained in:
s-hadinger 2021-07-29 08:59:47 +02:00 committed by GitHub
commit 2dd284aa0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1713 additions and 1859 deletions

View File

@ -6,67 +6,12 @@
*******************************************************************/
#include "be_constobj.h"
/********************************************************************
class Driver2 : Driver
var every_second
var every_100ms
var web_add_handler
var web_add_button
var web_add_main_button
var web_add_management_button
var web_add_config_button
var web_add_console_button
var save_before_restart
var web_sensor
var json_append
var button_pressed
var display
def get_tasmota()
import global
return global.tasmota
end
def add_cmd(c, f)
var tasmota = self.get_tasmota()
tasmota.add_cmd(c, / cmd, idx, payload, payload_json -> f(self, cmd, idx, payload, payload_json))
end
end
********************************************************************/
/********************************************************************
** Solidified function: get_tasmota
********************************************************************/
be_local_closure(get_tasmota, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
be_nested_string("global", 503252654, 6),
be_nested_string("tasmota", 424643812, 7),
}),
(be_nested_const_str("get_tasmota", 334356779, 11)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[ 3]) { /* code */
0xA4060000, // 0000 IMPORT R1 R256
0x88080301, // 0001 GETMBR R2 R1 R257
0x80040400, // 0002 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: add_cmd
********************************************************************/
be_local_closure(add_cmd, /* name */
be_nested_proto(
8, /* nstack */
7, /* nstack */
3, /* argc */
0, /* has upvals */
NULL, /* no upvals */
@ -100,80 +45,54 @@ be_local_closure(add_cmd, /* name */
}),
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
be_nested_string("get_tasmota", 334356779, 11),
be_nested_string("add_cmd", -933336417, 7),
be_nested_string("tasmota", 424643812, 7), /* R256 - K0 */
be_nested_string("add_cmd", -933336417, 7), /* R257 - K1 */
}),
(be_nested_const_str("add_cmd", -933336417, 7)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[ 8]) { /* code */
0x8C0C0100, // 0000 GETMET R3 R0 R256
0x7C0C0200, // 0001 CALL R3 1
0x8C100701, // 0002 GETMET R4 R3 R257
0x5C180200, // 0003 MOVE R6 R1
0x841C0000, // 0004 CLOSURE R7 P0
0x7C100600, // 0005 CALL R4 3
0xA0000000, // 0006 CLOSE 0
0x80000000, // 0007 RET 0 R0
( &(const binstruction[ 7]) { /* code */
0xB80E0000, // 0000 GETNGBL R3 R256
0x8C0C0701, // 0001 GETMET R3 R3 R257
0x5C140200, // 0002 MOVE R5 R1
0x84180000, // 0003 CLOSURE R6 P0
0x7C0C0600, // 0004 CALL R3 3
0xA0000000, // 0005 CLOSE 0
0x80000000, // 0006 RET 0 R0
})
)
);
/*******************************************************************/
#if BE_USE_PRECOMPILED_OBJECT
#include "../generate/be_fixed_be_class_tasmota_driver.h"
#endif
void be_load_driverlib(bvm *vm) {
#if !BE_USE_PRECOMPILED_OBJECT
static const bnfuncinfo members[] = {
{ "every_second", NULL },
{ "every_50ms", NULL },
{ "every_100ms", NULL },
{ "web_add_handler", NULL },
{ "web_add_button", NULL },
{ "web_add_main_button", NULL },
{ "web_add_management_button", NULL },
{ "web_add_config_button", NULL },
{ "web_add_console_button", NULL },
{ "save_before_restart", NULL },
{ "web_sensor", NULL },
{ "json_append", NULL },
{ "button_pressed", NULL },
{ "display", NULL },
/********************************************************************
** Solidified class: Driver
********************************************************************/
be_local_class(Driver,
13,
NULL,
be_nested_map(14,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("web_add_handler", -304792334, 15, 2), be_const_index(2) },
{ be_nested_key("every_second", 2075451465, 12, -1), be_const_index(0) },
{ be_nested_key("web_add_button", -757092238, 14, -1), be_const_index(3) },
{ be_nested_key("web_add_config_button", 639674325, 21, 1), be_const_index(6) },
{ be_nested_key("every_100ms", 1546407804, 11, 0), be_const_index(1) },
{ be_nested_key("add_cmd", -933336417, 7, -1), be_const_closure(add_cmd_closure) },
{ be_nested_key("web_add_management_button", -1556090110, 25, 13), be_const_index(5) },
{ be_nested_key("display", 1164572437, 7, -1), be_const_index(12) },
{ be_nested_key("web_add_main_button", -334599632, 19, 9), be_const_index(4) },
{ be_nested_key("save_before_restart", 1253239338, 19, 11), be_const_index(8) },
{ be_nested_key("web_sensor", -1394870324, 10, 6), be_const_index(9) },
{ be_nested_key("button_pressed", 1694209616, 14, -1), be_const_index(11) },
{ be_nested_key("json_append", -1292948012, 11, -1), be_const_index(10) },
{ be_nested_key("web_add_console_button", -813531104, 22, -1), be_const_index(7) },
})),
(be_nested_const_str("Driver", -718580993, 6))
);
/*******************************************************************/
{ NULL, (bntvfunc) BE_CLOSURE }, /* mark section for berry closures */
{ "get_tasmota", (bntvfunc) &get_tasmota_closure },
{ "add_cmd", (bntvfunc) &add_cmd_closure },
{ NULL, NULL }
};
be_regclass(vm, "Driver", members);
#else
be_pushntvclass(vm, &be_class_tasmota_driver);
void be_load_Driver_class(bvm *vm) {
be_pushntvclass(vm, &be_class_Driver);
be_setglobal(vm, "Driver");
be_pop(vm, 1);
#endif
}
/* @const_object_info_begin
class be_class_tasmota_driver (scope: global, name: Driver) {
every_second, var
every_50ms, var
every_100ms, var
web_add_handler, var
web_add_button, var
web_add_main_button, var
web_add_management_button, var
web_add_config_button, var
web_add_console_button, var
save_before_restart, var
web_sensor, var
json_append, var
button_pressed, var
display, var
get_tasmota, closure(get_tasmota_closure)
add_cmd, closure(add_cmd_closure)
}
@const_object_info_end */

View File

@ -9,7 +9,7 @@
*******************************************************************/
#include "be_constobj.h"
extern bclass* be_class_tasmota_driver; // Parent class
extern bclass* be_class_Driver; // Parent class
/********************************************************************
** Solidified function: init
@ -418,7 +418,7 @@ void be_load_driver_i2c_lib(bvm *vm) {
}
/* @const_object_info_begin
class be_class_tasmota_i2c_driver (scope: global, name: I2C_Driver, super: be_class_tasmota_driver) {
class be_class_tasmota_i2c_driver (scope: global, name: I2C_Driver, super: be_class_Driver) {
wire, var
addr, var
name, var

View File

@ -8,9 +8,6 @@
#ifdef USE_I2S
#ifdef USE_I2S_AUDIO_BERRY
// extern bclass* be_class_tasmota_driver; // Parent class
extern int i2s_output_i2s_init(bvm *vm);
extern int i2s_output_i2s_deinit(bvm *vm);

View File

@ -100,7 +100,7 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = {
#ifdef ESP32
extern void be_load_tasmota_ntvlib(bvm *vm);
extern void be_load_wirelib(bvm *vm);
extern void be_load_driverlib(bvm *vm);
extern void be_load_Driver_class(bvm *vm);
extern void be_load_driver_i2c_lib(bvm *vm);
extern void be_load_md5_lib(bvm *vm);
@ -131,7 +131,7 @@ BERRY_API void be_load_custom_libs(bvm *vm)
/* be_load_xxxlib(vm); */
#endif
be_load_tasmota_ntvlib(vm);
be_load_driverlib(vm);
be_load_Driver_class(vm);
be_load_md5_lib(vm);
#ifdef USE_I2C
be_load_wirelib(vm);

View File

@ -1371,27 +1371,26 @@ be_local_closure(event, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[16]) { /* constants */
be_nested_string("introspect", 164638290, 10),
be_nested_string("every_50ms", -1911083288, 10),
be_nested_string("run_deferred", 371594696, 12),
be_nested_string("cmd", -158181397, 3),
be_nested_string("exec_cmd", 493567399, 8),
be_nested_string("rule", -64077613, 4),
be_nested_string("exec_rules", 1445221092, 10),
be_nested_string("mqtt_data", -1756753932, 9),
be_nested_string("gc", 1042313471, 2),
be_nested_string("_drivers", -1034638311, 8),
be_nested_string("get", 1410115415, 3),
be_nested_string("function", -1630125495, 8),
be_nested_string("string", 398550328, 6),
be_nested_string("format", -1180859054, 6),
be_nested_string("BRY: Exception> '%s' - %s", -2047976332, 25),
be_nested_string("stop_iteration", -121173395, 14),
( &(const bvalue[15]) { /* constants */
be_nested_string("introspect", 164638290, 10), /* R256 - K0 */
be_nested_string("every_50ms", -1911083288, 10), /* R257 - K1 */
be_nested_string("run_deferred", 371594696, 12), /* R258 - K2 */
be_nested_string("cmd", -158181397, 3), /* R259 - K3 */
be_nested_string("exec_cmd", 493567399, 8), /* R260 - K4 */
be_nested_string("rule", -64077613, 4), /* R261 - K5 */
be_nested_string("exec_rules", 1445221092, 10), /* R262 - K6 */
be_nested_string("gc", 1042313471, 2), /* R263 - K7 */
be_nested_string("_drivers", -1034638311, 8), /* R264 - K8 */
be_nested_string("get", 1410115415, 3), /* R265 - K9 */
be_nested_string("function", -1630125495, 8), /* R266 - K10 */
be_nested_string("string", 398550328, 6), /* R267 - K11 */
be_nested_string("format", -1180859054, 6), /* R268 - K12 */
be_nested_string("BRY: Exception> '%s' - %s", -2047976332, 25), /* R269 - K13 */
be_nested_string("stop_iteration", -121173395, 14), /* R270 - K14 */
}),
(be_nested_const_str("event", -30355297, 5)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[72]) { /* code */
( &(const binstruction[78]) { /* code */
0xA4160000, // 0000 IMPORT R5 R256
0x1C180301, // 0001 EQ R6 R1 R257
0x781A0001, // 0002 JMPF R6 #0005
@ -1405,65 +1404,71 @@ be_local_closure(event, /* name */
0x5C280800, // 000A MOVE R10 R4
0x7C180800, // 000B CALL R6 4
0x80040C00, // 000C RET 1 R6
0x70020038, // 000D JMP #0047
0x7002003E, // 000D JMP #004D
0x1C180305, // 000E EQ R6 R1 R261
0x781A0004, // 000F JMPF R6 #0015
0x8C180106, // 0010 GETMET R6 R0 R262
0x5C200800, // 0011 MOVE R8 R4
0x7C180400, // 0012 CALL R6 2
0x80040C00, // 0013 RET 1 R6
0x70020031, // 0014 JMP #0047
0x70020037, // 0014 JMP #004D
0x1C180307, // 0015 EQ R6 R1 R263
0x781A0002, // 0016 JMPF R6 #001A
0x4C180000, // 0017 LDNIL 6
0x80040C00, // 0018 RET 1 R6
0x7002002C, // 0019 JMP #0047
0x1C180308, // 001A EQ R6 R1 R264
0x781A0003, // 001B JMPF R6 #0020
0x8C180108, // 001C GETMET R6 R0 R264
0x7C180200, // 001D CALL R6 1
0x80040C00, // 001E RET 1 R6
0x70020026, // 001F JMP #0047
0x88180109, // 0020 GETMBR R6 R0 R265
0x781A0024, // 0021 JMPF R6 #0047
0x60180000, // 0022 GETGBL R6 G0
0x881C0109, // 0023 GETMBR R7 R0 R265
0x7C180200, // 0024 CALL R6 1
0xA802001D, // 0025 EXBLK 0 #0044
0x5C1C0C00, // 0026 MOVE R7 R6
0x7C1C0000, // 0027 CALL R7 0
0x8C200B0A, // 0028 GETMET R8 R5 R266
0x5C280E00, // 0029 MOVE R10 R7
0x5C2C0200, // 002A MOVE R11 R1
0x7C200600, // 002B CALL R8 3
0x60240015, // 002C GETGBL R9 G21
0x5C281000, // 002D MOVE R10 R8
0x7C240200, // 002E CALL R9 1
0x1C24130B, // 002F EQ R9 R9 R267
0x78260011, // 0030 JMPF R9 #0043
0xA8020004, // 0031 EXBLK 0 #0037
0x5C241000, // 0032 MOVE R9 R8
0x5C280E00, // 0033 MOVE R10 R7
0x7C240200, // 0034 CALL R9 1
0xA8040001, // 0035 EXBLK 1 1
0x7002000B, // 0036 JMP #0043
0xAC240002, // 0037 CATCH R9 0 2
0x70020008, // 0038 JMP #0042
0xA42E1800, // 0039 IMPORT R11 R268
0x6030000F, // 003A GETGBL R12 G15
0x8C34170D, // 003B GETMET R13 R11 R269
0x583C000E, // 003C LDCONST R15 K14
0x5C401200, // 003D MOVE R16 R9
0x5C441400, // 003E MOVE R17 R10
0x7C340800, // 003F CALL R13 4
0x7C300200, // 0040 CALL R12 1
0x70020000, // 0041 JMP #0043
0xB0080000, // 0042 RAISE 2 R0 R0
0x7001FFE1, // 0043 JMP #0026
0x5818000F, // 0044 LDCONST R6 K15
0xAC180200, // 0045 CATCH R6 1 0
0x781A0003, // 0016 JMPF R6 #001B
0x8C180107, // 0017 GETMET R6 R0 R263
0x7C180200, // 0018 CALL R6 1
0x80040C00, // 0019 RET 1 R6
0x70020031, // 001A JMP #004D
0x88180108, // 001B GETMBR R6 R0 R264
0x781A002F, // 001C JMPF R6 #004D
0x60180000, // 001D GETGBL R6 G0
0x881C0108, // 001E GETMBR R7 R0 R264
0x7C180200, // 001F CALL R6 1
0xA8020026, // 0020 EXBLK 0 #0048
0x5C1C0C00, // 0021 MOVE R7 R6
0x7C1C0000, // 0022 CALL R7 0
0x8C200B09, // 0023 GETMET R8 R5 R265
0x5C280E00, // 0024 MOVE R10 R7
0x5C2C0200, // 0025 MOVE R11 R1
0x7C200600, // 0026 CALL R8 3
0x60240015, // 0027 GETGBL R9 G21
0x5C281000, // 0028 MOVE R10 R8
0x7C240200, // 0029 CALL R9 1
0x1C24130A, // 002A EQ R9 R9 R266
0x7826001A, // 002B JMPF R9 #0047
0xA802000D, // 002C EXBLK 0 #003B
0x5C241000, // 002D MOVE R9 R8
0x5C280E00, // 002E MOVE R10 R7
0x5C2C0400, // 002F MOVE R11 R2
0x5C300600, // 0030 MOVE R12 R3
0x5C340800, // 0031 MOVE R13 R4
0x7C240800, // 0032 CALL R9 4
0x50280200, // 0033 LDBOOL R10 1 0
0x1C28120A, // 0034 EQ R10 R9 R10
0x782A0002, // 0035 JMPF R10 #0039
0x50280200, // 0036 LDBOOL R10 1 0
0xA8040002, // 0037 EXBLK 1 2
0x80041400, // 0038 RET 1 R10
0xA8040001, // 0039 EXBLK 1 1
0x7002000B, // 003A JMP #0047
0xAC240002, // 003B CATCH R9 0 2
0x70020008, // 003C JMP #0046
0xA42E1600, // 003D IMPORT R11 R267
0x6030000F, // 003E GETGBL R12 G15
0x8C34170C, // 003F GETMET R13 R11 R268
0x583C000D, // 0040 LDCONST R15 K13
0x5C401200, // 0041 MOVE R16 R9
0x5C441400, // 0042 MOVE R17 R10
0x7C340800, // 0043 CALL R13 4
0x7C300200, // 0044 CALL R12 1
0x70020000, // 0045 JMP #0047
0xB0080000, // 0046 RAISE 2 R0 R0
0x80000000, // 0047 RET 0 R0
0x7001FFD8, // 0047 JMP #0021
0x5818000E, // 0048 LDCONST R6 K14
0xAC180200, // 0049 CATCH R6 1 0
0xB0080000, // 004A RAISE 2 R0 R0
0x50180000, // 004B LDBOOL R6 0 0
0x80040C00, // 004C RET 1 R6
0x80000000, // 004D RET 0 R0
})
)
);

View File

@ -0,0 +1,25 @@
#- Native code used for testing and code solidification -#
#- Do not use it -#
class Driver
var every_second
var every_100ms
var web_add_handler
var web_add_button
var web_add_main_button
var web_add_management_button
var web_add_config_button
var web_add_console_button
var save_before_restart
var web_sensor
var json_append
var button_pressed
var display
def init()
end
def add_cmd(c, f)
tasmota.add_cmd(c, / cmd, idx, payload, payload_json -> f(self, cmd, idx, payload, payload_json))
end
end

View File

@ -1,7 +1,7 @@
#- Native code used for testing and code solidification -#
#- Do not use it -#
class Tasmota2 : Tasmota
class Tasmota
# add `chars_in_string(s:string,c:string) -> int``
# looks for any char in c, and return the position of the first char
@ -247,20 +247,21 @@ class Tasmota2 : Tasmota
if event_type=='cmd' return self.exec_cmd(cmd, idx, payload)
elif event_type=='rule' return self.exec_rules(payload)
elif event_type=='mqtt_data' return nil
elif event_type=='gc' return self.gc()
elif self._drivers
for d:self._drivers
var f = introspect.get(d, event_type) # try to match a function or method with the same name
if type(f) == 'function'
try
f(d)
var done = f(d, cmd, idx, payload)
if done == true return true end
except .. as e,m
import string
print(string.format("BRY: Exception> '%s' - %s", e, m))
end
end
end
return false
end
end
@ -288,4 +289,3 @@ class Tasmota2 : Tasmota
end
end
tasmota = Tasmota2()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +0,0 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_lv_draw_line_map) {
{ be_const_key(init, 2), be_const_func(lvbe_draw_line_create) },
{ be_const_key(tostring, -1), be_const_func(lvx_tostring) },
{ be_const_key(dot_p, -1), be_const_int(0) },
{ be_const_key(member, 0), be_const_func(lvx_member) },
};
static be_define_const_map(
be_class_lv_draw_line_map,
4
);
BE_EXPORT_VARIABLE be_define_const_class(
be_class_lv_draw_line,
1,
NULL,
lv_draw_line
);

View File

@ -1,32 +0,0 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_driver_map) {
{ be_const_key(button_pressed, 6), be_const_index(0) },
{ be_const_key(web_add_management_button, -1), be_const_index(1) },
{ be_const_key(web_add_button, 13), be_const_index(2) },
{ be_const_key(web_add_config_button, -1), be_const_index(3) },
{ be_const_key(json_append, -1), be_const_index(4) },
{ be_const_key(display, 3), be_const_index(5) },
{ be_const_key(web_add_console_button, 14), be_const_index(6) },
{ be_const_key(every_100ms, -1), be_const_index(7) },
{ be_const_key(every_50ms, -1), be_const_index(8) },
{ be_const_key(every_second, -1), be_const_index(9) },
{ be_const_key(save_before_restart, -1), be_const_index(10) },
{ be_const_key(get_tasmota, -1), be_const_closure(get_tasmota_closure) },
{ be_const_key(web_sensor, 7), be_const_index(11) },
{ be_const_key(web_add_handler, 1), be_const_index(12) },
{ be_const_key(web_add_main_button, -1), be_const_index(13) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
};
static be_define_const_map(
be_class_tasmota_driver_map,
16
);
BE_EXPORT_VARIABLE be_define_const_class(
be_class_tasmota_driver,
14,
NULL,
Driver
);

View File

@ -22,6 +22,6 @@ static be_define_const_map(
BE_EXPORT_VARIABLE be_define_const_class(
be_class_tasmota_i2c_driver,
3,
(bclass *)&be_class_tasmota_driver,
(bclass *)&be_class_Driver,
I2C_Driver
);