From 12f78b867cfa4a427aa51330dcacad48549990d2 Mon Sep 17 00:00:00 2001 From: paradajz <2544094+paradajz@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:07:24 +0000 Subject: [PATCH] analog/filter: fix filtering for button message type --- src/firmware/application/io/analog/Filter.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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;