[wpilib, hal] DigitalGlitchFilter: Fix sim crash and clean up construction (#6937)

Fixes error when >3 are constructed- in java, m_filterAllocated[index] would be evaluated before the bounds check and throw IndexOutOfBounds, in c++ a vague assertion error would be thrown.

Makes DoAdd static in c++

Makes the error message when HAL_SetFilterSelect fails consistent with java
This commit is contained in:
Ryan Blue
2024-08-11 02:30:02 -04:00
committed by GitHub
parent c13c512221
commit dd99ff420c
5 changed files with 61 additions and 30 deletions

View File

@@ -117,12 +117,20 @@ class DigitalGlitchFilter : public wpi::Sendable,
void InitSendable(wpi::SendableBuilder& builder) override;
private:
int m_channelIndex;
// Sets the filter for the input to be the requested index. A value of 0
// disables the filter, and the filter value must be between 1 and 3,
// inclusive.
void DoAdd(DigitalSource* input, int requested_index);
static void DoAdd(DigitalSource* input, int requested_index);
/**
* Allocates the next available filter index, or -1 if there are no filters
* available.
* @return the filter index
*/
static int AllocateFilterIndex();
int m_channelIndex = -1;
static wpi::mutex m_mutex;
static std::array<bool, 3> m_filterAllocated;
};