Berry `tasmota.webcolor` (#20454)

This commit is contained in:
s-hadinger 2024-01-10 09:08:11 +01:00 committed by GitHub
parent 453a3462b7
commit edda5ddc33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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) {