mirror of https://github.com/arendst/Tasmota.git
Berry improve tasmota.scale_uint() (#19197)
This commit is contained in:
parent
9f16f09f29
commit
1a91dc441b
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue