31 int process(uint16_t value, uint8_t n_steps) {
32 if (n_steps < 2)
return 0;
35 int raw_step = (
static_cast<uint32_t
>(value) * n_steps) >> 16;
36 if (raw_step >= n_steps) raw_step = n_steps - 1;
39 if (!initialized_ || n_steps != last_n_steps_) {
42 last_n_steps_ = n_steps;
47 if (raw_step == step_)
return step_;
51 uint32_t step_width = 65536u / n_steps;
53 uint32_t margin = (step_width * hysteresis_) >> 8;
55 if (raw_step > step_) {
57 uint32_t threshold =
static_cast<uint32_t
>(step_ + 1) * step_width + margin;
58 if (value >= threshold) {
63 uint32_t boundary =
static_cast<uint32_t
>(step_) * step_width;
64 if (boundary >= margin && value <= boundary - margin) {
66 }
else if (boundary < margin && value == 0) {