mirror of https://github.com/arendst/Tasmota.git
Berry add `tasmota.random_byte()`
This commit is contained in:
parent
41d958020e
commit
44189186e9
|
@ -31,6 +31,7 @@ extern int l_delay(bvm *vm);
|
|||
extern int l_scaleuint(bvm *vm);
|
||||
extern int l_logInfo(bvm *vm);
|
||||
extern int l_save(bvm *vm);
|
||||
extern int t_random_byte(bvm *vm);
|
||||
|
||||
extern int l_read_sensors(bvm *vm);
|
||||
|
||||
|
@ -2026,6 +2027,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
|
|||
scale_uint, func(l_scaleuint)
|
||||
log, func(l_logInfo)
|
||||
save, func(l_save)
|
||||
random_byte, func(t_random_byte)
|
||||
|
||||
read_sensors, func(l_read_sensors)
|
||||
|
||||
|
|
|
@ -558,6 +558,7 @@ extern const bcstring be_const_str_r;
|
|||
extern const bcstring be_const_str_rad;
|
||||
extern const bcstring be_const_str_raise;
|
||||
extern const bcstring be_const_str_rand;
|
||||
extern const bcstring be_const_str_random_byte;
|
||||
extern const bcstring be_const_str_range;
|
||||
extern const bcstring be_const_str_read;
|
||||
extern const bcstring be_const_str_read12;
|
||||
|
|
|
@ -400,7 +400,7 @@ be_define_const_str(get_switch, "get_switch", 164821028u, 0, 10, &be_const_str_l
|
|||
be_define_const_str(get_temp, "get_temp", 3370919486u, 0, 8, &be_const_str_group_def);
|
||||
be_define_const_str(get_vbus_current, "get_vbus_current", 1205347942u, 0, 16, NULL);
|
||||
be_define_const_str(get_vbus_voltage, "get_vbus_voltage", 2398210401u, 0, 16, &be_const_str_select);
|
||||
be_define_const_str(get_warning_level, "get_warning_level", 1737834441u, 0, 17, &be_const_str_value_error);
|
||||
be_define_const_str(get_warning_level, "get_warning_level", 1737834441u, 0, 17, &be_const_str_random_byte);
|
||||
be_define_const_str(get_width, "get_width", 3293417300u, 0, 9, &be_const_str_pin);
|
||||
be_define_const_str(getbits, "getbits", 3094168979u, 0, 7, &be_const_str_pow);
|
||||
be_define_const_str(geti, "geti", 2381006490u, 0, 4, NULL);
|
||||
|
@ -550,6 +550,7 @@ be_define_const_str(r, "r", 4144776981u, 0, 1, NULL);
|
|||
be_define_const_str(rad, "rad", 1358899048u, 0, 3, &be_const_str_sec);
|
||||
be_define_const_str(raise, "raise", 1593437475u, 70, 5, NULL);
|
||||
be_define_const_str(rand, "rand", 2711325910u, 0, 4, &be_const_str_import);
|
||||
be_define_const_str(random_byte, "random_byte", 1603171253u, 0, 11, &be_const_str_value_error);
|
||||
be_define_const_str(range, "range", 4208725202u, 0, 5, &be_const_str_resp_cmnd);
|
||||
be_define_const_str(read, "read", 3470762949u, 0, 4, NULL);
|
||||
be_define_const_str(read12, "read12", 4291076970u, 0, 6, &be_const_str_tomap);
|
||||
|
@ -1149,6 +1150,6 @@ static const bstring* const m_string_table[] = {
|
|||
|
||||
static const struct bconststrtab m_const_string_table = {
|
||||
.size = 374,
|
||||
.count = 771,
|
||||
.count = 772,
|
||||
.table = m_string_table
|
||||
};
|
||||
|
|
|
@ -1,88 +1,89 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_map) {
|
||||
{ be_const_key(run_deferred, -1), be_const_closure(Tasmota_run_deferred_closure) },
|
||||
{ be_const_key(publish, -1), be_const_func(l_publish) },
|
||||
{ be_const_key(try_rule, 5), be_const_closure(Tasmota_try_rule_closure) },
|
||||
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
|
||||
{ be_const_key(get_free_heap, 47), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(eth, 56), be_const_func(l_eth) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(Tasmota_exec_rules_closure) },
|
||||
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(chars_in_string, 55), be_const_closure(Tasmota_chars_in_string_closure) },
|
||||
{ be_const_key(hs2rgb, -1), be_const_closure(Tasmota_hs2rgb_closure) },
|
||||
{ be_const_key(time_str, 0), be_const_closure(Tasmota_time_str_closure) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(Tasmota_set_light_closure) },
|
||||
{ be_const_key(response_append, 1), be_const_func(l_respAppend) },
|
||||
{ be_const_key(gen_cb, -1), be_const_closure(Tasmota_gen_cb_closure) },
|
||||
{ be_const_key(remove_driver, 50), be_const_closure(Tasmota_remove_driver_closure) },
|
||||
{ be_const_key(event, -1), be_const_closure(Tasmota_event_closure) },
|
||||
{ be_const_key(exec_cmd, 2), be_const_closure(Tasmota_exec_cmd_closure) },
|
||||
{ be_const_key(rtc, 12), be_const_func(l_rtc) },
|
||||
{ be_const_key(read_sensors, -1), be_const_func(l_read_sensors) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(Tasmota_set_timer_closure) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(exec_tele, -1), be_const_closure(Tasmota_exec_tele_closure) },
|
||||
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
|
||||
{ be_const_key(cmd_res, -1), be_const_var(0) },
|
||||
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
|
||||
{ be_const_key(add_driver, 14), be_const_closure(Tasmota_add_driver_closure) },
|
||||
{ be_const_key(_timers, -1), be_const_var(1) },
|
||||
{ be_const_key(add_rule, -1), be_const_closure(Tasmota_add_rule_closure) },
|
||||
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(remove_rule, 9), be_const_closure(Tasmota_remove_rule_closure) },
|
||||
{ be_const_key(web_send, 16), be_const_func(l_webSend) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(remove_timer, 10), be_const_closure(Tasmota_remove_timer_closure) },
|
||||
{ be_const_key(memory, 52), be_const_func(l_memory) },
|
||||
{ be_const_key(global, 71), be_const_var(2) },
|
||||
{ be_const_key(find_op, -1), be_const_closure(Tasmota_find_op_closure) },
|
||||
{ be_const_key(yield, 60), be_const_func(l_yield) },
|
||||
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(kv, 43), be_const_closure(Tasmota_kv_closure) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(Tasmota_wire_scan_closure) },
|
||||
{ be_const_key(wifi, 37), be_const_func(l_wifi) },
|
||||
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
|
||||
{ be_const_key(gc, -1), be_const_closure(Tasmota_gc_closure) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(get_light, -1), be_const_closure(Tasmota_get_light_closure) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(settings, -1), be_const_var(3) },
|
||||
{ be_const_key(cmd, 62), be_const_closure(Tasmota_cmd_closure) },
|
||||
{ be_const_key(load, -1), be_const_closure(Tasmota_load_closure) },
|
||||
{ be_const_key(strptime, -1), be_const_func(l_strptime) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(4) },
|
||||
{ be_const_key(find_key_i, 25), be_const_closure(Tasmota_find_key_i_closure) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
|
||||
{ be_const_key(save, 36), be_const_func(l_save) },
|
||||
{ be_const_key(millis, -1), be_const_func(l_millis) },
|
||||
{ be_const_key(wire2, -1), be_const_var(5) },
|
||||
{ be_const_key(wire1, 72), be_const_var(6) },
|
||||
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(scale_uint, 51), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
|
||||
{ be_const_key(_debug_present, -1), be_const_var(7) },
|
||||
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(8) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(Tasmota_add_cmd_closure) },
|
||||
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
|
||||
{ be_const_key(log, -1), be_const_func(l_logInfo) },
|
||||
{ be_const_key(arch, -1), be_const_func(l_arch) },
|
||||
{ be_const_key(resp_cmnd_done, 74), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(_rules, 38), be_const_var(9) },
|
||||
{ be_const_key(remove_cmd, -1), be_const_closure(Tasmota_remove_cmd_closure) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(Tasmota_set_light_closure) },
|
||||
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
|
||||
{ be_const_key(_timers, -1), be_const_var(0) },
|
||||
{ be_const_key(try_rule, -1), be_const_closure(Tasmota_try_rule_closure) },
|
||||
{ be_const_key(cmd, -1), be_const_closure(Tasmota_cmd_closure) },
|
||||
{ be_const_key(_rules, 58), be_const_var(1) },
|
||||
{ be_const_key(get_switch, 29), be_const_func(l_getswitch) },
|
||||
{ be_const_key(_debug_present, 38), be_const_var(2) },
|
||||
{ be_const_key(find_op, 4), be_const_closure(Tasmota_find_op_closure) },
|
||||
{ be_const_key(wire1, -1), be_const_var(3) },
|
||||
{ be_const_key(resp_cmnd_failed, 24), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(exec_cmd, 57), be_const_closure(Tasmota_exec_cmd_closure) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(hs2rgb, 41), be_const_closure(Tasmota_hs2rgb_closure) },
|
||||
{ be_const_key(gc, -1), be_const_closure(Tasmota_gc_closure) },
|
||||
{ be_const_key(kv, -1), be_const_closure(Tasmota_kv_closure) },
|
||||
{ be_const_key(add_rule, -1), be_const_closure(Tasmota_add_rule_closure) },
|
||||
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(event, 40), be_const_closure(Tasmota_event_closure) },
|
||||
{ be_const_key(rtc, 23), be_const_func(l_rtc) },
|
||||
{ be_const_key(cmd_res, -1), be_const_var(4) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(Tasmota_chars_in_string_closure) },
|
||||
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
|
||||
{ be_const_key(get_light, -1), be_const_closure(Tasmota_get_light_closure) },
|
||||
{ be_const_key(read_sensors, 16), be_const_func(l_read_sensors) },
|
||||
{ be_const_key(settings, -1), be_const_var(5) },
|
||||
{ be_const_key(global, -1), be_const_var(6) },
|
||||
{ be_const_key(save, -1), be_const_func(l_save) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(Tasmota_set_timer_closure) },
|
||||
{ be_const_key(time_str, -1), be_const_closure(Tasmota_time_str_closure) },
|
||||
{ be_const_key(response_append, 0), be_const_func(l_respAppend) },
|
||||
{ be_const_key(remove_driver, -1), be_const_closure(Tasmota_remove_driver_closure) },
|
||||
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(load, -1), be_const_closure(Tasmota_load_closure) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(millis, 73), be_const_func(l_millis) },
|
||||
{ be_const_key(log, -1), be_const_func(l_logInfo) },
|
||||
{ be_const_key(strftime, 1), be_const_func(l_strftime) },
|
||||
{ be_const_key(publish_result, 60), be_const_func(l_publish_result) },
|
||||
{ be_const_key(_drivers, -1), be_const_var(7) },
|
||||
{ be_const_key(run_deferred, 26), be_const_closure(Tasmota_run_deferred_closure) },
|
||||
{ be_const_key(init, -1), be_const_closure(Tasmota_init_closure) },
|
||||
{ be_const_key(wd, 53), be_const_var(10) },
|
||||
{ be_const_key(remove_cmd, 67), be_const_closure(Tasmota_remove_cmd_closure) },
|
||||
{ be_const_key(random_byte, 14), be_const_func(t_random_byte) },
|
||||
{ be_const_key(_cmd, 70), be_const_func(l_cmd) },
|
||||
{ be_const_key(remove_timer, -1), be_const_closure(Tasmota_remove_timer_closure) },
|
||||
{ be_const_key(remove_rule, 71), be_const_closure(Tasmota_remove_rule_closure) },
|
||||
{ be_const_key(resolvecmnd, 6), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(_settings_ptr, 56), be_const_comptr(&Settings) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(memory, -1), be_const_func(l_memory) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(wire_scan, 68), be_const_closure(Tasmota_wire_scan_closure) },
|
||||
{ be_const_key(strptime, -1), be_const_func(l_strptime) },
|
||||
{ be_const_key(_global_addr, 55), be_const_comptr(&TasmotaGlobal) },
|
||||
{ be_const_key(add_driver, -1), be_const_closure(Tasmota_add_driver_closure) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(Tasmota_exec_rules_closure) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(Tasmota_add_cmd_closure) },
|
||||
{ be_const_key(find_key_i, -1), be_const_closure(Tasmota_find_key_i_closure) },
|
||||
{ be_const_key(set_power, 21), be_const_func(l_setpower) },
|
||||
{ be_const_key(wire2, -1), be_const_var(8) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(wd, -1), be_const_var(9) },
|
||||
{ be_const_key(web_send, -1), be_const_func(l_webSend) },
|
||||
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(yield, -1), be_const_func(l_yield) },
|
||||
{ be_const_key(resp_cmnd, 69), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(publish, -1), be_const_func(l_publish) },
|
||||
{ be_const_key(_ccmd, -1), be_const_var(10) },
|
||||
{ be_const_key(eth, -1), be_const_func(l_eth) },
|
||||
{ be_const_key(exec_tele, -1), be_const_closure(Tasmota_exec_tele_closure) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_map,
|
||||
77
|
||||
78
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
|
|
@ -557,6 +557,13 @@ extern "C" {
|
|||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `random_byte() -> int`
|
||||
// returns a single byte (0..255) from a good random source
|
||||
int32_t t_random_byte(bvm *vm) {
|
||||
be_pushint(vm, esp_random() & 0xFF);
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
|
Loading…
Reference in New Issue