Skip to content

Commit

Permalink
analog/filter: fix filtering for button message type
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Nov 29, 2024
1 parent 76824e5 commit 12f78b8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/firmware/application/io/analog/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 12f78b8

Please sign in to comment.