Skip to content

Commit 12f78b8

Browse files
committedNov 29, 2024
analog/filter: fix filtering for button message type
1 parent 76824e5 commit 12f78b8

File tree

1 file changed

+12
-4
lines changed
  • src/firmware/application/io/analog

1 file changed

+12
-4
lines changed
 

‎src/firmware/application/io/analog/Filter.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,28 @@ namespace io
5454
// avoid filtering in this case for faster response
5555
if (descriptor.type == Analog::type_t::BUTTON)
5656
{
57+
bool newValue = _lastStableValue[index];
58+
5759
if (descriptor.value < _adcConfig.DIGITAL_VALUE_THRESHOLD_OFF)
5860
{
59-
descriptor.value = 1;
61+
newValue = true;
6062
}
6163
else if (descriptor.value > _adcConfig.DIGITAL_VALUE_THRESHOLD_ON)
6264
{
63-
descriptor.value = 0;
65+
newValue = false;
6466
}
6567
else
6668
{
67-
descriptor.value = 0;
69+
return false;
70+
}
71+
72+
if (newValue != _lastStableValue[index])
73+
{
74+
_lastStableValue[index] = newValue;
75+
return true;
6876
}
6977

70-
return true;
78+
return false;
7179
}
7280

7381
const bool FAST_FILTER = (core::mcu::timing::ms() - _lastStableMovementTime[index]) < FAST_FILTER_ENABLE_AFTER_MS;

0 commit comments

Comments
 (0)
Failed to load comments.