mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 02:36:35 +00:00
Berry fix tasmota.get_power(index)
(#18237)
This commit is contained in:
parent
4fd6694efc
commit
a36edadc0f
@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Refactor energy monitoring reducing stack usage and solve inherent exceptions and watchdogs (#18164)
|
- Refactor energy monitoring reducing stack usage and solve inherent exceptions and watchdogs (#18164)
|
||||||
|
- Berry fix `tasmota.get_power(index)`
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -708,17 +708,25 @@ extern "C" {
|
|||||||
int32_t l_getpower(bvm *vm) {
|
int32_t l_getpower(bvm *vm) {
|
||||||
power_t pow = TasmotaGlobal.power;
|
power_t pow = TasmotaGlobal.power;
|
||||||
int32_t top = be_top(vm); // Get the number of arguments
|
int32_t top = be_top(vm); // Get the number of arguments
|
||||||
if (top == 2 && be_isint(vm, 2)) {
|
if (top >= 2 && be_isint(vm, 2)) {
|
||||||
pow = be_toint(vm, 2);
|
int32_t idx = be_toint(vm, 2);
|
||||||
}
|
if (idx >= 0 && idx < TasmotaGlobal.devices_present) {
|
||||||
be_newobject(vm, "list");
|
be_pushbool(vm, bitRead(pow, idx));
|
||||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
be_return(vm);
|
||||||
be_pushbool(vm, bitRead(pow, i));
|
} else {
|
||||||
be_data_push(vm, -2);
|
be_return_nil(vm);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no parameter, return an array of all values
|
||||||
|
be_newobject(vm, "list");
|
||||||
|
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||||
|
be_pushbool(vm, bitRead(pow, i));
|
||||||
|
be_data_push(vm, -2);
|
||||||
|
be_pop(vm, 1);
|
||||||
|
}
|
||||||
be_pop(vm, 1);
|
be_pop(vm, 1);
|
||||||
|
be_return(vm); // Return
|
||||||
}
|
}
|
||||||
be_pop(vm, 1);
|
|
||||||
be_return(vm); // Return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t l_setpower(bvm *vm);
|
int32_t l_setpower(bvm *vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user