Merge pull request #13412 from s-hadinger/berry_global_sleep

Berry global sleep
This commit is contained in:
s-hadinger 2021-10-19 22:05:49 +02:00 committed by GitHub
commit 78933490aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1572 additions and 1519 deletions

View File

@ -7,7 +7,9 @@
struct dummy_struct {}; // we need a struct name but don't need any meaningful content, we just take the address
extern struct TasmotaGlobal_t TasmotaGlobal;
extern struct TSettings * Settings;
extern struct dummy_struct be_tasmota_global_struct;
extern struct dummy_struct be_tasmota_settings_struct;
extern int l_getFreeHeap(bvm *vm);
extern int l_publish(bvm *vm);
@ -53,7 +55,7 @@ extern int l_i2cenabled(bvm *vm);
********************************************************************/
be_local_closure(init, /* name */
be_nested_proto(
4, /* nstack */
7, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
@ -61,21 +63,45 @@ be_local_closure(init, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 4]) { /* constants */
( &(const bvalue[11]) { /* constants */
/* K0 */ be_nested_string("global", 503252654, 6),
/* K1 */ be_nested_string("ctypes_bytes_dyn", 915205307, 16),
/* K2 */ be_nested_string("_global_addr", 533766721, 12),
/* K3 */ be_nested_string("_global_def", 646007001, 11),
/* K4 */ be_nested_string("introspect", 164638290, 10),
/* K5 */ be_nested_string("_settings_ptr", 1825772182, 13),
/* K6 */ be_nested_string("get", 1410115415, 3),
/* K7 */ be_const_int(0),
/* K8 */ be_nested_string("settings", 1745255176, 8),
/* K9 */ be_nested_string("toptr", -915119842, 5),
/* K10 */ be_nested_string("_settings_def", -519406989, 13),
}),
(be_nested_const_str("init", 380752755, 4)),
(be_nested_const_str("input", -103256197, 5)),
( &(const binstruction[ 6]) { /* code */
(be_nested_const_str("tasmota.be", 1128870755, 10)),
( &(const binstruction[23]) { /* code */
0xB8060200, // 0000 GETNGBL R1 K1
0x88080102, // 0001 GETMBR R2 R0 K2
0x880C0103, // 0002 GETMBR R3 R0 K3
0x7C040400, // 0003 CALL R1 2
0x90020001, // 0004 SETMBR R0 K0 R1
0x80000000, // 0005 RET 0
0xA4060800, // 0005 IMPORT R1 K4
0x60080015, // 0006 GETGBL R2 G21
0x880C0105, // 0007 GETMBR R3 R0 K5
0x54120003, // 0008 LDINT R4 4
0x7C080400, // 0009 CALL R2 2
0x8C080506, // 000A GETMET R2 R2 K6
0x58100007, // 000B LDCONST R4 K7
0x54160003, // 000C LDINT R5 4
0x7C080600, // 000D CALL R2 3
0x780A0006, // 000E JMPF R2 #0016
0xB80E0200, // 000F GETNGBL R3 K1
0x8C100309, // 0010 GETMET R4 R1 K9
0x5C180400, // 0011 MOVE R6 R2
0x7C100400, // 0012 CALL R4 2
0x8814010A, // 0013 GETMBR R5 R0 K10
0x7C0C0400, // 0014 CALL R3 2
0x90021003, // 0015 SETMBR R0 K8 R3
0x80000000, // 0016 RET 0
})
)
);
@ -1659,10 +1685,13 @@ class be_class_tasmota (scope: global, name: Tasmota) {
wire1, var
wire2, var
global, var
settings, var
cmd_res, var
_global_def, comptr(&be_tasmota_global_struct)
_settings_def, comptr(&be_tasmota_settings_struct)
_global_addr, comptr(&TasmotaGlobal)
_settings_ptr, comptr(&Settings)
init, closure(init_closure)

View File

@ -26,10 +26,16 @@ class Tasmota
var wire2
var cmd_res # store the command result, nil if disables, true if capture enabled, contains return value
var global # mapping to TasmotaGlobal
var settings
def init()
# instanciate the mapping object to TasmotaGlobal
self.global = ctypes_bytes_dyn(self._global_addr, self._global_def)
import introspect
var settings_addr = bytes(self._settings_ptr, 4).get(0,4)
if settings_addr
self.settings = ctypes_bytes_dyn(introspect.toptr(settings_addr), self._settings_def)
end
end
# add `chars_in_string(s:string,c:string) -> int``

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +1,88 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(response_append, 44), be_const_func(l_respAppend) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
{ be_const_key(resp_cmnd_str, 10), be_const_func(l_respCmndStr) },
{ be_const_key(_cb, 33), be_const_var(0) },
{ be_const_key(set_timer, 66), be_const_closure(set_timer_closure) },
{ be_const_key(publish, -1), be_const_func(l_publish) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(add_cmd, 32), be_const_closure(add_cmd_closure) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(chars_in_string, 35), be_const_closure(chars_in_string_closure) },
{ be_const_key(gen_cb, 48), be_const_closure(gen_cb_closure) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
{ be_const_key(yield, -1), be_const_func(l_yield) },
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(eth, -1), be_const_func(l_eth) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ be_const_key(resp_cmnd_failed, 2), be_const_func(l_respCmndFailed) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
{ be_const_key(millis, 37), be_const_func(l_millis) },
{ be_const_key(_rules, -1), be_const_var(1) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(resp_cmnd_done, 53), be_const_func(l_respCmndDone) },
{ be_const_key(delay, 55), be_const_func(l_delay) },
{ be_const_key(add_driver, 62), be_const_closure(add_driver_closure) },
{ be_const_key(cmd_res, -1), be_const_var(2) },
{ be_const_key(_global_addr, 12), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(time_str, 30), be_const_closure(time_str_closure) },
{ be_const_key(save, -1), be_const_func(l_save) },
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(_drivers, -1), be_const_var(0) },
{ be_const_key(millis, -1), be_const_func(l_millis) },
{ be_const_key(resp_cmnd_done, 57), be_const_func(l_respCmndDone) },
{ be_const_key(settings, 42), be_const_var(1) },
{ be_const_key(time_reached, 6), be_const_func(l_timereached) },
{ be_const_key(try_rule, 46), be_const_closure(try_rule_closure) },
{ be_const_key(resp_cmnd_error, 69), be_const_func(l_respCmndError) },
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
{ be_const_key(get_power, 19), be_const_func(l_getpower) },
{ be_const_key(eth, -1), be_const_func(l_eth) },
{ be_const_key(time_dump, 28), be_const_func(l_time_dump) },
{ be_const_key(web_send_decimal, 61), be_const_func(l_webSendDecimal) },
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
{ be_const_key(global, 67), be_const_var(2) },
{ be_const_key(event, -1), be_const_closure(event_closure) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(time_reached, 59), be_const_func(l_timereached) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(remove_driver, 4), be_const_closure(remove_driver_closure) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
{ be_const_key(resolvecmnd, 65), be_const_func(l_resolveCmnd) },
{ be_const_key(wire2, -1), be_const_var(3) },
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
{ be_const_key(_drivers, 4), be_const_var(3) },
{ be_const_key(global, -1), be_const_var(4) },
{ be_const_key(_cmd, 6), be_const_func(l_cmd) },
{ be_const_key(response_append, 36), be_const_func(l_respAppend) },
{ be_const_key(_rules, -1), be_const_var(4) },
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
{ be_const_key(web_send, -1), be_const_func(l_webSend) },
{ be_const_key(_ccmd, -1), be_const_var(5) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
{ be_const_key(get_power, 43), be_const_func(l_getpower) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(resp_cmnd_str, 44), be_const_func(l_respCmndStr) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(publish, 17), be_const_func(l_publish) },
{ be_const_key(_global_def, 41), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(add_driver, -1), be_const_closure(add_driver_closure) },
{ be_const_key(init, -1), be_const_closure(init_closure) },
{ be_const_key(wire2, -1), be_const_var(6) },
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
{ be_const_key(strftime, 16), be_const_func(l_strftime) },
{ be_const_key(find_op, 39), be_const_closure(find_op_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(_cb, 2), be_const_var(5) },
{ be_const_key(find_op, 27), be_const_closure(find_op_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(_ccmd, -1), be_const_var(6) },
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
{ be_const_key(_timers, -1), be_const_var(7) },
{ be_const_key(wire1, 46), be_const_var(8) },
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
{ be_const_key(delay, 23), be_const_func(l_delay) },
{ be_const_key(_global_addr, 53), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
{ be_const_key(cmd, 24), be_const_closure(cmd_closure) },
{ be_const_key(_timers, 10), be_const_var(7) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(exec_cmd, 50), be_const_closure(exec_cmd_closure) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
{ be_const_key(cmd_res, -1), be_const_var(8) },
{ be_const_key(wire1, 11), be_const_var(9) },
{ be_const_key(publish_result, 47), be_const_func(l_publish_result) },
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(yield, -1), be_const_func(l_yield) },
{ be_const_key(get_switch, 37), be_const_func(l_getswitch) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
{ be_const_key(remove_cmd, 26), be_const_closure(remove_cmd_closure) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
};
static be_define_const_map(
be_class_tasmota_map,
69
72
);
BE_EXPORT_VARIABLE be_define_const_class(
be_class_tasmota,
9,
10,
NULL,
Tasmota
);

View File

@ -33,11 +33,18 @@ extern "C" {
extern const be_ctypes_structure_t be_tasmota_global_struct = {
sizeof(TasmotaGlobal), /* size in bytes */
2, /* number of elements */
1, /* number of elements */
nullptr,
(const be_ctypes_structure_item_t[2]) {
{ "energy_driver", offsetof(TasmotaGlobal_t, energy_driver), 0, 0, ctypes_u8, 0 },
{ "uptime", offsetof(TasmotaGlobal_t, uptime), 0, 0, ctypes_u32, 0 },
{ "sleep", offsetof(TasmotaGlobal_t, sleep), 0, 0, ctypes_u8, 0 },
}};
extern const be_ctypes_structure_t be_tasmota_settings_struct = {
sizeof(TSettings), /* size in bytes */
1, /* number of elements */
nullptr,
(const be_ctypes_structure_item_t[2]) {
{ "sleep", offsetof(TSettings, sleep), 0, 0, ctypes_u8, 0 },
}};
}