Berry add `tasmota.get_switch()` (#13173)

This commit is contained in:
s-hadinger 2021-09-19 15:52:13 +02:00 committed by GitHub
parent 5e2686407d
commit 74bd4cfd53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1819 additions and 1798 deletions

View File

@ -37,9 +37,10 @@ extern int l_webSend(bvm *vm);
extern int l_webSendDecimal(bvm *vm);
extern int l_getlight(bvm *vm);
extern int l_getpower(bvm *vm);
extern int l_setlight(bvm *vm);
extern int l_getpower(bvm *vm);
extern int l_setpower(bvm *vm);
extern int l_getswitch(bvm *vm);
extern int l_i2cenabled(bvm *vm);
@ -1609,6 +1610,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
get_power, func(l_getpower)
set_power, func(l_setpower)
get_switch, func(l_getswitch)
i2c_enabled, func(l_i2cenabled)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +1,75 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ be_const_key(_cmd, 45), be_const_func(l_cmd) },
{ be_const_key(millis, 53), be_const_func(l_millis) },
{ be_const_key(web_send, -1), be_const_func(l_webSend) },
{ be_const_key(wire1, -1), be_const_var(0) },
{ be_const_key(response_append, -1), be_const_func(l_respAppend) },
{ be_const_key(_get_cb, 30), be_const_func(l_get_cb) },
{ be_const_key(get_free_heap, 22), be_const_func(l_getFreeHeap) },
{ be_const_key(resp_cmnd_failed, 2), be_const_func(l_respCmndFailed) },
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
{ be_const_key(set_light, 8), be_const_closure(set_light_closure) },
{ be_const_key(resp_cmnd, 16), be_const_func(l_respCmnd) },
{ be_const_key(find_op, 34), be_const_closure(find_op_closure) },
{ be_const_key(eth, -1), be_const_func(l_eth) },
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
{ be_const_key(remove_rule, 1), be_const_closure(remove_rule_closure) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(exec_rules, 37), be_const_closure(exec_rules_closure) },
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
{ be_const_key(remove_driver, 29), be_const_closure(remove_driver_closure) },
{ be_const_key(publish_result, 38), be_const_func(l_publish_result) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
{ be_const_key(gen_cb, 42), be_const_closure(gen_cb_closure) },
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
{ be_const_key(_timers, -1), be_const_var(1) },
{ be_const_key(wire2, -1), be_const_var(2) },
{ be_const_key(run_deferred, 20), be_const_closure(run_deferred_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(resp_cmnd_str, 51), be_const_func(l_respCmndStr) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(publish, 55), be_const_func(l_publish) },
{ be_const_key(_ccmd, -1), be_const_var(3) },
{ be_const_key(resp_cmnd_error, 23), be_const_func(l_respCmndError) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(save, -1), be_const_func(l_save) },
{ be_const_key(_drivers, -1), be_const_var(4) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(wifi, 36), be_const_func(l_wifi) },
{ be_const_key(set_timer, 40), be_const_closure(set_timer_closure) },
{ be_const_key(i2c_enabled, 44), be_const_func(l_i2cenabled) },
{ be_const_key(set_power, 54), be_const_func(l_setpower) },
{ be_const_key(_rules, 14), be_const_var(5) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(time_reached, 26), be_const_func(l_timereached) },
{ be_const_key(web_send_decimal, 58), be_const_func(l_webSendDecimal) },
{ be_const_key(_cb, -1), be_const_var(6) },
{ be_const_key(yield, 56), be_const_func(l_yield) },
{ be_const_key(event, -1), be_const_closure(event_closure) },
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
{ 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(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
};
static be_define_const_map(
be_class_tasmota_map,
63
64
);
BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -451,6 +451,21 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// get power
int32_t l_getswitch(bvm *vm);
int32_t l_getswitch(bvm *vm) {
be_newobject(vm, "list");
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if (PinUsed(GPIO_SWT1, i)) {
be_pushbool(vm, Switch.virtual_state[i] == PRESSED);
be_data_push(vm, -2);
be_pop(vm, 1);
}
}
be_pop(vm, 1);
be_return(vm); // Return
}
#ifdef USE_I2C
// I2C specific
// Berry: `i2c_enabled(index:int) -> bool` is I2C device enabled