mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[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:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
@@ -110,8 +111,11 @@ void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (length > HAL_kAddressableLEDMaxLength) {
|
||||
if (length > HAL_kAddressableLEDMaxLength || length < 0) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "LED length must be less than or equal to " +
|
||||
wpi::Twine(HAL_kAddressableLEDMaxLength) +
|
||||
". " + wpi::Twine(length) + " was requested");
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].length = length;
|
||||
@@ -127,6 +131,10 @@ void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle,
|
||||
}
|
||||
if (length > SimAddressableLEDData[led->index].length) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status,
|
||||
"Data length must be less than or equal to " +
|
||||
wpi::Twine(SimAddressableLEDData[led->index].length) +
|
||||
". " + wpi::Twine(length) + " was requested");
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].SetData(data, length);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "CounterInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
@@ -246,6 +247,7 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
|
||||
|
||||
if (minRate == 0.0) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "minRate must not be 0");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -262,6 +264,7 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
|
||||
|
||||
if (distancePerPulse == 0.0) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "distancePerPulse must not be 0");
|
||||
return;
|
||||
}
|
||||
encoder->distancePerPulse = distancePerPulse;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "CANAPIInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/CANAPI.h"
|
||||
#include "hal/Errors.h"
|
||||
@@ -27,6 +28,7 @@ extern "C" {
|
||||
HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, "Invalid pdp module " + wpi::Twine(module));
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
hal::init::CheckInit();
|
||||
|
||||
Reference in New Issue
Block a user