[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

@@ -277,8 +277,8 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
*status = HAL_HANDLE_ERROR;
return;
}
// TODO(Thad) Figure this out
// mimics athena HAL
port->filterIndex = filterIndex % 4;
}
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
@@ -287,8 +287,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return 0;
// TODO(Thad) Figure this out
return port->filterIndex;
}
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {