mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[wpimath] Fix Debouncer type-changing behavior (#7870)
Closes #7867 Properly resets the baseline upon switching the debounce type, and adds a test for such. Signed-off-by: swurl <swurl@swurl.xyz>
This commit is contained in:
@@ -40,11 +40,7 @@ public class Debouncer {
|
||||
|
||||
resetTimer();
|
||||
|
||||
m_baseline =
|
||||
switch (m_debounceType) {
|
||||
case kBoth, kRising -> false;
|
||||
case kFalling -> true;
|
||||
};
|
||||
m_baseline = m_debounceType == DebounceType.kFalling;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +110,8 @@ public class Debouncer {
|
||||
*/
|
||||
public void setDebounceType(DebounceType type) {
|
||||
m_debounceType = type;
|
||||
|
||||
m_baseline = m_debounceType == DebounceType.kFalling;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,15 +10,7 @@ using namespace frc;
|
||||
|
||||
Debouncer::Debouncer(units::second_t debounceTime, DebounceType type)
|
||||
: m_debounceTime(debounceTime), m_debounceType(type) {
|
||||
switch (type) {
|
||||
case DebounceType::kBoth: // fall-through
|
||||
case DebounceType::kRising:
|
||||
m_baseline = false;
|
||||
break;
|
||||
case DebounceType::kFalling:
|
||||
m_baseline = true;
|
||||
break;
|
||||
}
|
||||
m_baseline = m_debounceType == DebounceType::kFalling;
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,11 @@ class WPILIB_DLLEXPORT Debouncer {
|
||||
*
|
||||
* @param type Which type of state change the debouncing will be performed on.
|
||||
*/
|
||||
constexpr void SetDebounceType(DebounceType type) { m_debounceType = type; }
|
||||
constexpr void SetDebounceType(DebounceType type) {
|
||||
m_debounceType = type;
|
||||
|
||||
m_baseline = m_debounceType == DebounceType::kFalling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the debounce type.
|
||||
|
||||
@@ -84,5 +84,6 @@ class DebouncerTest {
|
||||
debouncer.setDebounceType(Debouncer.DebounceType.kFalling);
|
||||
|
||||
assertSame(debouncer.getDebounceType(), Debouncer.DebounceType.kFalling);
|
||||
assertTrue(debouncer.calculate(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +72,6 @@ TEST_F(DebouncerTest, DebounceParams) {
|
||||
|
||||
EXPECT_TRUE(debouncer.GetDebounceType() ==
|
||||
frc::Debouncer::DebounceType::kFalling);
|
||||
|
||||
EXPECT_TRUE(debouncer.Calculate(false));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user