Merge pull request #13022 from s-hadinger/berry_strftime

Berry strftime
This commit is contained in:
s-hadinger 2021-08-30 23:32:16 +02:00 committed by GitHub
commit 01e3a2feb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 60 deletions

View File

@ -15,6 +15,7 @@ extern int l_millis(bvm *vm);
extern int l_timereached(bvm *vm); extern int l_timereached(bvm *vm);
extern int l_rtc(bvm *vm); extern int l_rtc(bvm *vm);
extern int l_time_dump(bvm *vm); extern int l_time_dump(bvm *vm);
extern int l_strftime(bvm *vm);
extern int l_memory(bvm *vm); extern int l_memory(bvm *vm);
extern int l_wifi(bvm *vm); extern int l_wifi(bvm *vm);
extern int l_eth(bvm *vm); extern int l_eth(bvm *vm);
@ -2216,6 +2217,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
time_reached, func(l_timereached) time_reached, func(l_timereached)
rtc, func(l_rtc) rtc, func(l_rtc)
time_dump, func(l_time_dump) time_dump, func(l_time_dump)
strftime, func(l_strftime)
memory, func(l_memory) memory, func(l_memory)
wifi, func(l_wifi) wifi, func(l_wifi)
eth, func(l_eth) eth, func(l_eth)

View File

@ -599,6 +599,7 @@ extern const bcstring be_const_str_SYMBOL_UP;
extern const bcstring be_const_str_lv_draw_mask_radius_param_cfg; extern const bcstring be_const_str_lv_draw_mask_radius_param_cfg;
extern const bcstring be_const_str_member; extern const bcstring be_const_str_member;
extern const bcstring be_const_str_set; extern const bcstring be_const_str_set;
extern const bcstring be_const_str_strftime;
extern const bcstring be_const_str_EPAPER29_CS; extern const bcstring be_const_str_EPAPER29_CS;
extern const bcstring be_const_str_SPI_MISO; extern const bcstring be_const_str_SPI_MISO;
extern const bcstring be_const_str_HIGH; extern const bcstring be_const_str_HIGH;

View File

@ -598,7 +598,8 @@ be_define_const_str(tolower, "tolower", 1042520049u, 0, 7, NULL);
be_define_const_str(SYMBOL_UP, "SYMBOL_UP", 3886401511u, 0, 9, &be_const_str_lv_draw_mask_radius_param_cfg); be_define_const_str(SYMBOL_UP, "SYMBOL_UP", 3886401511u, 0, 9, &be_const_str_lv_draw_mask_radius_param_cfg);
be_define_const_str(lv_draw_mask_radius_param_cfg, "lv_draw_mask_radius_param_cfg", 3889386773u, 0, 29, &be_const_str_member); be_define_const_str(lv_draw_mask_radius_param_cfg, "lv_draw_mask_radius_param_cfg", 3889386773u, 0, 29, &be_const_str_member);
be_define_const_str(member, "member", 719708611u, 0, 6, &be_const_str_set); be_define_const_str(member, "member", 719708611u, 0, 6, &be_const_str_set);
be_define_const_str(set, "set", 3324446467u, 0, 3, NULL); be_define_const_str(set, "set", 3324446467u, 0, 3, &be_const_str_strftime);
be_define_const_str(strftime, "strftime", 187738851u, 0, 8, NULL);
be_define_const_str(EPAPER29_CS, "EPAPER29_CS", 3916373594u, 0, 11, &be_const_str_SPI_MISO); be_define_const_str(EPAPER29_CS, "EPAPER29_CS", 3916373594u, 0, 11, &be_const_str_SPI_MISO);
be_define_const_str(SPI_MISO, "SPI_MISO", 150818010u, 0, 8, NULL); be_define_const_str(SPI_MISO, "SPI_MISO", 150818010u, 0, 8, NULL);
be_define_const_str(HIGH, "HIGH", 2066738941u, 0, 4, &be_const_str_MAX7219DIN); be_define_const_str(HIGH, "HIGH", 2066738941u, 0, 4, &be_const_str_MAX7219DIN);
@ -992,6 +993,6 @@ static const bstring* const m_string_table[] = {
static const struct bconststrtab m_const_string_table = { static const struct bconststrtab m_const_string_table = {
.size = 322, .size = 322,
.count = 644, .count = 645,
.table = m_string_table .table = m_string_table
}; };

View File

@ -1,72 +1,73 @@
#include "be_constobj.h" #include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_map) { static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(publish, -1), be_const_func(l_publish) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) }, { be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
{ be_const_key(event, -1), be_const_closure(event_closure) },
{ be_const_key(log, 25), be_const_func(l_logInfo) },
{ be_const_key(_drivers, -1), be_const_var(0) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(wire2, 26), be_const_var(1) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(wire1, -1), be_const_var(2) },
{ be_const_key(set_power, 46), be_const_func(l_setpower) },
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(get_light, 42), be_const_closure(get_light_closure) },
{ be_const_key(_rules, 54), be_const_var(3) },
{ be_const_key(run_deferred, 19), be_const_closure(run_deferred_closure) },
{ be_const_key(try_rule, 18), be_const_closure(try_rule_closure) },
{ be_const_key(remove_cmd, 41), be_const_closure(remove_cmd_closure) },
{ be_const_key(add_driver, 0), be_const_closure(add_driver_closure) },
{ be_const_key(get_power, 36), be_const_func(l_getpower) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(_timers, -1), be_const_var(4) },
{ be_const_key(add_rule, 33), be_const_closure(add_rule_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(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
{ be_const_key(millis, -1), be_const_func(l_millis) },
{ be_const_key(get_option, 52), be_const_func(l_getoption) },
{ be_const_key(eth, -1), be_const_func(l_eth) },
{ be_const_key(wifi, 22), be_const_func(l_wifi) },
{ be_const_key(response_append, 43), be_const_func(l_respAppend) },
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
{ be_const_key(set_timer, 28), be_const_closure(set_timer_closure) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(memory, 47), be_const_func(l_memory) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(web_send_decimal, 44), be_const_func(l_webSendDecimal) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(web_send, 56), be_const_func(l_webSend) },
{ be_const_key(_ccmd, -1), be_const_var(5) },
{ be_const_key(i2c_enabled, 48), be_const_func(l_i2cenabled) },
{ be_const_key(save, -1), be_const_func(l_save) },
{ be_const_key(exec_cmd, 2), be_const_closure(exec_cmd_closure) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) }, { be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) }, { be_const_key(wire2, -1), be_const_var(0) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, { be_const_key(_cb, -1), be_const_var(1) },
{ be_const_key(delay, -1), be_const_func(l_delay) }, { be_const_key(web_send, -1), be_const_func(l_webSend) },
{ be_const_key(_cb, -1), be_const_var(6) }, { be_const_key(wire_scan, 43), be_const_closure(wire_scan_closure) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, { be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(eth, 11), be_const_func(l_eth) },
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
{ be_const_key(response_append, -1), be_const_func(l_respAppend) },
{ be_const_key(wifi, 2), be_const_func(l_wifi) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(cmd, 32), be_const_closure(cmd_closure) },
{ be_const_key(resp_cmnd_failed, 6), be_const_func(l_respCmndFailed) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(event, -1), be_const_closure(event_closure) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(publish, 41), be_const_func(l_publish) },
{ be_const_key(_rules, -1), be_const_var(2) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(time_dump, 50), be_const_func(l_time_dump) },
{ be_const_key(_timers, -1), be_const_var(3) },
{ be_const_key(wire1, -1), be_const_var(4) },
{ be_const_key(add_cmd, 35), be_const_closure(add_cmd_closure) },
{ be_const_key(add_driver, 56), be_const_closure(add_driver_closure) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(exec_cmd, 16), be_const_closure(exec_cmd_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
{ be_const_key(find_op, 24), be_const_closure(find_op_closure) },
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ 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(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(save, 58), be_const_func(l_save) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
{ be_const_key(yield, -1), be_const_func(l_yield) }, { be_const_key(yield, -1), be_const_func(l_yield) },
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) }, { be_const_key(_ccmd, -1), be_const_var(5) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(millis, 8), be_const_func(l_millis) },
{ be_const_key(_drivers, -1), be_const_var(6) },
{ be_const_key(load, 29), be_const_closure(load_closure) },
{ be_const_key(run_deferred, 5), be_const_closure(run_deferred_closure) },
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(time_str, 21), be_const_closure(time_str_closure) },
{ be_const_key(add_rule, 26), be_const_closure(add_rule_closure) },
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(time_reached, 22), be_const_func(l_timereached) },
{ be_const_key(chars_in_string, 7), be_const_closure(chars_in_string_closure) },
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
}; };
static be_define_const_map( static be_define_const_map(
be_class_tasmota_map, be_class_tasmota_map,
61 62
); );
BE_EXPORT_VARIABLE be_define_const_class( BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -279,6 +279,20 @@ extern "C" {
be_raise(vm, kTypeError, nullptr); be_raise(vm, kTypeError, nullptr);
} }
int32_t l_strftime(bvm *vm) {
int32_t argc = be_top(vm); // Get the number of arguments
if (argc == 3 && be_isstring(vm, 2) && be_isint(vm, 3)) {
const char * format = be_tostring(vm, 2);
time_t ts = be_toint(vm, 3);
struct tm *t = gmtime(&ts);
char s[64] = {0};
strftime(s, sizeof(s), format, t);
be_pushstring(vm, s);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Berry: tasmota.delay(timer:int) -> nil // Berry: tasmota.delay(timer:int) -> nil
// //
int32_t l_delay(struct bvm *vm); int32_t l_delay(struct bvm *vm);