mirror of https://github.com/arendst/Tasmota.git
Berry webserver, added constants
This commit is contained in:
parent
5cffd58c16
commit
de1ac64bd4
|
@ -51,12 +51,12 @@ const size_t lv_func_size = sizeof(lv_func) / sizeof(lv_func[0]);
|
|||
|
||||
|
||||
|
||||
typedef struct lvbe_constant_t {
|
||||
typedef struct be_constint_t {
|
||||
const char * name;
|
||||
int32_t value;
|
||||
} lvbe_constant_t;
|
||||
} be_constint_t;
|
||||
|
||||
const lvbe_constant_t lv0_constants[] = {
|
||||
const be_constint_t lv0_constants[] = {
|
||||
|
||||
{ "ALIGN_CENTER", LV_ALIGN_CENTER },
|
||||
{ "ALIGN_IN_BOTTOM_LEFT", LV_ALIGN_IN_BOTTOM_LEFT },
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#ifdef USE_WEBSERVER
|
||||
|
||||
extern int w_webserver_member(bvm *vm);
|
||||
extern int w_webserver_on(bvm *vm);
|
||||
extern int w_webserver_state(bvm *vm);
|
||||
|
||||
|
@ -26,11 +27,7 @@ extern int w_webserver_has_arg(bvm *vm);
|
|||
|
||||
#if !BE_USE_PRECOMPILED_OBJECT
|
||||
be_native_module_attr_table(webserver) {
|
||||
be_native_module_int("HTTP_OFF", 0),
|
||||
be_native_module_int("HTTP_USER", 1),
|
||||
be_native_module_int("HTTP_ADMIN", 2),
|
||||
be_native_module_int("HTTP_MANAGER", 3),
|
||||
be_native_module_int("HTTP_MANAGER_RESET_ONLY", 4),
|
||||
be_native_module_function("member", w_webserver_member),
|
||||
|
||||
be_native_module_function("on", w_webserver_on),
|
||||
be_native_module_function("state", w_webserver_state),
|
||||
|
@ -54,11 +51,7 @@ be_define_native_module(webserver, NULL);
|
|||
#else
|
||||
/* @const_object_info_begin
|
||||
module webserver (scope: global) {
|
||||
HTTP_OFF, int(0)
|
||||
HTTP_USER, int(1)
|
||||
HTTP_ADMIN, int(2)
|
||||
HTTP_MANAGER, int(3)
|
||||
HTTP_MANAGER_RESET_ONLY, int(4)
|
||||
member, func(w_webserver_member)
|
||||
|
||||
on, func(w_webserver_on)
|
||||
state, func(w_webserver_state)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +1,24 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(m_libwebserver_map) {
|
||||
{ be_const_key(has_arg, -1), be_const_func(w_webserver_has_arg) },
|
||||
{ be_const_key(HTTP_MANAGER, -1), be_const_int(3) },
|
||||
{ be_const_key(content_start, 12), be_const_func(w_webserver_content_start) },
|
||||
{ be_const_key(args, -1), be_const_func(w_webserver_args) },
|
||||
{ be_const_key(HTTP_USER, -1), be_const_int(1) },
|
||||
{ be_const_key(content_stop, -1), be_const_func(w_webserver_content_stop) },
|
||||
{ be_const_key(arg, 10), be_const_func(w_webserver_arg) },
|
||||
{ be_const_key(HTTP_ADMIN, -1), be_const_int(2) },
|
||||
{ be_const_key(on, 12), be_const_func(w_webserver_on) },
|
||||
{ be_const_key(state, 6), be_const_func(w_webserver_state) },
|
||||
{ be_const_key(content_send_style, -1), be_const_func(w_webserver_content_send_style) },
|
||||
{ be_const_key(content_flush, 14), be_const_func(w_webserver_content_flush) },
|
||||
{ be_const_key(state, -1), be_const_func(w_webserver_state) },
|
||||
{ be_const_key(content_button, -1), be_const_func(w_webserver_content_button) },
|
||||
{ be_const_key(HTTP_OFF, -1), be_const_int(0) },
|
||||
{ be_const_key(on, 5), be_const_func(w_webserver_on) },
|
||||
{ be_const_key(content_send, -1), be_const_func(w_webserver_content_send) },
|
||||
{ be_const_key(HTTP_MANAGER_RESET_ONLY, 16), be_const_int(4) },
|
||||
{ be_const_key(arg, -1), be_const_func(w_webserver_arg) },
|
||||
{ be_const_key(content_flush, -1), be_const_func(w_webserver_content_flush) },
|
||||
{ be_const_key(content_start, 5), be_const_func(w_webserver_content_start) },
|
||||
{ be_const_key(content_button, -1), be_const_func(w_webserver_content_button) },
|
||||
{ be_const_key(args, 2), be_const_func(w_webserver_args) },
|
||||
{ be_const_key(check_privileged_access, -1), be_const_func(w_webserver_check_privileged_access) },
|
||||
{ be_const_key(content_stop, -1), be_const_func(w_webserver_content_stop) },
|
||||
{ be_const_key(member, -1), be_const_func(w_webserver_member) },
|
||||
{ be_const_key(has_arg, -1), be_const_func(w_webserver_has_arg) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
m_libwebserver_map,
|
||||
17
|
||||
13
|
||||
);
|
||||
|
||||
static be_define_const_module(
|
||||
|
|
|
@ -26,6 +26,24 @@
|
|||
const char kTypeError[] PROGMEM = "type_error";
|
||||
const char kInternalError[] PROGMEM = "intenal_error";
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Support for Berry int constants
|
||||
* as virtual members
|
||||
\*********************************************************************************************/
|
||||
typedef struct be_constint_t {
|
||||
const char * name;
|
||||
int32_t value;
|
||||
} be_constint_t;
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* LVGL top level virtual members
|
||||
*
|
||||
* Responds to virtual constants
|
||||
\*********************************************************************************************/
|
||||
extern "C" {
|
||||
#include "be_exec.h"
|
||||
void be_dumpstack(bvm *vm) {
|
||||
|
|
|
@ -753,16 +753,10 @@ extern "C" {
|
|||
* Responds to virtual constants
|
||||
\*********************************************************************************************/
|
||||
|
||||
typedef struct lvbe_constant_t {
|
||||
const char * name;
|
||||
int32_t value;
|
||||
} lvbe_constant_t;
|
||||
|
||||
|
||||
extern const lvbe_call_c_t lv_func[];
|
||||
extern const size_t lv_func_size;
|
||||
|
||||
extern const lvbe_constant_t lv0_constants[];
|
||||
extern const be_constint_t lv0_constants[];
|
||||
extern const size_t lv0_constants_size;
|
||||
|
||||
int lv0_member(bvm *vm);
|
||||
|
|
|
@ -24,6 +24,44 @@
|
|||
|
||||
#include <berry.h>
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Int constants
|
||||
*********************************************************************************************/
|
||||
const be_constint_t webserver_constants[] = {
|
||||
{ "BUTTON_CONFIGURATION", BUTTON_CONFIGURATION },
|
||||
{ "BUTTON_INFORMATION", BUTTON_INFORMATION },
|
||||
{ "BUTTON_MAIN", BUTTON_MAIN },
|
||||
{ "BUTTON_MANAGEMENT", BUTTON_MANAGEMENT },
|
||||
{ "BUTTON_MODULE", BUTTON_MODULE },
|
||||
{ "HTTP_ADMIN", HTTP_ADMIN },
|
||||
{ "HTTP_ANY", HTTP_ANY },
|
||||
{ "HTTP_GET", HTTP_GET },
|
||||
{ "HTTP_MANAGER", HTTP_MANAGER },
|
||||
{ "HTTP_MANAGER_RESET_ONLY", HTTP_MANAGER_RESET_ONLY },
|
||||
{ "HTTP_OFF", HTTP_OFF },
|
||||
{ "HTTP_OPTIONS", HTTP_OPTIONS },
|
||||
{ "HTTP_POST", HTTP_POST },
|
||||
{ "HTTP_USER", HTTP_USER },
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
int w_webserver_member(bvm *vm);
|
||||
int w_webserver_member(bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc == 1 && be_isstring(vm, 1)) {
|
||||
const char * needle = be_tostring(vm, 1);
|
||||
|
||||
int32_t constant_idx = bin_search(needle, &webserver_constants[0].name, sizeof(webserver_constants[0]), ARRAY_SIZE(webserver_constants));
|
||||
|
||||
if (constant_idx >= 0) {
|
||||
// we did have a match, low == high
|
||||
be_pushint(vm, webserver_constants[constant_idx].value);
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Native functions mapped to Berry functions
|
||||
|
|
|
@ -549,12 +549,12 @@ const size_t lv_func_size = sizeof(lv_func) / sizeof(lv_func[0]);
|
|||
|
||||
print("""
|
||||
|
||||
typedef struct lvbe_constant_t {
|
||||
typedef struct be_constint_t {
|
||||
const char * name;
|
||||
int32_t value;
|
||||
} lvbe_constant_t;
|
||||
} be_constint_t;
|
||||
|
||||
const lvbe_constant_t lv0_constants[] = {
|
||||
const be_constint_t lv0_constants[] = {
|
||||
""")
|
||||
|
||||
lv_module2 = {}
|
||||
|
|
Loading…
Reference in New Issue