[hal] Use last error reporting instead of PARAMETER_OUT_OF_RANGE (#3328)

Makes the error messages much more specific to each error.
This commit is contained in:
Thad House
2021-05-01 13:22:08 -07:00
committed by GitHub
parent 23d2326d1d
commit 3c08461685
15 changed files with 89 additions and 21 deletions

View File

@@ -7,6 +7,7 @@
#include "ConstantsInternal.h"
#include "DigitalInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/HAL.h"
#include "hal/handles/LimitedHandleResource.h"
@@ -146,6 +147,9 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
// TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only
// supports DownSource in TwoPulse and ExternalDirection modes.");
*status = PARAMETER_OUT_OF_RANGE;
hal::SetLastError(status,
"Counter only supports DownSource in TwoPulse and "
"ExternalDirection mode.");
return;
}
@@ -260,6 +264,11 @@ void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
}
if (samplesToAverage < 1 || samplesToAverage > 127) {
*status = PARAMETER_OUT_OF_RANGE;
hal::SetLastError(
status,
"Samples to average must be between 1 and 127 inclusive. Requested " +
wpi::Twine(samplesToAverage));
return;
}
counter->counter->writeTimerConfig_AverageSize(samplesToAverage, status);
}