mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Berry add tasmota.global
This commit is contained in:
parent
86e72bbedd
commit
a21e4a58fc
@ -236,7 +236,7 @@ int be_ctypes_member(bvm *vm) {
|
||||
}
|
||||
// the int result is at top of the stack
|
||||
// check if we need an instance mapping
|
||||
if (member->mapping > 0) {
|
||||
if (member->mapping > 0 && definitions->instance_mapping) {
|
||||
const char * mapping_name = definitions->instance_mapping[member->mapping - 1];
|
||||
if (mapping_name) {
|
||||
be_getglobal(vm, mapping_name); // stack: class
|
||||
@ -378,14 +378,64 @@ int be_ctypes_tomap(bvm *vm) {
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
//
|
||||
// Constructor for ctypes_dyn structure
|
||||
//
|
||||
// Arg1 is instance self
|
||||
// Arg2 is int or comptr (and not null): create a mapped bytes buffer to read/write at a specific location
|
||||
// Arg3 is int or comptr (and not null): the binary definition of the struct (dynamic and not fixed as static member)
|
||||
int be_ctypes_dyn_init(bvm *vm) {
|
||||
int argc = be_top(vm);
|
||||
void * src_data = NULL;
|
||||
const be_ctypes_structure_t * definitions = NULL;
|
||||
if (argc > 2 && (be_isint(vm, 2) || be_iscomptr(vm, 2)) && (be_isint(vm, 3) || be_iscomptr(vm, 3))) {
|
||||
if (be_iscomptr(vm, 2)) {
|
||||
src_data = be_tocomptr(vm, 2);
|
||||
} else {
|
||||
src_data = (void*) be_toint(vm, 2);
|
||||
}
|
||||
if (be_iscomptr(vm, 3)) {
|
||||
definitions = (const be_ctypes_structure_t *) be_tocomptr(vm, 3);
|
||||
} else {
|
||||
definitions = (const be_ctypes_structure_t *) be_toint(vm, 3);
|
||||
}
|
||||
}
|
||||
if (!src_data || !definitions) {
|
||||
be_raise(vm, "value_error", "'address' and 'definition' cannot be null");
|
||||
}
|
||||
|
||||
// store definition in member variable
|
||||
be_pushcomptr(vm, (void*) definitions);
|
||||
be_setmember(vm, 1, "_def"); // static class comptr
|
||||
be_pop(vm, 1);
|
||||
|
||||
// call bytes.init(self)
|
||||
be_getbuiltin(vm, "bytes"); // shortcut `ctypes` init and call directly bytes.init()
|
||||
be_getmember(vm, -1, "init");
|
||||
be_pushvalue(vm, 1);
|
||||
be_pushcomptr(vm, src_data);
|
||||
be_pushint(vm, -definitions->size_bytes); // negative size signals a fixed size
|
||||
be_call(vm, 3); // call with 2 or 3 arguments depending on provided address
|
||||
be_pop(vm, 4);
|
||||
// super(self, bytes) still on top of stack
|
||||
|
||||
be_pop(vm, 1);
|
||||
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_bytes;
|
||||
|
||||
#include "../generate/be_fixed_be_class_ctypes.h"
|
||||
#include "../generate/be_fixed_be_class_ctypes_dyn.h"
|
||||
|
||||
void be_load_ctypes_lib(bvm *vm) {
|
||||
be_pushntvclass(vm, &be_class_ctypes);
|
||||
be_setglobal(vm, "ctypes_bytes");
|
||||
be_pop(vm, 1);
|
||||
be_pushntvclass(vm, &be_class_ctypes_dyn);
|
||||
be_setglobal(vm, "ctypes_bytes_dyn");
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
/* @const_object_info_begin
|
||||
@ -399,3 +449,10 @@ class be_class_ctypes (scope: global, name: ctypes_bytes, super: be_class_bytes)
|
||||
tomap, func(be_ctypes_tomap)
|
||||
}
|
||||
@const_object_info_end */
|
||||
|
||||
/* @const_object_info_begin
|
||||
class be_class_ctypes_dyn (scope: global, name: ctypes_bytes_dyn, super: be_class_ctypes) {
|
||||
_def, var
|
||||
init, func(be_ctypes_dyn_init)
|
||||
}
|
||||
@const_object_info_end */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************
|
||||
* Tasmota LVGL ctypes mapping
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
#include "be_ctypes.h"
|
||||
|
||||
#ifdef USE_ENERGY_SENSOR
|
||||
|
||||
@ -9,78 +9,10 @@
|
||||
* Generated code, don't edit
|
||||
*******************************************************************/
|
||||
|
||||
enum {
|
||||
ctypes_i32 = 14,
|
||||
ctypes_i16 = 12,
|
||||
ctypes_i8 = 11,
|
||||
ctypes_u32 = 4,
|
||||
ctypes_u16 = 2,
|
||||
ctypes_u8 = 1,
|
||||
|
||||
// big endian
|
||||
ctypes_be_i32 = -14,
|
||||
ctypes_be_i16 = -12,
|
||||
ctypes_be_i8 = -11,
|
||||
ctypes_be_u32 = -4,
|
||||
ctypes_be_u16 = -2,
|
||||
ctypes_be_u8 = -1,
|
||||
|
||||
ctypes_bf = 0, //bif-field
|
||||
};
|
||||
|
||||
typedef struct be_ctypes_structure_item_t {
|
||||
const char * name;
|
||||
uint16_t offset_bytes;
|
||||
uint8_t offset_bits : 3;
|
||||
uint8_t len_bits : 5;
|
||||
int8_t type : 5;
|
||||
uint8_t mapping : 3;
|
||||
} be_ctypes_structure_item_t;
|
||||
|
||||
typedef struct be_ctypes_structure_t {
|
||||
uint16_t size_bytes; /* size in bytes */
|
||||
uint16_t size_elt; /* number of elements */
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_structure_item_t * items;
|
||||
} be_ctypes_structure_t;
|
||||
|
||||
typedef struct be_ctypes_class_t {
|
||||
const char * name;
|
||||
const be_ctypes_structure_t * definitions;
|
||||
} be_ctypes_class_t;
|
||||
|
||||
typedef struct be_ctypes_classes_t {
|
||||
uint16_t size;
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_class_t * classes;
|
||||
} be_ctypes_classes_t;
|
||||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_ctypes;
|
||||
|
||||
static void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {
|
||||
be_pushntvclass(vm, ctypes_class);
|
||||
be_setglobal(vm, str(ctypes_class->name));
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
static const char * be_ctypes_instance_mappings[]; /* forward definition */
|
||||
|
||||
// Define a sub-class of ctypes with only one member which points to the ctypes defintion
|
||||
#define be_define_ctypes_class(_c_name, _def, _super, _name) \
|
||||
be_local_class(_c_name, \
|
||||
0, \
|
||||
_super, \
|
||||
be_nested_map(1, \
|
||||
( (struct bmapnode*) &(const bmapnode[]) { \
|
||||
{ be_nested_key("_def", 1985022181, 4, -1), be_const_comptr(_def) },\
|
||||
})), \
|
||||
(be_nested_const_str(_name, 0, sizeof(_name)-1)) \
|
||||
)
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
const be_ctypes_structure_t be_energy_struct = {
|
||||
158, /* size in bytes */
|
||||
170, /* size in bytes */
|
||||
66, /* number of elements */
|
||||
be_ctypes_instance_mappings,
|
||||
(const be_ctypes_structure_item_t[66]) {
|
||||
@ -94,7 +26,7 @@ const be_ctypes_structure_t be_energy_struct = {
|
||||
{ "current", 12, 0, 0, 5, 0 },
|
||||
{ "current_2", 16, 0, 0, 5, 0 },
|
||||
{ "current_3", 20, 0, 0, 5, 0 },
|
||||
{ "current_available", 130, 5, 1, 0, 0 },
|
||||
{ "current_available", 135, 0, 0, 1, 0 },
|
||||
{ "daily", 100, 0, 0, 5, 0 },
|
||||
{ "data_valid", 126, 0, 0, 1, 0 },
|
||||
{ "data_valid_2", 127, 0, 0, 1, 0 },
|
||||
@ -106,50 +38,50 @@ const be_ctypes_structure_t be_energy_struct = {
|
||||
{ "frequency", 72, 0, 0, 5, 0 },
|
||||
{ "frequency_2", 76, 0, 0, 5, 0 },
|
||||
{ "frequency_3", 80, 0, 0, 5, 0 },
|
||||
{ "frequency_common", 130, 1, 1, 0, 0 },
|
||||
{ "max_current_flag", 150, 5, 1, 0, 0 },
|
||||
{ "max_energy_state", 157, 0, 0, 1, 0 },
|
||||
{ "max_power_flag", 150, 1, 1, 0, 0 },
|
||||
{ "max_voltage_flag", 150, 3, 1, 0, 0 },
|
||||
{ "min_current_flag", 150, 4, 1, 0, 0 },
|
||||
{ "min_power_flag", 150, 0, 1, 0, 0 },
|
||||
{ "min_voltage_flag", 150, 2, 1, 0, 0 },
|
||||
{ "mplh_counter", 152, 0, 0, 2, 0 },
|
||||
{ "mplr_counter", 156, 0, 0, 1, 0 },
|
||||
{ "mplw_counter", 154, 0, 0, 2, 0 },
|
||||
{ "frequency_common", 131, 0, 0, 1, 0 },
|
||||
{ "max_current_flag", 162, 0, 0, 1, 0 },
|
||||
{ "max_energy_state", 169, 0, 0, 1, 0 },
|
||||
{ "max_power_flag", 158, 0, 0, 1, 0 },
|
||||
{ "max_voltage_flag", 160, 0, 0, 1, 0 },
|
||||
{ "min_current_flag", 161, 0, 0, 1, 0 },
|
||||
{ "min_power_flag", 157, 0, 0, 1, 0 },
|
||||
{ "min_voltage_flag", 159, 0, 0, 1, 0 },
|
||||
{ "mplh_counter", 164, 0, 0, 2, 0 },
|
||||
{ "mplr_counter", 168, 0, 0, 1, 0 },
|
||||
{ "mplw_counter", 166, 0, 0, 2, 0 },
|
||||
{ "period", 120, 0, 0, 4, 0 },
|
||||
{ "phase_count", 129, 0, 0, 1, 0 },
|
||||
{ "power_factor", 60, 0, 0, 5, 0 },
|
||||
{ "power_factor_2", 64, 0, 0, 5, 0 },
|
||||
{ "power_factor_3", 68, 0, 0, 5, 0 },
|
||||
{ "power_history_0", 131, 0, 0, 2, 0 },
|
||||
{ "power_history_0_2", 133, 0, 0, 2, 0 },
|
||||
{ "power_history_0_3", 135, 0, 0, 2, 0 },
|
||||
{ "power_history_1", 137, 0, 0, 2, 0 },
|
||||
{ "power_history_1_2", 139, 0, 0, 2, 0 },
|
||||
{ "power_history_1_3", 141, 0, 0, 2, 0 },
|
||||
{ "power_history_2", 143, 0, 0, 2, 0 },
|
||||
{ "power_history_2_2", 145, 0, 0, 2, 0 },
|
||||
{ "power_history_2_3", 147, 0, 0, 2, 0 },
|
||||
{ "power_on", 130, 7, 1, 0, 0 },
|
||||
{ "power_steady_counter", 149, 0, 0, 1, 0 },
|
||||
{ "power_history_0", 138, 0, 0, 2, 0 },
|
||||
{ "power_history_0_2", 140, 0, 0, 2, 0 },
|
||||
{ "power_history_0_3", 142, 0, 0, 2, 0 },
|
||||
{ "power_history_1", 144, 0, 0, 2, 0 },
|
||||
{ "power_history_1_2", 146, 0, 0, 2, 0 },
|
||||
{ "power_history_1_3", 148, 0, 0, 2, 0 },
|
||||
{ "power_history_2", 150, 0, 0, 2, 0 },
|
||||
{ "power_history_2_2", 152, 0, 0, 2, 0 },
|
||||
{ "power_history_2_3", 154, 0, 0, 2, 0 },
|
||||
{ "power_on", 137, 0, 0, 1, 0 },
|
||||
{ "power_steady_counter", 156, 0, 0, 1, 0 },
|
||||
{ "reactive_power", 48, 0, 0, 5, 0 },
|
||||
{ "reactive_power_2", 52, 0, 0, 5, 0 },
|
||||
{ "reactive_power_3", 56, 0, 0, 5, 0 },
|
||||
{ "start_energy", 96, 0, 0, 5, 0 },
|
||||
{ "suff", 151, 0, 0, 1, 0 },
|
||||
{ "stuff", 163, 0, 0, 1, 0 },
|
||||
{ "today_delta_kwh", 108, 0, 0, 4, 0 },
|
||||
{ "today_kwh", 116, 0, 0, 4, 0 },
|
||||
{ "today_offset_init_kwh", 130, 3, 1, 0, 0 },
|
||||
{ "today_offset_init_kwh", 133, 0, 0, 1, 0 },
|
||||
{ "today_offset_kwh", 112, 0, 0, 4, 0 },
|
||||
{ "total", 104, 0, 0, 5, 0 },
|
||||
{ "type_dc", 130, 6, 1, 0, 0 },
|
||||
{ "use_overtemp", 130, 2, 1, 0, 0 },
|
||||
{ "type_dc", 136, 0, 0, 1, 0 },
|
||||
{ "use_overtemp", 132, 0, 0, 1, 0 },
|
||||
{ "voltage", 0, 0, 0, 5, 0 },
|
||||
{ "voltage_2", 4, 0, 0, 5, 0 },
|
||||
{ "voltage_3", 8, 0, 0, 5, 0 },
|
||||
{ "voltage_available", 130, 4, 1, 0, 0 },
|
||||
{ "voltage_common", 130, 0, 1, 0, 0 },
|
||||
{ "voltage_available", 134, 0, 0, 1, 0 },
|
||||
{ "voltage_common", 130, 0, 0, 1, 0 },
|
||||
}};
|
||||
|
||||
static const char * be_ctypes_instance_mappings[] = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************
|
||||
* Tasmota LVGL ctypes mapping
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
#include "be_ctypes.h"
|
||||
|
||||
#ifdef USE_LVGL
|
||||
|
||||
@ -11,76 +11,8 @@
|
||||
* Generated code, don't edit
|
||||
*******************************************************************/
|
||||
|
||||
enum {
|
||||
ctypes_i32 = 14,
|
||||
ctypes_i16 = 12,
|
||||
ctypes_i8 = 11,
|
||||
ctypes_u32 = 4,
|
||||
ctypes_u16 = 2,
|
||||
ctypes_u8 = 1,
|
||||
|
||||
// big endian
|
||||
ctypes_be_i32 = -14,
|
||||
ctypes_be_i16 = -12,
|
||||
ctypes_be_i8 = -11,
|
||||
ctypes_be_u32 = -4,
|
||||
ctypes_be_u16 = -2,
|
||||
ctypes_be_u8 = -1,
|
||||
|
||||
ctypes_bf = 0, //bif-field
|
||||
};
|
||||
|
||||
typedef struct be_ctypes_structure_item_t {
|
||||
const char * name;
|
||||
uint16_t offset_bytes;
|
||||
uint8_t offset_bits : 3;
|
||||
uint8_t len_bits : 5;
|
||||
int8_t type : 5;
|
||||
uint8_t mapping : 3;
|
||||
} be_ctypes_structure_item_t;
|
||||
|
||||
typedef struct be_ctypes_structure_t {
|
||||
uint16_t size_bytes; /* size in bytes */
|
||||
uint16_t size_elt; /* number of elements */
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_structure_item_t * items;
|
||||
} be_ctypes_structure_t;
|
||||
|
||||
typedef struct be_ctypes_class_t {
|
||||
const char * name;
|
||||
const be_ctypes_structure_t * definitions;
|
||||
} be_ctypes_class_t;
|
||||
|
||||
typedef struct be_ctypes_classes_t {
|
||||
uint16_t size;
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_class_t * classes;
|
||||
} be_ctypes_classes_t;
|
||||
|
||||
BE_EXPORT_VARIABLE extern const bclass be_class_ctypes;
|
||||
|
||||
static void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {
|
||||
be_pushntvclass(vm, ctypes_class);
|
||||
be_setglobal(vm, str(ctypes_class->name));
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
static const char * be_ctypes_instance_mappings[]; /* forward definition */
|
||||
|
||||
// Define a sub-class of ctypes with only one member which points to the ctypes defintion
|
||||
#define be_define_ctypes_class(_c_name, _def, _super, _name) \
|
||||
be_local_class(_c_name, \
|
||||
0, \
|
||||
_super, \
|
||||
be_nested_map(1, \
|
||||
( (struct bmapnode*) &(const bmapnode[]) { \
|
||||
{ be_nested_key("_def", 1985022181, 4, -1), be_const_comptr(_def) },\
|
||||
})), \
|
||||
(be_nested_const_str(_name, 0, sizeof(_name)-1)) \
|
||||
)
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
const be_ctypes_structure_t be_lv_point = {
|
||||
4, /* size in bytes */
|
||||
2, /* number of elements */
|
||||
|
@ -5,6 +5,10 @@
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
|
||||
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 dummy_struct be_tasmota_global_struct;
|
||||
|
||||
extern int l_getFreeHeap(bvm *vm);
|
||||
extern int l_publish(bvm *vm);
|
||||
extern int l_publish_result(bvm *vm);
|
||||
@ -44,6 +48,38 @@ extern int l_getswitch(bvm *vm);
|
||||
|
||||
extern int l_i2cenabled(bvm *vm);
|
||||
|
||||
/********************************************************************
|
||||
** Solidified function: init
|
||||
********************************************************************/
|
||||
be_local_closure(init, /* name */
|
||||
be_nested_proto(
|
||||
4, /* nstack */
|
||||
1, /* argc */
|
||||
0, /* 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_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),
|
||||
}),
|
||||
(be_nested_const_str("init", 380752755, 4)),
|
||||
(be_nested_const_str("input", -103256197, 5)),
|
||||
( &(const binstruction[ 6]) { /* 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
|
||||
})
|
||||
)
|
||||
);
|
||||
/*******************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
** Solidified function: add_driver
|
||||
@ -1598,6 +1634,12 @@ class be_class_tasmota (scope: global, name: Tasmota) {
|
||||
_cb, var
|
||||
wire1, var
|
||||
wire2, var
|
||||
global, var
|
||||
|
||||
_global_def, comptr(&be_tasmota_global_struct)
|
||||
_global_addr, comptr(&TasmotaGlobal)
|
||||
|
||||
init, closure(init_closure)
|
||||
|
||||
get_free_heap, func(l_getFreeHeap)
|
||||
publish, func(l_publish)
|
||||
|
@ -37,7 +37,6 @@ module webserver (scope: global) {
|
||||
|
||||
check_privileged_access, func(w_webserver_check_privileged_access)
|
||||
redirect, func(w_webserver_redirect)
|
||||
content_start, func(w_webserver_content_start)
|
||||
content_send, func(w_webserver_content_send)
|
||||
content_send_style, func(w_webserver_content_send_style)
|
||||
content_flush, func(w_webserver_content_flush)
|
||||
|
@ -17,6 +17,12 @@ end
|
||||
|
||||
tasmota = nil
|
||||
class Tasmota
|
||||
var global # mapping to TasmotaGlobal
|
||||
|
||||
def init()
|
||||
# instanciate the mapping object to TasmotaGlobal
|
||||
self.global = ctypes_bytes_dyn(self._global_addr, self._global_def)
|
||||
end
|
||||
|
||||
# add `chars_in_string(s:string,c:string) -> int``
|
||||
# looks for any char in c, and return the position of the first char
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
18
lib/libesp32/Berry/generate/be_fixed_be_class_ctypes_dyn.h
Normal file
18
lib/libesp32/Berry/generate/be_fixed_be_class_ctypes_dyn.h
Normal file
@ -0,0 +1,18 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_ctypes_dyn_map) {
|
||||
{ be_const_key(_def, -1), be_const_var(0) },
|
||||
{ be_const_key(init, 0), be_const_func(be_ctypes_dyn_init) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_ctypes_dyn_map,
|
||||
2
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_ctypes_dyn,
|
||||
1,
|
||||
(bclass *)&be_class_ctypes,
|
||||
ctypes_bytes_dyn
|
||||
);
|
@ -1,80 +1,84 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_map) {
|
||||
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(add_driver, -1), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(web_send, -1), be_const_func(l_webSend) },
|
||||
{ be_const_key(response_append, 1), be_const_func(l_respAppend) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(i2c_enabled, 55), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(wifi, 57), be_const_func(l_wifi) },
|
||||
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
|
||||
{ be_const_key(save, 21), be_const_func(l_save) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(add_cmd, 19), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(wire1, -1), be_const_var(0) },
|
||||
{ be_const_key(_rules, 16), be_const_var(1) },
|
||||
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) },
|
||||
{ be_const_key(_cb, -1), be_const_var(2) },
|
||||
{ be_const_key(log, -1), be_const_func(l_logInfo) },
|
||||
{ be_const_key(get_power, 12), be_const_func(l_getpower) },
|
||||
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(event, 47), be_const_closure(event_closure) },
|
||||
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
|
||||
{ be_const_key(run_deferred, 6), be_const_closure(run_deferred_closure) },
|
||||
{ be_const_key(find_key_i, 38), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(millis, 33), be_const_func(l_millis) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(3) },
|
||||
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
|
||||
{ be_const_key(web_send_decimal, 53), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(wire2, -1), be_const_var(4) },
|
||||
{ be_const_key(gen_cb, 10), be_const_closure(gen_cb_closure) },
|
||||
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
|
||||
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
|
||||
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
|
||||
{ be_const_key(strftime, 51), be_const_func(l_strftime) },
|
||||
{ be_const_key(exec_rules, 27), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(5) },
|
||||
{ be_const_key(resp_cmnd_str, 18), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
|
||||
{ be_const_key(load, -1), be_const_closure(load_closure) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
|
||||
{ be_const_key(get_light, 50), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(memory, -1), be_const_func(l_memory) },
|
||||
{ be_const_key(yield, 45), be_const_func(l_yield) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
|
||||
{ be_const_key(_timers, -1), be_const_var(6) },
|
||||
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(set_timer, 58), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(set_light, 14), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(publish, 2), be_const_func(l_publish) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(time_dump, 9), be_const_func(l_time_dump) },
|
||||
{ be_const_key(eth, -1), be_const_func(l_eth) },
|
||||
{ be_const_key(try_rule, 4), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(publish_result, 63), be_const_func(l_publish_result) },
|
||||
{ be_const_key(try_rule, 18), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(eth, 26), be_const_func(l_eth) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
|
||||
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
|
||||
{ be_const_key(add_driver, 40), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(remove_rule, 4), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(load, -1), be_const_closure(load_closure) },
|
||||
{ be_const_key(response_append, -1), be_const_func(l_respAppend) },
|
||||
{ be_const_key(wire1, 20), be_const_var(0) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(time_reached, 3), be_const_func(l_timereached) },
|
||||
{ be_const_key(log, -1), be_const_func(l_logInfo) },
|
||||
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
|
||||
{ be_const_key(init, 8), be_const_closure(init_closure) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(global, 36), be_const_var(1) },
|
||||
{ be_const_key(event, -1), be_const_closure(event_closure) },
|
||||
{ be_const_key(time_str, 45), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(rtc, 42), be_const_func(l_rtc) },
|
||||
{ be_const_key(millis, -1), be_const_func(l_millis) },
|
||||
{ be_const_key(save, -1), be_const_func(l_save) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
|
||||
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(2) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(_cb, 0), be_const_var(3) },
|
||||
{ be_const_key(resp_cmnd_failed, 59), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(get_light, 2), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
|
||||
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
|
||||
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
|
||||
{ be_const_key(web_send, 54), be_const_func(l_webSend) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(get_switch, 38), be_const_func(l_getswitch) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(find_key_i, 5), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(yield, -1), be_const_func(l_yield) },
|
||||
{ be_const_key(web_send_decimal, 34), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(i2c_enabled, 13), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
|
||||
{ be_const_key(cmd, 14), be_const_closure(cmd_closure) },
|
||||
{ be_const_key(publish, 10), be_const_func(l_publish) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(4) },
|
||||
{ be_const_key(_timers, -1), be_const_var(5) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
|
||||
{ be_const_key(_rules, -1), be_const_var(6) },
|
||||
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(wire2, 47), be_const_var(7) },
|
||||
{ be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
|
||||
{ be_const_key(memory, -1), be_const_func(l_memory) },
|
||||
{ be_const_key(add_rule, 29), be_const_closure(add_rule_closure) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_map,
|
||||
64
|
||||
68
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_tasmota,
|
||||
7,
|
||||
8,
|
||||
NULL,
|
||||
Tasmota
|
||||
);
|
||||
|
83
lib/libesp32/Berry/include/be_ctypes.h
Normal file
83
lib/libesp32/Berry/include/be_ctypes.h
Normal file
@ -0,0 +1,83 @@
|
||||
/********************************************************************
|
||||
* Tasmota ctypes mapping headers
|
||||
*******************************************************************/
|
||||
#ifndef __BE_CONSTOBJ_H__
|
||||
#define __BE_CONSTOBJ_H__
|
||||
|
||||
#include "be_constobj.h"
|
||||
|
||||
enum {
|
||||
ctypes_i32 = 14,
|
||||
ctypes_i16 = 12,
|
||||
ctypes_i8 = 11,
|
||||
ctypes_u32 = 4,
|
||||
ctypes_u16 = 2,
|
||||
ctypes_u8 = 1,
|
||||
|
||||
// big endian
|
||||
ctypes_be_i32 = -14,
|
||||
ctypes_be_i16 = -12,
|
||||
ctypes_be_i8 = -11,
|
||||
ctypes_be_u32 = -4,
|
||||
ctypes_be_u16 = -2,
|
||||
ctypes_be_u8 = -1,
|
||||
|
||||
// floating point
|
||||
ctypes_float = 5,
|
||||
ctypes_double = 10,
|
||||
|
||||
// pointer
|
||||
ctypes_ptr32 = 9,
|
||||
ctypes_ptr64 = -9,
|
||||
|
||||
ctypes_bf = 0, //bif-field
|
||||
};
|
||||
|
||||
typedef struct be_ctypes_structure_item_t {
|
||||
const char * name;
|
||||
uint16_t offset_bytes;
|
||||
uint8_t offset_bits : 3;
|
||||
uint8_t len_bits : 5;
|
||||
int8_t type : 5;
|
||||
uint8_t mapping : 3;
|
||||
} be_ctypes_structure_item_t;
|
||||
|
||||
typedef struct be_ctypes_structure_t {
|
||||
uint16_t size_bytes; /* size in bytes */
|
||||
uint16_t size_elt; /* number of elements */
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_structure_item_t * items;
|
||||
} be_ctypes_structure_t;
|
||||
|
||||
typedef struct be_ctypes_class_t {
|
||||
const char * name;
|
||||
const be_ctypes_structure_t * definitions;
|
||||
} be_ctypes_class_t;
|
||||
|
||||
typedef struct be_ctypes_classes_t {
|
||||
uint16_t size;
|
||||
const char **instance_mapping; /* array of instance class names for automatic instanciation of class */
|
||||
const be_ctypes_class_t * classes;
|
||||
} be_ctypes_classes_t;
|
||||
|
||||
BE_EXPORT_VARIABLE const bclass be_class_ctypes;
|
||||
|
||||
static void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {
|
||||
be_pushntvclass(vm, ctypes_class);
|
||||
be_setglobal(vm, str(ctypes_class->name));
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
|
||||
// Define a sub-class of ctypes with only one member which points to the ctypes defintion
|
||||
#define be_define_ctypes_class(_c_name, _def, _super, _name) \
|
||||
be_local_class(_c_name, \
|
||||
0, \
|
||||
_super, \
|
||||
be_nested_map(1, \
|
||||
( (struct bmapnode*) &(const bmapnode[]) { \
|
||||
{ be_nested_key("_def", 1985022181, 4, -1), be_const_comptr(_def) },\
|
||||
})), \
|
||||
(be_nested_const_str(_name, 0, sizeof(_name)-1)) \
|
||||
)
|
||||
|
||||
#endif // __BE_CONSTOBJ_H__
|
@ -73,7 +73,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#define be_const_comptr(_val) { \
|
||||
.v.p = (void*)(_val), \
|
||||
.v.c = (const void*)(_val), \
|
||||
.type = BE_COMPTR \
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,10 @@ ctypes.be_u8 = -1
|
||||
ctypes.float = 5
|
||||
ctypes.double = 10
|
||||
|
||||
# pointer
|
||||
ctypes.ptr32 = 9
|
||||
ctypes.ptr64 = -9
|
||||
|
||||
ctypes.bf_x = 0 # generic bitfield
|
||||
# bitfields (always unsigned)
|
||||
ctypes.bf_0 = 100 # serves as base
|
||||
@ -167,77 +171,8 @@ ctypes.print_types = def ()
|
||||
print(" * Generated code, don't edit")
|
||||
print(" *******************************************************************/")
|
||||
print()
|
||||
print("enum {")
|
||||
print(" ctypes_i32 = 14,")
|
||||
print(" ctypes_i16 = 12,")
|
||||
print(" ctypes_i8 = 11,")
|
||||
print(" ctypes_u32 = 4,")
|
||||
print(" ctypes_u16 = 2,")
|
||||
print(" ctypes_u8 = 1,")
|
||||
print("")
|
||||
print(" // big endian")
|
||||
print(" ctypes_be_i32 = -14,")
|
||||
print(" ctypes_be_i16 = -12,")
|
||||
print(" ctypes_be_i8 = -11,")
|
||||
print(" ctypes_be_u32 = -4,")
|
||||
print(" ctypes_be_u16 = -2,")
|
||||
print(" ctypes_be_u8 = -1,")
|
||||
print()
|
||||
print(" ctypes_bf = 0, //bif-field")
|
||||
print("};")
|
||||
print()
|
||||
print("typedef struct be_ctypes_structure_item_t {")
|
||||
print(" const char * name;")
|
||||
print(" uint16_t offset_bytes;")
|
||||
print(" uint8_t offset_bits : 3;")
|
||||
print(" uint8_t len_bits : 5;")
|
||||
print(" int8_t type : 5;")
|
||||
print(" uint8_t mapping : 3;")
|
||||
print("} be_ctypes_structure_item_t;")
|
||||
print()
|
||||
print("typedef struct be_ctypes_structure_t {")
|
||||
print(" uint16_t size_bytes; /* size in bytes */")
|
||||
print(" uint16_t size_elt; /* number of elements */")
|
||||
print(" const char **instance_mapping; /* array of instance class names for automatic instanciation of class */")
|
||||
print(" const be_ctypes_structure_item_t * items;")
|
||||
print("} be_ctypes_structure_t;")
|
||||
print()
|
||||
print("typedef struct be_ctypes_class_t {")
|
||||
print(" const char * name;")
|
||||
print(" const be_ctypes_structure_t * definitions;")
|
||||
print("} be_ctypes_class_t;")
|
||||
print("")
|
||||
print("typedef struct be_ctypes_classes_t {")
|
||||
print(" uint16_t size;")
|
||||
print(" const char **instance_mapping; /* array of instance class names for automatic instanciation of class */")
|
||||
print(" const be_ctypes_class_t * classes;")
|
||||
print("} be_ctypes_classes_t;")
|
||||
print()
|
||||
print("BE_EXPORT_VARIABLE extern const bclass be_class_ctypes;")
|
||||
print()
|
||||
print("static void ctypes_register_class(bvm *vm, const bclass * ctypes_class, const be_ctypes_structure_t * definitions) {")
|
||||
print(" be_pushntvclass(vm, ctypes_class);")
|
||||
print(" be_setglobal(vm, str(ctypes_class->name));")
|
||||
print(" be_pop(vm, 1);")
|
||||
print("}")
|
||||
print()
|
||||
print("static const char * be_ctypes_instance_mappings[]; /* forward definition */")
|
||||
print()
|
||||
|
||||
print("// Define a sub-class of ctypes with only one member which points to the ctypes defintion")
|
||||
print("#define be_define_ctypes_class(_c_name, _def, _super, _name) \\")
|
||||
print(" be_local_class(_c_name, \\")
|
||||
print(" 0, \\")
|
||||
print(" _super, \\")
|
||||
print(" be_nested_map(1, \\")
|
||||
print(" ( (struct bmapnode*) &(const bmapnode[]) { \\")
|
||||
print(" { be_nested_key(\"_def\", 1985022181, 4, -1), be_const_comptr(_def) },\\")
|
||||
print(" })), \\")
|
||||
print(" (be_nested_const_str(_name, 0, sizeof(_name)-1)) \\")
|
||||
print(" )")
|
||||
print()
|
||||
print("/********************************************************************/")
|
||||
print()
|
||||
end
|
||||
|
||||
global_classes = [] # track the list of all classes and
|
||||
@ -370,6 +305,9 @@ class structure
|
||||
if type_obj > ctypes.bf_0
|
||||
# bit field
|
||||
self.get_bitfield_closure(name, type_obj - ctypes.bf_0, mapping_idx)
|
||||
elif (type_obj == ctypes.ptr32) || (type_obj == ctypes.ptr64)
|
||||
# pointer
|
||||
self.get_ptr_closure(name, type_obj, mapping_idx)
|
||||
elif (type_obj == ctypes.float) || (type_obj == ctypes.double)
|
||||
# multi-bytes
|
||||
self.get_float_closure(name, type_obj, mapping_idx)
|
||||
@ -445,8 +383,30 @@ class structure
|
||||
self.cur_offset += size_in_bytes # next offset
|
||||
end
|
||||
|
||||
def get_ptr_closure(name, type, instance_mapping) # can be 1/2/4
|
||||
#- actual size -#
|
||||
import introspect
|
||||
var size_in_bytes = (type == ctypes.ptr32) ? 4 : 8
|
||||
|
||||
self.align(size_in_bytes) # force alignment
|
||||
var offset = self.cur_offset # prepare variable for capture in closure
|
||||
|
||||
self.mapping[name] = [offset, 0, 0, type, instance_mapping]
|
||||
|
||||
#- add closures -#
|
||||
# TODO no closure yet, anyways need to rethink closures, they are too heavy
|
||||
# if signed
|
||||
# self.get_closures[name] = def (b, p) return b.geti(offset + p, size_in_bytes_le_be) end
|
||||
# else
|
||||
# self.get_closures[name] = def (b, p) return b.get(offset + p, size_in_bytes_le_be) end
|
||||
# end
|
||||
# self.set_closures[name] = def (b, p, v) return b.set(offset+ p, v, size_in_bytes_le_be) end
|
||||
|
||||
self.cur_offset += size_in_bytes # next offset
|
||||
end
|
||||
|
||||
def get_float_closure(name, type, instance_mapping) # can be 1/2/4
|
||||
#- abs size -#
|
||||
#- actual size -#
|
||||
var size_in_bytes = (type == ctypes.float) ? 4 : 8
|
||||
|
||||
self.align(size_in_bytes) # force alignment
|
||||
|
@ -86,7 +86,7 @@ const uint32_t VERSION_MARKER[] PROGMEM = { 0x5AA55AA5, 0xFFFFFFFF, 0xA55AA55A }
|
||||
|
||||
WiFiUDP PortUdp; // UDP Syslog and Alexa
|
||||
|
||||
struct {
|
||||
struct TasmotaGlobal_t {
|
||||
uint32_t global_update; // Timestamp of last global temperature and humidity update
|
||||
uint32_t baudrate; // Current Serial baudrate
|
||||
uint32_t pulse_timer[MAX_PULSETIMERS]; // Power off timer
|
||||
|
45
tasmota/xdrv_52_3_berry_tasmota_global.ino
Normal file
45
tasmota/xdrv_52_3_berry_tasmota_global.ino
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
xdrv_52_3_berry_tasmota_global.ino - Berry scripting language, mapping to TasmotaGlobal
|
||||
|
||||
Copyright (C) 2021 Stephan Hadinger, Berry language by Guan Wenliang https://github.com/Skiars/berry
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/********************************************************************
|
||||
* Tasmota LVGL ctypes mapping
|
||||
*******************************************************************/
|
||||
|
||||
#ifdef USE_BERRY
|
||||
|
||||
#include <berry.h>
|
||||
#include "be_ctypes.h"
|
||||
|
||||
/********************************************************************
|
||||
* Generated code, don't edit
|
||||
*******************************************************************/
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern const be_ctypes_structure_t be_tasmota_global_struct = {
|
||||
sizeof(TasmotaGlobal), /* size in bytes */
|
||||
2, /* 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 },
|
||||
}};
|
||||
|
||||
}
|
||||
|
||||
#endif // USE_BERRY
|
Loading…
x
Reference in New Issue
Block a user