clamp Helper

template<size_t MaxDeps = 8, typename Source>
auto RxESP32::Helpers::Numerical::clamp(Source &source, decltype(source.get()) min_val, decltype(source.get()) max_val, const typename Computed<decltype(source.get()), 1, MaxDeps>::Options &options = {})

Clamp source value to a range [min, max].

Creates a Computed that constrains source values to the specified range.

Since

v0.1.0

Signal<int> input(0);
auto limited = clamp(input, -100, 100);

input.set(150);   // limited.get() == 100
input.set(-200);  // limited.get() == -100
input.set(50);    // limited.get() == 50

Warning

Only accepts arithmetic types (integral and floating-point).

Template Parameters:
size_t MaxDeps = 8

Maximum number of dependents for the computed signal.

Parameters:
Source &source

Source (determines result type).

decltype(source.get()) min_val

Minimum allowed value.

decltype(source.get()) max_val

Maximum allowed value.

const typename Computed<decltype(source.get()), 1, MaxDeps>::Options &options = {}

Optional Computed configuration.

Returns:

Computed with clamped values.

See Also