From edda5ddc3312034ec9184410002662c63c54e29a Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:08:11 +0100 Subject: [PATCH] Berry `tasmota.webcolor` (#20454) --- CHANGELOG.md | 1 + .../berry_tasmota/src/be_tasmota_lib.c | 3 +++ .../xdrv_52_3_berry_tasmota.ino | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d521e1e5c..556181f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - Berry `debug_panel.tapp` to display real-time heap and wifi rssi - Berry `webserver.header` to read browser sent headers - Berry provide lightweight options for `tasmota.wifi/eth/memory/rtc` +- Berry `tasmota.webcolor` ### Breaking Changed diff --git a/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c b/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c index 528a3b8b8..54449644d 100644 --- a/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c @@ -56,6 +56,8 @@ extern int l_respAppend(bvm *vm); extern int l_webSend(bvm *vm); extern int l_webSendDecimal(bvm *vm); +extern int l_webcolor(bvm *vm); + extern int l_getlight(bvm *vm); extern int l_setlight(bvm *vm); extern int l_getpower(bvm *vm); @@ -143,6 +145,7 @@ class be_class_tasmota (scope: global, name: Tasmota) { response_append, func(l_respAppend) web_send, func(l_webSend) web_send_decimal, func(l_webSendDecimal) + webcolor, static_func(l_webcolor) get_power, func(l_getpower) set_power, func(l_setpower) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino index f82bb0fb9..563abacef 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino @@ -820,6 +820,33 @@ extern "C" { be_raise(vm, kTypeError, nullptr); } + // get webcolors + int32_t l_webcolor(bvm *vm); + int32_t l_webcolor(bvm *vm) { + char tmp[16]; + int32_t top = be_top(vm); // Get the number of arguments + if (top >= 1 && be_isint(vm, 1)) { // argument is int + int32_t idx = be_toint(vm, 1); + if (idx >= 0 && idx < COL_LAST) { + snprintf_P(tmp, sizeof(tmp), PSTR("#%06x"), WebColor(idx)); + be_pushstring(vm, tmp); + be_return(vm); + } else { + be_return_nil(vm); + } + } else { + be_newobject(vm, "list"); + for (uint32_t i = 0; i < COL_LAST; i++) { + snprintf_P(tmp, sizeof(tmp), PSTR("#%06x"), WebColor(i)); + be_pushstring(vm, tmp); + be_data_push(vm, -2); + be_pop(vm, 1); + } + be_pop(vm, 1); + be_return(vm); + } + } + // get power int32_t l_getpower(bvm *vm); int32_t l_getpower(bvm *vm) {