Skip to content

Commit

Permalink
Berry improve tasmota.scale_uint() (#19197)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Jul 26, 2023
1 parent 9f16f09 commit 1a91dc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 1a91dc4

Please sign in to comment.