mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user