Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Berry improve tasmota.scale_uint() #19197

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/libesp32/berry_tasmota/src/be_tasmota_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
yield, func(l_yield)
delay, func(l_delay)
delay_microseconds, func(l_delay_microseconds)
scale_uint, func(l_scaleuint)
scale_uint, static_func(l_scaleuint)
log, func(l_logInfo)
loglevel, func(l_loglevel)
save, func(l_save)
Expand Down
13 changes: 12 additions & 1 deletion tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,18 @@ extern "C" {
//
int32_t l_scaleuint(struct bvm *vm);
int32_t l_scaleuint(struct bvm *vm) {
return be_call_c_func(vm, (void*) &changeUIntScale, "i", "-iiiii");
int32_t top = be_top(vm); // Get the number of arguments
if (top == 5 && be_isint(vm, 1) && be_isint(vm, 2) && be_isint(vm, 3) && be_isint(vm, 4) && be_isint(vm, 5)) {
int32_t val = be_toint(vm, 1);
int32_t from_min = be_toint(vm, 2);
int32_t from_max = be_toint(vm, 3);
int32_t to_min = be_toint(vm, 4);
int32_t to_max = be_toint(vm, 5);
int32_t scaled = changeUIntScale(val, from_min, from_max, to_min, to_max);
be_pushint(vm, scaled);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}

int32_t l_respCmnd(bvm *vm);
Expand Down