diff --git a/src/firmware/application/io/analog/Filter.h b/src/firmware/application/io/analog/Filter.h index 95c22ff90..c6d690f00 100644 --- a/src/firmware/application/io/analog/Filter.h +++ b/src/firmware/application/io/analog/Filter.h @@ -54,20 +54,28 @@ namespace io // avoid filtering in this case for faster response if (descriptor.type == Analog::type_t::BUTTON) { + bool newValue = _lastStableValue[index]; + if (descriptor.value < _adcConfig.DIGITAL_VALUE_THRESHOLD_OFF) { - descriptor.value = 1; + newValue = true; } else if (descriptor.value > _adcConfig.DIGITAL_VALUE_THRESHOLD_ON) { - descriptor.value = 0; + newValue = false; } else { - descriptor.value = 0; + return false; + } + + if (newValue != _lastStableValue[index]) + { + _lastStableValue[index] = newValue; + return true; } - return true; + return false; } const bool FAST_FILTER = (core::mcu::timing::ms() - _lastStableMovementTime[index]) < FAST_FILTER_ENABLE_AFTER_MS;