-
Notifications
You must be signed in to change notification settings - Fork 658
Description
Is your feature request related to a problem? Please describe.
Example: With a new Debouncer(1, DebounceType.kFalling)
, it's frustrating that we can't tell it to override to read false
if hasExpired()
is false
(like in the first 1 second or later). A hard reset is sometimes helpful if we know the final state (false
in this example) of some operation and don't want the old state (true
) to persist at all after the operation completes.
The issue boils down to the fact that we can't force a change in state, even if we as programmers know what the value should be.
Describe the solution you'd like
I'd like to propose a new method reset()
that would tell the debouncer to ignore the "baseline" and just return the input value (until it resets the timer). For example, with a debouncer with type kFalling
, calling reset()
would cause any subsequent calls to debouncer.calculate(false)
to return false until a new true
was passed in.
This could be done by wrapping the last timestamp as an Option<Double>
in Java, and setting it to Option.empty()
upon a call to reset()
. The internal method resetTimer()
would set it back to a non-empty value. A call to hasExpired()
would return true
if the last timestamp is empty.
Describe alternatives you've considered
This could be done with some boolean flag, but it's more easily done with just an optional type - and it provides better context; we want to show that this value might not exist if we've reset the debouncer.
What my team had to do to get this feature was just copy-paste the WPILib impl of Debouncer
into a new class, SuperDebouncer
and add the change - lots of redundant code, not linked to the first, and just for one little feature.
Additional context
I'd open a PR but I'm not comfortable enough with C++ to actually implement it in both Java and C++; I don't know if there's a good way to start working on this by writing the Java version and then asking for help with the C++ version from somebody else?