diff --git a/hal/src/main/native/cpp/ErrorHandling.cpp b/hal/src/main/native/cpp/ErrorHandling.cpp index 35aef022413..5304b211cd6 100644 --- a/hal/src/main/native/cpp/ErrorHandling.cpp +++ b/hal/src/main/native/cpp/ErrorHandling.cpp @@ -21,24 +21,23 @@ static LastErrorStorage& GetThreadLastError() { } namespace wpi::hal { -void SetLastError(int32_t* status, std::string_view value) { +void SetLastError(HAL_Status status, std::string_view value) { LastErrorStorage& lastError = GetThreadLastError(); lastError.message = value; - lastError.status = *status; - *status = HAL_USE_LAST_ERROR; + lastError.status = status; } -void SetLastErrorIndexOutOfRange(int32_t* status, std::string_view message, +void SetLastErrorIndexOutOfRange(HAL_Status status, std::string_view message, int32_t minimum, int32_t maximum, int32_t requested) { SetLastError( status, fmt::format("{}\n Status: {}\n Minimum: {} Maximum: {} Requested: {}", - message, *status, minimum, maximum, requested)); + message, status, minimum, maximum, requested)); } -void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message, - int32_t channel, +void SetLastErrorPreviouslyAllocated(HAL_Status status, + std::string_view message, int32_t channel, std::string_view previousAllocation) { wpi::hal::SetLastError( status, fmt::format("{} {} previously allocated.\n" @@ -49,7 +48,7 @@ void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message, } // namespace wpi::hal extern "C" { -const char* HAL_GetLastError(int32_t* status) { +const char* HAL_GetLastError(HAL_Status* status) { if (*status == HAL_USE_LAST_ERROR) { LastErrorStorage& lastError = GetThreadLastError(); *status = lastError.status; diff --git a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp index 12c6a3e921f..8de6a4861cf 100644 --- a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp +++ b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp @@ -7,6 +7,7 @@ #include "HALUtil.hpp" #include "org_wpilib_hardware_hal_AddressableLEDJNI.h" #include "wpi/hal/AddressableLED.h" +#include "wpi/hal/Types.h" #include "wpi/util/jni_util.hpp" using namespace wpi::hal; @@ -37,11 +38,11 @@ JNIEXPORT jint JNICALL Java_org_wpilib_hardware_hal_AddressableLEDJNI_initialize (JNIEnv* env, jclass, jint channel) { - int32_t status = 0; auto stack = wpi::util::java::GetJavaStackTrace(env, "org.wpilib"); - auto ret = HAL_InitializeAddressableLED(channel, stack.c_str(), &status); + HAL_AddressableLEDHandle handle; + HAL_Status status = HAL_InitializeAddressableLED(channel, stack.c_str(), &handle); CheckStatusForceThrow(env, status); - return ret; + return static_cast(handle); } /* @@ -67,9 +68,8 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_AddressableLEDJNI_setStart (JNIEnv* env, jclass, jint handle, jint start) { - int32_t status = 0; - HAL_SetAddressableLEDStart(static_cast(handle), - start, &status); + HAL_Status status = HAL_SetAddressableLEDStart(static_cast(handle), + start); CheckStatus(env, status); } @@ -82,9 +82,8 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_AddressableLEDJNI_setLength (JNIEnv* env, jclass, jint handle, jint length) { - int32_t status = 0; - HAL_SetAddressableLEDLength(static_cast(handle), - length, &status); + HAL_Status status = HAL_SetAddressableLEDLength(static_cast(handle), + length); CheckStatus(env, status); } @@ -121,11 +120,11 @@ Java_org_wpilib_hardware_hal_AddressableLEDJNI_setData return; } auto rawdata = cdata.uarray().subspan(start, len); - int32_t status = 0; - HAL_SetAddressableLEDData( + HAL_Status status = HAL_SetAddressableLEDData( outStart, rawdata.size() / 3, static_cast(colorOrder), - reinterpret_cast(rawdata.data()), &status); + reinterpret_cast(rawdata.data())); + CheckStatus(env, status); } /* @@ -160,10 +159,10 @@ Java_org_wpilib_hardware_hal_AddressableLEDJNI_setDataFromBuffer return; } auto rawdata = cdata.uarray().subspan(start, len); - int32_t status = 0; - HAL_SetAddressableLEDData( + HAL_Status status = HAL_SetAddressableLEDData( outStart, rawdata.size() / 3, static_cast(colorOrder), - reinterpret_cast(rawdata.data()), &status); + reinterpret_cast(rawdata.data())); + CheckStatus(env, status); } } // extern "C" diff --git a/hal/src/main/native/cpp/jni/AlertJNI.cpp b/hal/src/main/native/cpp/jni/AlertJNI.cpp index 61df81fee81..516801a0ff8 100644 --- a/hal/src/main/native/cpp/jni/AlertJNI.cpp +++ b/hal/src/main/native/cpp/jni/AlertJNI.cpp @@ -27,13 +27,12 @@ JNIEXPORT jint JNICALL Java_org_wpilib_hardware_hal_AlertJNI_createAlert (JNIEnv* env, jclass, jstring group, jstring text, jint level) { - int32_t status = 0; wpi::util::java::JStringRef jgroup{env, group}; wpi::util::java::JStringRef jtext{env, text}; WPI_String wpiGroup = wpi::util::make_string(jgroup); WPI_String wpiText = wpi::util::make_string(jtext); - HAL_AlertHandle alertHandle = - HAL_CreateAlert(&wpiGroup, &wpiText, level, &status); + HAL_AlertHandle alertHandle; + HAL_Status status = HAL_CreateAlert(&wpiGroup, &wpiText, level, &alertHandle); if (alertHandle <= 0 || !CheckStatusForceThrow(env, status)) { return 0; // something went wrong in HAL @@ -65,8 +64,7 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_AlertJNI_setAlertActive (JNIEnv* env, jclass cls, jint alertHandle, jboolean active) { - int32_t status = 0; - HAL_SetAlertActive((HAL_AlertHandle)alertHandle, active, &status); + HAL_Status status = HAL_SetAlertActive((HAL_AlertHandle)alertHandle, active); CheckStatus(env, status); } @@ -79,8 +77,8 @@ JNIEXPORT jboolean JNICALL Java_org_wpilib_hardware_hal_AlertJNI_isAlertActive (JNIEnv* env, jclass cls, jint alertHandle) { - int32_t status = 0; - jboolean active = HAL_IsAlertActive((HAL_AlertHandle)alertHandle, &status); + HAL_Bool active; + HAL_Status status = HAL_IsAlertActive((HAL_AlertHandle)alertHandle, &active); CheckStatus(env, status); return active; } @@ -94,10 +92,9 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_AlertJNI_setAlertText (JNIEnv* env, jclass cls, jint alertHandle, jstring text) { - int32_t status = 0; wpi::util::java::JStringRef jtext{env, text}; WPI_String wpiText = wpi::util::make_string(jtext); - HAL_SetAlertText((HAL_AlertHandle)alertHandle, &wpiText, &status); + HAL_Status status = HAL_SetAlertText((HAL_AlertHandle)alertHandle, &wpiText); CheckStatus(env, status); } @@ -110,9 +107,8 @@ JNIEXPORT jstring JNICALL Java_org_wpilib_hardware_hal_AlertJNI_getAlertText (JNIEnv* env, jclass cls, jint alertHandle) { - int32_t status = 0; WPI_String text; - HAL_GetAlertText((HAL_AlertHandle)alertHandle, &text, &status); + HAL_Status status = HAL_GetAlertText((HAL_AlertHandle)alertHandle, &text); if (!CheckStatus(env, status)) { return nullptr; } diff --git a/hal/src/main/native/cpp/jni/NotifierJNI.cpp b/hal/src/main/native/cpp/jni/NotifierJNI.cpp index 92cefa1a20f..e287935b55e 100644 --- a/hal/src/main/native/cpp/jni/NotifierJNI.cpp +++ b/hal/src/main/native/cpp/jni/NotifierJNI.cpp @@ -45,10 +45,9 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_NotifierJNI_setNotifierName (JNIEnv* env, jclass cls, jint notifierHandle, jstring name) { - int32_t status = 0; wpi::util::java::JStringRef jname{env, name}; WPI_String wpiName = wpi::util::make_string(jname); - HAL_SetNotifierName((HAL_NotifierHandle)notifierHandle, &wpiName, &status); + HAL_Status status = HAL_SetNotifierName((HAL_NotifierHandle)notifierHandle, &wpiName); CheckStatus(env, status); } @@ -76,10 +75,9 @@ Java_org_wpilib_hardware_hal_NotifierJNI_setNotifierAlarm (JNIEnv* env, jclass cls, jint notifierHandle, jlong alarmTime, jlong intervalTime, jboolean absolute, jboolean ack) { - int32_t status = 0; - HAL_SetNotifierAlarm( + HAL_Status status = HAL_SetNotifierAlarm( (HAL_NotifierHandle)notifierHandle, static_cast(alarmTime), - static_cast(intervalTime), absolute, ack, &status); + static_cast(intervalTime), absolute, ack); CheckStatus(env, status); } @@ -92,8 +90,7 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_NotifierJNI_cancelNotifierAlarm (JNIEnv* env, jclass cls, jint notifierHandle, jboolean ack) { - int32_t status = 0; - HAL_CancelNotifierAlarm((HAL_NotifierHandle)notifierHandle, ack, &status); + HAL_Status status = HAL_CancelNotifierAlarm((HAL_NotifierHandle)notifierHandle, ack); CheckStatus(env, status); } @@ -106,9 +103,7 @@ JNIEXPORT void JNICALL Java_org_wpilib_hardware_hal_NotifierJNI_acknowledgeNotifierAlarm (JNIEnv* env, jclass cls, jint notifierHandle) { - int32_t status = 0; - HAL_AcknowledgeNotifierAlarm((HAL_NotifierHandle)notifierHandle, &status); - + HAL_Status status = HAL_AcknowledgeNotifierAlarm((HAL_NotifierHandle)notifierHandle); CheckStatus(env, status); } @@ -121,10 +116,8 @@ JNIEXPORT jint JNICALL Java_org_wpilib_hardware_hal_NotifierJNI_getNotifierOverrun (JNIEnv* env, jclass cls, jint notifierHandle) { - int32_t status = 0; - int32_t count = - HAL_GetNotifierOverrun((HAL_NotifierHandle)notifierHandle, &status); - + int32_t count = 0; + HAL_Status status = HAL_GetNotifierOverrun((HAL_NotifierHandle)notifierHandle, &count); CheckStatus(env, status); return static_cast(count); diff --git a/hal/src/main/native/include/wpi/hal/AddressableLED.h b/hal/src/main/native/include/wpi/hal/AddressableLED.h index 3a6c71e172a..cea1f8a40ce 100644 --- a/hal/src/main/native/include/wpi/hal/AddressableLED.h +++ b/hal/src/main/native/include/wpi/hal/AddressableLED.h @@ -25,11 +25,12 @@ extern "C" { * @param[in] channel the smartio channel * @param[in] allocationLocation the location where the allocation is occurring * (can be null) - * @param[out] status the error code, or 0 for success - * @return Addressable LED handle + * @param[out] handle Addressable LED handle + * @return the error code, or 0 for success */ -HAL_AddressableLEDHandle HAL_InitializeAddressableLED( - int32_t channel, const char* allocationLocation, int32_t* status); +HAL_Status HAL_InitializeAddressableLED(int32_t channel, + const char* allocationLocation, + HAL_AddressableLEDHandle* handle); /** * Free the Addressable LED Handle. @@ -46,10 +47,10 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle); * * @param[in] handle the Addressable LED handle * @param[in] start the strip start, in LEDs - * @param[out] status the error code, or 0 for success + * @return the error code, or 0 for success */ -void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start, - int32_t* status); +HAL_Status HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, + int32_t start); /** * Sets the length of the LED strip. @@ -59,10 +60,10 @@ void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start, * * @param[in] handle the Addressable LED handle * @param[in] length the strip length, in LEDs - * @param[out] status the error code, or 0 for success + * @return the error code, or 0 for success */ -void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, - int32_t length, int32_t* status); +HAL_Status HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, + int32_t length); /** * Sets the led output data. @@ -74,12 +75,11 @@ void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, * @param[in] length the strip length, in LEDs * @param[in] colorOrder the color order * @param[in] data the buffer to write - * @param[out] status the error code, or 0 for success + * @return the error code, or 0 for success */ -void HAL_SetAddressableLEDData(int32_t start, int32_t length, - HAL_AddressableLEDColorOrder colorOrder, - const struct HAL_AddressableLEDData* data, - int32_t* status); +HAL_Status HAL_SetAddressableLEDData(int32_t start, int32_t length, + HAL_AddressableLEDColorOrder colorOrder, + const struct HAL_AddressableLEDData* data); #ifdef __cplusplus } // extern "C" diff --git a/hal/src/main/native/include/wpi/hal/Alert.h b/hal/src/main/native/include/wpi/hal/Alert.h index faa8f1a2a84..9237e63c323 100644 --- a/hal/src/main/native/include/wpi/hal/Alert.h +++ b/hal/src/main/native/include/wpi/hal/Alert.h @@ -49,12 +49,12 @@ HAL_ENUM(HAL_AlertLevel) { * @param group Group identifier * @param text Text to be displayed when the alert is active * @param level Alert urgency level (HAL_AlertLevel) - * @param[out] status Error status variable. 0 on success. - * @return the created alert + * @param[out] alertHandle The created alert handle + * @return Error status variable. 0 on success. */ -HAL_AlertHandle HAL_CreateAlert(const struct WPI_String* group, - const struct WPI_String* text, int32_t level, - int32_t* status); +HAL_Status HAL_CreateAlert(const struct WPI_String* group, + const struct WPI_String* text, int32_t level, + HAL_AlertHandle* alertHandle); /** * Destroys an alert. @@ -69,19 +69,18 @@ void HAL_DestroyAlert(HAL_AlertHandle alertHandle); * * @param alertHandle the alert handle * @param active true to display the alert, false to hide it - * @param[out] status Error status variable. 0 on success. + * @return Error status variable. 0 on success. */ -void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active, - int32_t* status); +HAL_Status HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active); /** * Checks if an alert is active. * * @param alertHandle the alert handle - * @param[out] status Error status variable. 0 on success. - * @return true if the alert is active + * @param[out] active true if the alert is active + * @return Error status variable. 0 on success. */ -HAL_Bool HAL_IsAlertActive(HAL_AlertHandle alertHandle, int32_t* status); +HAL_Status HAL_IsAlertActive(HAL_AlertHandle alertHandle, HAL_Bool* active); /** * Updates the text of an alert. Use this method to dynamically change the @@ -89,20 +88,20 @@ HAL_Bool HAL_IsAlertActive(HAL_AlertHandle alertHandle, int32_t* status); * * @param alertHandle the alert handle * @param text new text to be displayed when the alert is active - * @param[out] status Error status variable. 0 on success. + * @return Error status variable. 0 on success. */ -void HAL_SetAlertText(HAL_AlertHandle alertHandle, - const struct WPI_String* text, int32_t* status); +HAL_Status HAL_SetAlertText(HAL_AlertHandle alertHandle, + const struct WPI_String* text); /** * Gets the text of an alert. * * @param alertHandle the alert handle * @param text pointer to a WPI_String to be filled with the current text - * @param[out] status Error status variable. 0 on success. + * @return Error status variable. 0 on success. */ -void HAL_GetAlertText(HAL_AlertHandle alertHandle, struct WPI_String* text, - int32_t* status); +HAL_Status HAL_GetAlertText(HAL_AlertHandle alertHandle, + struct WPI_String* text); #ifdef __cplusplus } // extern "C" diff --git a/hal/src/main/native/include/wpi/hal/HAL.h b/hal/src/main/native/include/wpi/hal/HAL.h index 0e40d9ffcb3..43b7987c4d7 100644 --- a/hal/src/main/native/include/wpi/hal/HAL.h +++ b/hal/src/main/native/include/wpi/hal/HAL.h @@ -50,7 +50,7 @@ extern "C" { * @return the error message for the code. This does not need to be freed, * but can be overwritten by another hal call on the same thread. */ -const char* HAL_GetLastError(int32_t* status); +const char* HAL_GetLastError(HAL_Status* status); /** * Gets the error message for a specific status code. diff --git a/hal/src/main/native/include/wpi/hal/Notifier.h b/hal/src/main/native/include/wpi/hal/Notifier.h index c914bbdf499..48dad77ff8f 100644 --- a/hal/src/main/native/include/wpi/hal/Notifier.h +++ b/hal/src/main/native/include/wpi/hal/Notifier.h @@ -25,20 +25,20 @@ extern "C" { * A notifier is an timer that alarms at an initial and (optionally) repeated * intervals. This can be used to make precise control loops. * - * @param[out] status Error status variable. 0 on success. - * @return the created notifier + * @param[out] notifierHandle The created notifier handle. + * @return Error status. 0 on success. */ -HAL_NotifierHandle HAL_CreateNotifier(int32_t* status); +HAL_Status HAL_CreateNotifier(HAL_NotifierHandle* notifierHandle); /** * Sets the name of a notifier. * * @param[in] notifierHandle the notifier handle * @param[in] name name - * @param[out] status Error status variable. 0 on success. + * @return Error status. 0 on success. */ -void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, - const struct WPI_String* name, int32_t* status); +HAL_Status HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, + const struct WPI_String* name); /** * Destroys a notifier. @@ -65,21 +65,21 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle); * @param[in] intervalTime the periodic interval time (in microseconds) * @param[in] absolute true if the alarm time is absolute * @param[in] ack true to acknowledge any prior alarm - * @param[out] status Error status variable. 0 on success. + * @return Error status. 0 on success. */ -void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime, - uint64_t intervalTime, HAL_Bool absolute, - HAL_Bool ack, int32_t* status); +HAL_Status HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, + uint64_t alarmTime, uint64_t intervalTime, + HAL_Bool absolute, HAL_Bool ack); /** * Cancels all future notifier alarms for a notifier. * * @param[in] notifierHandle the notifier handle * @param[in] ack true to acknowledge any prior alarm - * @param[out] status Error status variable. 0 on success. + * @return Error status. 0 on success. */ -void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, - int32_t* status); +HAL_Status HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, + HAL_Bool ack); /** * Indicates the notifier alarm has been serviced. Makes no change to future @@ -89,10 +89,9 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, * ack=true), or this function must be called before waiting for the next alarm. * * @param[in] notifierHandle the notifier handle - * @param[out] status Error status variable. 0 on success. + * @return Error status. 0 on success. */ -void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle, - int32_t* status); +HAL_Status HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle); /** * Gets the overrun count for a notifier. @@ -101,11 +100,11 @@ void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle, * scheduled alarm time. * * @param[in] notifierHandle the notifier handle - * @param[out] status Error status variable. 0 on success. - * @return overrun count + * @param[out] count overrun count + * @return Error status. 0 on success. */ -int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, - int32_t* status); +HAL_Status HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, + int32_t* count); #ifdef __cplusplus } // extern "C" diff --git a/hal/src/main/native/include/wpi/hal/Notifier.hpp b/hal/src/main/native/include/wpi/hal/Notifier.hpp index f3f52148b0a..11ee84c13b8 100644 --- a/hal/src/main/native/include/wpi/hal/Notifier.hpp +++ b/hal/src/main/native/include/wpi/hal/Notifier.hpp @@ -14,10 +14,10 @@ * * @param[in] notifierHandle the notifier handle * @param[in] name name - * @param[out] status Error status variable. 0 on success. + * @return Error status. 0 on success. */ -inline void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, - std::string_view name, int32_t* status) { +inline HAL_Status HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, + std::string_view name) { WPI_String nameStr = wpi::util::make_string(name); - HAL_SetNotifierName(notifierHandle, &nameStr, status); + return HAL_SetNotifierName(notifierHandle, &nameStr); } diff --git a/hal/src/main/native/sim/AddressableLED.cpp b/hal/src/main/native/sim/AddressableLED.cpp index 4a8e030e3d1..e8e900c2185 100644 --- a/hal/src/main/native/sim/AddressableLED.cpp +++ b/hal/src/main/native/sim/AddressableLED.cpp @@ -21,24 +21,24 @@ void InitializeAddressableLED() {} } // namespace wpi::hal::init extern "C" { -HAL_AddressableLEDHandle HAL_InitializeAddressableLED( - int32_t channel, const char* allocationLocation, int32_t* status) { +HAL_Status HAL_InitializeAddressableLED(int32_t channel, + const char* allocationLocation, + HAL_AddressableLEDHandle* handle) { wpi::hal::init::CheckInit(); if (channel < 0 || channel >= kNumAddressableLEDs) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange(status, + *handle = HAL_INVALID_HANDLE; + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, "Invalid Index for AddressableLED", 0, kNumAddressableLEDs, channel); - return HAL_INVALID_HANDLE; + return HAL_USE_LAST_ERROR; } - HAL_DigitalHandle handle; - + int32_t status = 0; auto port = digitalChannelHandles->Allocate( - channel, HAL_HandleEnum::ADDRESSABLE_LED, &handle, status); + channel, HAL_HandleEnum::ADDRESSABLE_LED, handle, &status); - if (*status != 0) { + if (status != 0) { if (port) { wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, port->previousAllocation); @@ -47,7 +47,8 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED( "Invalid Index for AddressableLED", 0, kNumAddressableLEDs, channel); } - return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. + *handle = HAL_INVALID_HANDLE; + return HAL_USE_LAST_ERROR; } port->channel = static_cast(channel); @@ -57,7 +58,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED( SimAddressableLEDData[channel].initialized = true; port->previousAllocation = allocationLocation ? allocationLocation : ""; - return handle; + return HAL_SUCCESS; } void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) { @@ -71,50 +72,48 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) { SimAddressableLEDData[port->channel].initialized = false; } -void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start, - int32_t* status) { +HAL_Status HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, + int32_t start) { auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED); if (!port) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } if (start > HAL_ADDRESSABLE_LED_MAX_LEN || start < 0) { - *status = PARAMETER_OUT_OF_RANGE; wpi::hal::SetLastError( - status, + PARAMETER_OUT_OF_RANGE, fmt::format( "LED start must be less than or equal to {}. {} was requested", HAL_ADDRESSABLE_LED_MAX_LEN, start)); - return; + return HAL_USE_LAST_ERROR; } SimAddressableLEDData[port->channel].start = start; + return HAL_SUCCESS; } -void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, - int32_t length, int32_t* status) { +HAL_Status HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, + int32_t length) { auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED); if (!port) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } if (length > HAL_ADDRESSABLE_LED_MAX_LEN || length < 0) { - *status = PARAMETER_OUT_OF_RANGE; wpi::hal::SetLastError( - status, + PARAMETER_OUT_OF_RANGE, fmt::format( "LED length must be less than or equal to {}. {} was requested", HAL_ADDRESSABLE_LED_MAX_LEN, length)); - return; + return HAL_USE_LAST_ERROR; } SimAddressableLEDData[port->channel].length = length; + return HAL_SUCCESS; } -void HAL_SetAddressableLEDData(int32_t start, int32_t length, - HAL_AddressableLEDColorOrder colorOrder, - const struct HAL_AddressableLEDData* data, - int32_t* status) { +HAL_Status HAL_SetAddressableLEDData( + int32_t start, int32_t length, HAL_AddressableLEDColorOrder colorOrder, + const struct HAL_AddressableLEDData* data) { SimAddressableLEDDataBuffer->SetData(start, length, data); + return HAL_SUCCESS; } } // extern "C" diff --git a/hal/src/main/native/sim/Alert.cpp b/hal/src/main/native/sim/Alert.cpp index 25c520d416b..97a33cd755e 100644 --- a/hal/src/main/native/sim/Alert.cpp +++ b/hal/src/main/native/sim/Alert.cpp @@ -46,34 +46,31 @@ void InitializeAlert() { extern "C" { -HAL_AlertHandle HAL_CreateAlert(const WPI_String* group, const WPI_String* text, - int32_t level, int32_t* status) { +HAL_Status HAL_CreateAlert(const WPI_String* group, const WPI_String* text, + int32_t level, HAL_AlertHandle* alertHandle) { wpi::hal::init::CheckInit(); std::shared_ptr alert = std::make_shared( wpi::util::to_string_view(group), wpi::util::to_string_view(text), level); - HAL_AlertHandle handle = alertHandles->Allocate(alert); - if (handle == HAL_INVALID_HANDLE) { - *status = HAL_HANDLE_ERROR; - return HAL_INVALID_HANDLE; + *alertHandle = alertHandles->Allocate(alert); + if (*alertHandle == HAL_INVALID_HANDLE) { + return HAL_HANDLE_ERROR; } - return handle; + return HAL_SUCCESS; } void HAL_DestroyAlert(HAL_AlertHandle alertHandle) { alertHandles->Free(alertHandle); } -void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active, - int32_t* status) { +HAL_Status HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } if (active) { if (alert->activeStartTime.load(std::memory_order_relaxed) != 0) { // Already active, do nothing (avoids cost of getting time) - return; + return HAL_SUCCESS; } int64_t now = HAL_GetMonotonicTime(); int64_t expected = 0; @@ -82,37 +79,39 @@ void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active, } else { alert->activeStartTime = 0; } + return HAL_SUCCESS; } -HAL_Bool HAL_IsAlertActive(HAL_AlertHandle alertHandle, int32_t* status) { +HAL_Status HAL_IsAlertActive(HAL_AlertHandle alertHandle, HAL_Bool* active) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return false; + return HAL_HANDLE_ERROR; } - return alert->activeStartTime != 0; + *active = alert->activeStartTime != 0; + return HAL_SUCCESS; } -void HAL_SetAlertText(HAL_AlertHandle alertHandle, const WPI_String* text, - int32_t* status) { +HAL_Status HAL_SetAlertText(HAL_AlertHandle alertHandle, + const WPI_String* text) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } std::scoped_lock lock(alert->textMutex); alert->text = wpi::util::to_string_view(text); + return HAL_SUCCESS; } -void HAL_GetAlertText(HAL_AlertHandle alertHandle, struct WPI_String* text, - int32_t* status) { +HAL_Status HAL_GetAlertText(HAL_AlertHandle alertHandle, + struct WPI_String* text) { auto alert = alertHandles->Get(alertHandle); if (alert) { std::scoped_lock lock(alert->textMutex); *text = wpi::util::alloc_wpi_string(alert->text); + return HAL_SUCCESS; } else { - *status = HAL_HANDLE_ERROR; *text = WPI_String{}; + return HAL_HANDLE_ERROR; } } diff --git a/hal/src/main/native/sim/AnalogInput.cpp b/hal/src/main/native/sim/AnalogInput.cpp index 755cef541c9..928831d0072 100644 --- a/hal/src/main/native/sim/AnalogInput.cpp +++ b/hal/src/main/native/sim/AnalogInput.cpp @@ -21,9 +21,10 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( int32_t channel, const char* allocationLocation, int32_t* status) { wpi::hal::init::CheckInit(); if (channel < 0 || channel >= kNumAnalogInputs) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange( - status, "Invalid Index for Analog Input", 0, kNumAnalogInputs, channel); + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for Analog Input", 0, + kNumAnalogInputs, channel); + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } @@ -33,12 +34,13 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( if (*status != 0) { if (analog_port) { wpi::hal::SetLastErrorPreviouslyAllocated( - status, "Analog Input", channel, analog_port->previousAllocation); + *status, "Analog Input", channel, analog_port->previousAllocation); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, + wpi::hal::SetLastErrorIndexOutOfRange(*status, "Invalid Index for Analog Input", 0, kNumAnalogInputs, channel); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/sim/CTREPCM.cpp b/hal/src/main/native/sim/CTREPCM.cpp index 9a26f21cf9c..d831402f466 100644 --- a/hal/src/main/native/sim/CTREPCM.cpp +++ b/hal/src/main/native/sim/CTREPCM.cpp @@ -45,13 +45,14 @@ HAL_CTREPCMHandle HAL_InitializeCTREPCM(int32_t busId, int32_t module, if (*status != 0) { if (pcm) { - wpi::hal::SetLastErrorPreviouslyAllocated(status, "CTRE PCM", module, + wpi::hal::SetLastErrorPreviouslyAllocated(*status, "CTRE PCM", module, pcm->previousAllocation); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, + wpi::hal::SetLastErrorIndexOutOfRange(*status, "Invalid Index for CTRE PCM", 0, kNumCTREPCMModules - 1, module); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/sim/DIO.cpp b/hal/src/main/native/sim/DIO.cpp index 8bf3a24d8ec..a0ac56aef2a 100644 --- a/hal/src/main/native/sim/DIO.cpp +++ b/hal/src/main/native/sim/DIO.cpp @@ -10,6 +10,7 @@ #include "PortsInternal.hpp" #include "mockdata/DIODataInternal.hpp" #include "mockdata/DigitalPWMDataInternal.hpp" +#include "wpi/hal/Errors.h" #include "wpi/hal/handles/HandlesInternal.hpp" #include "wpi/hal/handles/LimitedHandleResource.hpp" @@ -37,9 +38,10 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input, wpi::hal::init::CheckInit(); if (channel < 0 || channel >= kNumDigitalChannels) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for DIO", 0, kNumDigitalChannels, channel); + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } @@ -50,12 +52,13 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input, if (*status != 0) { if (port) { - wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + wpi::hal::SetLastErrorPreviouslyAllocated(*status, "PWM or DIO", channel, port->previousAllocation); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + wpi::hal::SetLastErrorIndexOutOfRange(*status, "Invalid Index for DIO", 0, kNumDigitalChannels, channel); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } @@ -189,8 +192,9 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value, } } if (SimDIOData[port->channel].isInput) { - *status = PARAMETER_OUT_OF_RANGE; - wpi::hal::SetLastError(status, "Cannot set output of an input channel"); + wpi::hal::SetLastError(PARAMETER_OUT_OF_RANGE, + "Cannot set output of an input channel"); + *status = HAL_USE_LAST_ERROR; return; } SimDIOData[port->channel].value = value; diff --git a/hal/src/main/native/sim/DutyCycle.cpp b/hal/src/main/native/sim/DutyCycle.cpp index 5be29264c71..a9c99d395a6 100644 --- a/hal/src/main/native/sim/DutyCycle.cpp +++ b/hal/src/main/native/sim/DutyCycle.cpp @@ -47,12 +47,13 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel, if (*status != 0) { if (dutyCycle) { - wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel, + wpi::hal::SetLastErrorPreviouslyAllocated(*status, "SmartIo", channel, dutyCycle->previousAllocation); } else { wpi::hal::SetLastErrorIndexOutOfRange( - status, "Invalid Index for Duty Cycle", 0, kNumDutyCycles, channel); + *status, "Invalid Index for Duty Cycle", 0, kNumDutyCycles, channel); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/sim/Encoder.cpp b/hal/src/main/native/sim/Encoder.cpp index 4bbc3e05d13..71e89252942 100644 --- a/hal/src/main/native/sim/Encoder.cpp +++ b/hal/src/main/native/sim/Encoder.cpp @@ -271,8 +271,8 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate, } if (minRate == 0.0) { - *status = PARAMETER_OUT_OF_RANGE; - wpi::hal::SetLastError(status, "minRate must not be 0"); + wpi::hal::SetLastError(PARAMETER_OUT_OF_RANGE, "minRate must not be 0"); + *status = HAL_USE_LAST_ERROR; return; } @@ -288,8 +288,8 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle, } if (distancePerPulse == 0.0) { - *status = PARAMETER_OUT_OF_RANGE; - wpi::hal::SetLastError(status, "distancePerPulse must not be 0"); + wpi::hal::SetLastError(PARAMETER_OUT_OF_RANGE, "distancePerPulse must not be 0"); + *status = HAL_USE_LAST_ERROR; return; } encoder->distancePerPulse = distancePerPulse; diff --git a/hal/src/main/native/sim/HALInternal.hpp b/hal/src/main/native/sim/HALInternal.hpp index 0023442999d..b27401bad68 100644 --- a/hal/src/main/native/sim/HALInternal.hpp +++ b/hal/src/main/native/sim/HALInternal.hpp @@ -8,12 +8,14 @@ #include +#include "wpi/hal/Types.h" + namespace wpi::hal { -void SetLastError(int32_t* status, std::string_view value); -void SetLastErrorIndexOutOfRange(int32_t* status, std::string_view message, +void SetLastError(HAL_Status status, std::string_view value); +void SetLastErrorIndexOutOfRange(HAL_Status status, std::string_view message, int32_t minimum, int32_t maximum, int32_t channel); -void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message, - int32_t channel, +void SetLastErrorPreviouslyAllocated(HAL_Status status, + std::string_view message, int32_t channel, std::string_view previousAllocation); } // namespace wpi::hal diff --git a/hal/src/main/native/sim/Notifier.cpp b/hal/src/main/native/sim/Notifier.cpp index e7f7066cc0f..9fa5a11c1d6 100644 --- a/hal/src/main/native/sim/Notifier.cpp +++ b/hal/src/main/native/sim/Notifier.cpp @@ -211,27 +211,27 @@ void wpi::hal::WakeupWaitNotifiers() { extern "C" { -HAL_NotifierHandle HAL_CreateNotifier(int32_t* status) { +HAL_Status HAL_CreateNotifier(HAL_NotifierHandle* notifierHandle) { wpi::hal::init::CheckInit(); std::shared_ptr notifier = std::make_shared(); - HAL_NotifierHandle handle = + *notifierHandle = notifierInstance->owner.GetThread()->m_handles.Allocate(notifier); - if (handle == HAL_INVALID_HANDLE) { - *status = HAL_HANDLE_ERROR; - return HAL_INVALID_HANDLE; + if (*notifierHandle == HAL_INVALID_HANDLE) { + return HAL_HANDLE_ERROR; } - wpi::util::CreateSignalObject(handle); - return handle; + wpi::util::CreateSignalObject(*notifierHandle); + return HAL_SUCCESS; } -void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, - const WPI_String* name, int32_t* status) { +HAL_Status HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, + const WPI_String* name) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } notifier->name = wpi::util::to_string_view(name); + return HAL_SUCCESS; } void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) { @@ -241,13 +241,13 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) { thr->m_alarmQueue.remove({notifierHandle, notifier}); } -void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime, - uint64_t intervalTime, HAL_Bool absolute, - HAL_Bool ack, int32_t* status) { +HAL_Status HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, + uint64_t alarmTime, uint64_t intervalTime, + HAL_Bool absolute, HAL_Bool ack) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } if (ack) { @@ -273,14 +273,15 @@ void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime, if (alarmTime < prevWakeup) { thr->m_cond.notify_all(); } + return HAL_SUCCESS; } -void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, - int32_t* status) { +HAL_Status HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, + HAL_Bool ack) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } if (ack) { @@ -290,27 +291,30 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, thr->m_alarmQueue.remove({notifierHandle, notifier}); notifier->alarmTime = UINT64_MAX; + return HAL_SUCCESS; } -void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle, - int32_t* status) { +HAL_Status HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } notifier->handlerSignaled.clear(); wpi::util::ResetSignalObject(notifierHandle); + return HAL_SUCCESS; } -int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, - int32_t* status) { +HAL_Status HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, + int32_t* count) { auto notifier = notifierInstance->owner.GetThread()->m_handles.Get(notifierHandle); if (!notifier) { - return -1; + *count = 0; + return HAL_HANDLE_ERROR; } - return notifier->userOverrunCount; + *count = notifier->userOverrunCount; + return HAL_SUCCESS; } uint64_t HALSIM_GetNextNotifierTimeout(void) { diff --git a/hal/src/main/native/sim/PWM.cpp b/hal/src/main/native/sim/PWM.cpp index d34a6febf66..c4f8d0a8053 100644 --- a/hal/src/main/native/sim/PWM.cpp +++ b/hal/src/main/native/sim/PWM.cpp @@ -27,9 +27,10 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel, wpi::hal::init::CheckInit(); if (channel < 0 || channel >= kNumPWMChannels) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for PWM", 0, kNumPWMChannels, channel); + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } @@ -48,12 +49,13 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel, if (*status != 0) { if (port) { - wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + wpi::hal::SetLastErrorPreviouslyAllocated(*status, "PWM or DIO", channel, port->previousAllocation); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + wpi::hal::SetLastErrorIndexOutOfRange(*status, "Invalid Index for PWM", 0, kNumPWMChannels, channel); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/sim/PowerDistribution.cpp b/hal/src/main/native/sim/PowerDistribution.cpp index 94f8bb5cbb7..19732351c81 100644 --- a/hal/src/main/native/sim/PowerDistribution.cpp +++ b/hal/src/main/native/sim/PowerDistribution.cpp @@ -32,9 +32,10 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution( const char* allocationLocation, int32_t* status) { if (type == HAL_POWER_DISTRIBUTION_AUTOMATIC) { if (module != HAL_DEFAULT_POWER_DISTRIBUTION_MODULE) { - *status = PARAMETER_OUT_OF_RANGE; wpi::hal::SetLastError( - status, "Automatic PowerDistributionType must have default module"); + PARAMETER_OUT_OF_RANGE, + "Automatic PowerDistributionType must have default module"); + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } @@ -44,15 +45,16 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution( } if (!HAL_CheckPowerDistributionModule(module, type)) { - *status = RESOURCE_OUT_OF_RANGE; if (type == HAL_PowerDistributionType::HAL_POWER_DISTRIBUTION_CTRE) { - wpi::hal::SetLastErrorIndexOutOfRange(status, + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, "Invalid Index for CTRE PDP", 0, kNumCTREPDPModules - 1, module); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH", - 1, kNumREVPDHModules, module); + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for REV PDH", 1, + kNumREVPDHModules, module); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } wpi::hal::init::CheckInit(); diff --git a/hal/src/main/native/sim/REVPH.cpp b/hal/src/main/native/sim/REVPH.cpp index 52eb0f7441c..077fca0139f 100644 --- a/hal/src/main/native/sim/REVPH.cpp +++ b/hal/src/main/native/sim/REVPH.cpp @@ -41,9 +41,10 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module, wpi::hal::init::CheckInit(); if (!HAL_CheckREVPHModuleNumber(module)) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1, + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for REV PH", 1, kNumREVPHModules, module); + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; } @@ -53,12 +54,13 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module, if (*status != 0) { if (pcm) { - wpi::hal::SetLastErrorPreviouslyAllocated(status, "REV PH", module, + wpi::hal::SetLastErrorPreviouslyAllocated(*status, "REV PH", module, pcm->previousAllocation); } else { - wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", + wpi::hal::SetLastErrorIndexOutOfRange(*status, "Invalid Index for REV PH", 1, kNumREVPHModules, module); } + *status = HAL_USE_LAST_ERROR; return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/systemcore/AddressableLED.cpp b/hal/src/main/native/systemcore/AddressableLED.cpp index fb687c23318..707cdd33e2f 100644 --- a/hal/src/main/native/systemcore/AddressableLED.cpp +++ b/hal/src/main/native/systemcore/AddressableLED.cpp @@ -84,23 +84,24 @@ void InitializeAddressableLED() { extern "C" { -HAL_AddressableLEDHandle HAL_InitializeAddressableLED( - int32_t channel, const char* allocationLocation, int32_t* status) { +HAL_Status HAL_InitializeAddressableLED(int32_t channel, + const char* allocationLocation, + HAL_AddressableLEDHandle* handle) { wpi::hal::init::CheckInit(); if (channel < 0 || channel >= kNumSmartIo) { - *status = RESOURCE_OUT_OF_RANGE; - wpi::hal::SetLastErrorIndexOutOfRange( - status, "Invalid Index for AddressableLED", 0, kNumSmartIo, channel); - return HAL_INVALID_HANDLE; + wpi::hal::SetLastErrorIndexOutOfRange(RESOURCE_OUT_OF_RANGE, + "Invalid Index for AddressableLED", 0, + kNumSmartIo, channel); + *handle = HAL_INVALID_HANDLE; + return HAL_USE_LAST_ERROR; } - HAL_DigitalHandle handle; - + HAL_Status status = 0; auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::ADDRESSABLE_LED, - &handle, status); + handle, &status); - if (*status != 0) { + if (status != 0) { if (port) { wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel, port->previousAllocation); @@ -108,7 +109,8 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED( wpi::hal::SetLastErrorIndexOutOfRange( status, "Invalid Index for AddressableLED", 0, kNumSmartIo, channel); } - return HAL_INVALID_HANDLE; // failed to allocate. Pass error back. + *handle = HAL_INVALID_HANDLE; + return HAL_USE_LAST_ERROR; } port->channel = channel; diff --git a/hal/src/main/native/systemcore/Alert.cpp b/hal/src/main/native/systemcore/Alert.cpp index 03c8fc6b9de..b32dce8fdd5 100644 --- a/hal/src/main/native/systemcore/Alert.cpp +++ b/hal/src/main/native/systemcore/Alert.cpp @@ -46,34 +46,31 @@ void InitializeAlert() { extern "C" { -HAL_AlertHandle HAL_CreateAlert(const WPI_String* group, const WPI_String* text, - int32_t level, int32_t* status) { +HAL_Status HAL_CreateAlert(const WPI_String* group, const WPI_String* text, + int32_t level, HAL_AlertHandle* alertHandle) { wpi::hal::init::CheckInit(); std::shared_ptr alert = std::make_shared( wpi::util::to_string_view(group), wpi::util::to_string_view(text), level); - HAL_AlertHandle handle = alertHandles->Allocate(alert); - if (handle == HAL_INVALID_HANDLE) { - *status = HAL_HANDLE_ERROR; - return HAL_INVALID_HANDLE; + *alertHandle = alertHandles->Allocate(alert); + if (*alertHandle == HAL_INVALID_HANDLE) { + return HAL_HANDLE_ERROR; } - return handle; + return HAL_OK; } void HAL_DestroyAlert(HAL_AlertHandle alertHandle) { alertHandles->Free(alertHandle); } -void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active, - int32_t* status) { +HAL_Status HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } if (active) { if (alert->activeStartTime.load(std::memory_order_relaxed) != 0) { // Already active, do nothing (avoids cost of getting time) - return; + return HAL_OK; } int64_t now = HAL_GetMonotonicTime(); int64_t expected = 0; @@ -82,37 +79,39 @@ void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active, } else { alert->activeStartTime = 0; } + return HAL_OK; } -HAL_Bool HAL_IsAlertActive(HAL_AlertHandle alertHandle, int32_t* status) { +HAL_Status HAL_IsAlertActive(HAL_AlertHandle alertHandle, HAL_Bool* active) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return false; + return HAL_HANDLE_ERROR; } - return alert->activeStartTime != 0; + *active = alert->activeStartTime != 0; + return HAL_OK; } -void HAL_SetAlertText(HAL_AlertHandle alertHandle, const WPI_String* text, - int32_t* status) { +HAL_Status HAL_SetAlertText(HAL_AlertHandle alertHandle, + const WPI_String* text) { auto alert = alertHandles->Get(alertHandle); if (!alert) { - *status = HAL_HANDLE_ERROR; - return; + return HAL_HANDLE_ERROR; } std::scoped_lock lock(alert->textMutex); alert->text = wpi::util::to_string_view(text); + return HAL_OK; } -void HAL_GetAlertText(HAL_AlertHandle alertHandle, struct WPI_String* text, - int32_t* status) { +HAL_Status HAL_GetAlertText(HAL_AlertHandle alertHandle, + struct WPI_String* text) { auto alert = alertHandles->Get(alertHandle); if (alert) { std::scoped_lock lock(alert->textMutex); *text = wpi::util::alloc_wpi_string(alert->text); + return HAL_OK; } else { - *status = HAL_HANDLE_ERROR; *text = WPI_String{}; + return HAL_HANDLE_ERROR; } } diff --git a/hal/src/main/native/systemcore/HALInternal.hpp b/hal/src/main/native/systemcore/HALInternal.hpp index 628763c9eda..b9b28199af6 100644 --- a/hal/src/main/native/systemcore/HALInternal.hpp +++ b/hal/src/main/native/systemcore/HALInternal.hpp @@ -9,12 +9,12 @@ #include namespace wpi::hal { -void SetLastError(int32_t* status, std::string_view value); -void SetLastErrorIndexOutOfRange(int32_t* status, std::string_view message, +void SetLastError(HAL_Status status, std::string_view value); +void SetLastErrorIndexOutOfRange(HAL_Status status, std::string_view message, int32_t minimum, int32_t maximum, int32_t channel); -void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message, - int32_t channel, +void SetLastErrorPreviouslyAllocated(HAL_Status status, + std::string_view message, int32_t channel, std::string_view previousAllocation); uint64_t GetDSInitializeTime(); } // namespace wpi::hal diff --git a/hal/src/main/native/systemcore/Notifier.cpp b/hal/src/main/native/systemcore/Notifier.cpp index f80e220004c..5532a28af4c 100644 --- a/hal/src/main/native/systemcore/Notifier.cpp +++ b/hal/src/main/native/systemcore/Notifier.cpp @@ -142,27 +142,27 @@ void NotifierThread::ProcessAlarms() { extern "C" { -HAL_NotifierHandle HAL_CreateNotifier(int32_t* status) { +HAL_Status HAL_CreateNotifier(HAL_NotifierHandle* notifierHandle) { wpi::hal::init::CheckInit(); std::shared_ptr notifier = std::make_shared(); - HAL_NotifierHandle handle = + *notifierHandle = notifierInstance->owner.GetThread()->m_handles.Allocate(notifier); - if (handle == HAL_INVALID_HANDLE) { - *status = HAL_HANDLE_ERROR; - return HAL_INVALID_HANDLE; + if (*notifierHandle == HAL_INVALID_HANDLE) { + return HAL_HANDLE_ERROR; } - wpi::util::CreateSignalObject(handle); - return handle; + wpi::util::CreateSignalObject(*notifierHandle); + return HAL_OK; } -void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, - const WPI_String* name, int32_t* status) { +HAL_Status HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, + const WPI_String* name) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } notifier->name = wpi::util::to_string_view(name); + return HAL_OK; } void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) { @@ -172,13 +172,13 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) { thr->m_alarmQueue.remove({notifierHandle, notifier}); } -void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime, - uint64_t intervalTime, HAL_Bool absolute, - HAL_Bool ack, int32_t* status) { +HAL_Status HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, + uint64_t alarmTime, uint64_t intervalTime, + HAL_Bool absolute, HAL_Bool ack) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } if (ack) { @@ -204,14 +204,15 @@ void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime, if (alarmTime < prevWakeup) { thr->m_cond.notify_all(); } + return HAL_OK; } -void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, - int32_t* status) { +HAL_Status HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, + HAL_Bool ack) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } if (ack) { @@ -221,27 +222,30 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack, thr->m_alarmQueue.remove({notifierHandle, notifier}); notifier->alarmTime = UINT64_MAX; + return HAL_OK; } -void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle, - int32_t* status) { +HAL_Status HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle) { auto thr = notifierInstance->owner.GetThread(); auto notifier = thr->m_handles.Get(notifierHandle); if (!notifier) { - return; + return HAL_HANDLE_ERROR; } notifier->handlerSignaled.clear(); wpi::util::ResetSignalObject(notifierHandle); + return HAL_OK; } -int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, - int32_t* status) { +HAL_Status HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle, + int32_t* count) { auto notifier = notifierInstance->owner.GetThread()->m_handles.Get(notifierHandle); if (!notifier) { - return -1; + *count = 0; + return HAL_HANDLE_ERROR; } - return notifier->userOverrunCount; + *count = notifier->userOverrunCount; + return HAL_OK; } } // extern "C" diff --git a/wpilibc/src/main/native/cpp/driverstation/Alert.cpp b/wpilibc/src/main/native/cpp/driverstation/Alert.cpp index b8b140bee91..4e50079d5e0 100644 --- a/wpilibc/src/main/native/cpp/driverstation/Alert.cpp +++ b/wpilibc/src/main/native/cpp/driverstation/Alert.cpp @@ -8,6 +8,7 @@ #include +#include "wpi/hal/Types.h" #include "wpi/util/string.hpp" using namespace wpi; @@ -16,9 +17,10 @@ static HAL_AlertHandle CreateAlert(std::string_view group, std::string_view text, Alert::Level level) { WPI_String wpiGroup = wpi::util::make_string(group); WPI_String wpiText = wpi::util::make_string(text); - int32_t status = 0; - return HAL_CreateAlert(&wpiGroup, &wpiText, static_cast(level), - &status); + HAL_AlertHandle alertHandle; + HAL_CreateAlert(&wpiGroup, &wpiText, static_cast(level), + &alertHandle); + return alertHandle; } Alert::Alert(std::string_view text, Level type) : Alert("Alerts", text, type) {} @@ -27,25 +29,23 @@ Alert::Alert(std::string_view group, std::string_view text, Level type) : m_handle{CreateAlert(group, text, type)} {} void Alert::Set(bool active) { - int32_t status = 0; - HAL_SetAlertActive(m_handle, active, &status); + HAL_SetAlertActive(m_handle, active); } bool Alert::Get() const { - int32_t status = 0; - return HAL_IsAlertActive(m_handle, &status); + HAL_Bool active; + HAL_IsAlertActive(m_handle, &active); + return active; } void Alert::SetText(std::string_view text) { WPI_String wpiText = wpi::util::make_string(text); - int32_t status = 0; - HAL_SetAlertText(m_handle, &wpiText, &status); + HAL_SetAlertText(m_handle, &wpiText); } std::string Alert::GetText() const { WPI_String wpiText; - int32_t status = 0; - HAL_GetAlertText(m_handle, &wpiText, &status); + HAL_GetAlertText(m_handle, &wpiText); std::string rv{wpiText.str, wpiText.len}; WPI_FreeString(&wpiText); return rv; diff --git a/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp b/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp index 05680fee47c..eabc3847b1e 100644 --- a/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp +++ b/wpilibc/src/main/native/cpp/framework/OpModeRobot.cpp @@ -34,9 +34,9 @@ OpModeRobotBase::OpModeRobotBase(wpi::units::second_t period) Alert::Level::MEDIUM}, m_watchdog{period, [this] { m_loopOverrunAlert.Set(true); }} { // Create our own notifier and callback queue - int32_t status = 0; - m_notifier = HAL_CreateNotifier(&status); - HAL_SetNotifierName(m_notifier, "OpModeRobot", &status); + HAL_Status status = HAL_CreateNotifier(&m_notifier); + WPILIB_CheckErrorStatus(status, "CreateNotifier"); + HAL_SetNotifierName(m_notifier, "OpModeRobot"); m_startTime = std::chrono::microseconds{RobotController::GetMonotonicTime()}; diff --git a/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp b/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp index 14307f41369..c36990d4ff7 100644 --- a/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp +++ b/wpilibc/src/main/native/cpp/framework/TimedRobot.cpp @@ -44,10 +44,11 @@ TimedRobot::TimedRobot(wpi::units::second_t period) m_startTime = std::chrono::microseconds{RobotController::GetMonotonicTime()}; AddPeriodic([=, this] { LoopFunc(); }, period); - int32_t status = 0; - m_notifier = HAL_CreateNotifier(&status); + HAL_NotifierHandle notifier = 0; + HAL_Status status = HAL_CreateNotifier(¬ifier); WPILIB_CheckErrorStatus(status, "InitializeNotifier"); - HAL_SetNotifierName(m_notifier, "TimedRobot", &status); + m_notifier = notifier; + HAL_SetNotifierName(m_notifier, "TimedRobot"); HAL_ReportUsage("Framework", "TimedRobot"); } diff --git a/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp b/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp index 278a55e48fa..8b37cdd6c1d 100644 --- a/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp +++ b/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp @@ -7,6 +7,7 @@ #include #include "wpi/hal/AddressableLED.h" +#include "wpi/hal/Types.h" #include "wpi/hal/UsageReporting.hpp" #include "wpi/system/Errors.hpp" #include "wpi/util/SensorUtil.hpp" @@ -19,9 +20,11 @@ AddressableLED::AddressableLED(int channel) : m_channel{channel} { throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); } - int32_t status = 0; auto stack = wpi::util::GetStackTrace(1); - m_handle = HAL_InitializeAddressableLED(channel, stack.c_str(), &status); + HAL_AddressableLEDHandle handle; + HAL_Status status = + HAL_InitializeAddressableLED(channel, stack.c_str(), &handle); + m_handle = handle; WPILIB_CheckErrorStatus(status, "Channel {}", channel); HAL_ReportUsage("IO", channel, "AddressableLED"); @@ -33,15 +36,13 @@ void AddressableLED::SetColorOrder(AddressableLED::ColorOrder order) { void AddressableLED::SetStart(int start) { m_start = start; - int32_t status = 0; - HAL_SetAddressableLEDStart(m_handle, start, &status); + HAL_Status status = HAL_SetAddressableLEDStart(m_handle, start); WPILIB_CheckErrorStatus(status, "Channel {} start {}", m_channel, start); } void AddressableLED::SetLength(int length) { m_length = length; - int32_t status = 0; - HAL_SetAddressableLEDLength(m_handle, length, &status); + HAL_Status status = HAL_SetAddressableLEDLength(m_handle, length); WPILIB_CheckErrorStatus(status, "Channel {} length {}", m_channel, length); } @@ -49,11 +50,9 @@ static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData), "LED Structs MUST be the same size"); void AddressableLED::SetData(std::span ledData) { - int32_t status = 0; - HAL_SetAddressableLEDData( + HAL_Status status = HAL_SetAddressableLEDData( m_start, std::min(static_cast(m_length), ledData.size()), - static_cast(m_colorOrder), ledData.data(), - &status); + static_cast(m_colorOrder), ledData.data()); WPILIB_CheckErrorStatus(status, "Port {}", m_channel); } @@ -63,11 +62,9 @@ void AddressableLED::SetData(std::initializer_list ledData) { void AddressableLED::SetGlobalData(int start, ColorOrder colorOrder, std::span ledData) { - int32_t status = 0; - HAL_SetAddressableLEDData( + HAL_Status status = HAL_SetAddressableLEDData( start, ledData.size(), - static_cast(colorOrder), ledData.data(), - &status); + static_cast(colorOrder), ledData.data()); WPILIB_CheckErrorStatus(status, ""); } diff --git a/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp b/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp index 55900668cff..d701d100887 100644 --- a/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp +++ b/wpilibc/src/main/native/cpp/internal/PeriodicPriorityQueue.cpp @@ -87,9 +87,8 @@ bool PeriodicPriorityQueue::RunCallbacks(HAL_NotifierHandle notifier) { // at the end of the loop. auto callback = m_queue.pop(); - int32_t status = 0; - HAL_SetNotifierAlarm(notifier, callback.expirationTime.count(), 0, true, true, - &status); + HAL_Status status = HAL_SetNotifierAlarm( + notifier, callback.expirationTime.count(), 0, true, true); WPILIB_CheckErrorStatus(status, "SetNotifierAlarm"); if (WPI_WaitForObject(notifier) == 0) { diff --git a/wpilibc/src/main/native/cpp/system/Notifier.cpp b/wpilibc/src/main/native/cpp/system/Notifier.cpp index 5a7fa4f01ca..6882aa9e0e1 100644 --- a/wpilibc/src/main/native/cpp/system/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/system/Notifier.cpp @@ -7,6 +7,7 @@ #include #include "wpi/hal/DriverStation.h" +#include "wpi/hal/Errors.h" #include "wpi/hal/Notifier.hpp" #include "wpi/hal/Threads.h" #include "wpi/system/Errors.hpp" @@ -19,9 +20,10 @@ Notifier::Notifier(int priority, std::function callback) { throw WPILIB_MakeError(err::NullParameter, "callback"); } m_callback = callback; - HAL_Status status = 0; - m_notifier = HAL_CreateNotifier(&status); - WPILIB_CheckErrorStatus(status, "InitializeNotifier"); + HAL_NotifierHandle handle; + HAL_Status status = HAL_CreateNotifier(&handle); + m_notifier = handle; + WPILIB_CheckErrorStatus(status, "CreateNotifier"); m_thread = std::thread([=, this] { if (priority > 0 && HAL_SetCurrentThreadPriority(priority) != 0) { @@ -63,8 +65,7 @@ Notifier::Notifier(int priority, std::function callback) { } // Ack notifier - HAL_Status status = 0; - HAL_AcknowledgeNotifierAlarm(notifier, &status); + HAL_Status status = HAL_AcknowledgeNotifierAlarm(notifier); WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier"); } }); @@ -94,8 +95,7 @@ Notifier& Notifier::operator=(Notifier&& rhs) { } void Notifier::SetName(std::string_view name) { - int32_t status = 0; - HAL_SetNotifierName(m_notifier, name, &status); + HAL_SetNotifierName(m_notifier, name); } void Notifier::SetCallback(std::function callback) { @@ -104,16 +104,16 @@ void Notifier::SetCallback(std::function callback) { } void Notifier::StartSingle(wpi::units::second_t delay) { - int32_t status = 0; - HAL_SetNotifierAlarm(m_notifier, static_cast(delay * 1e6), 0, false, - false, &status); + HAL_Status status = HAL_SetNotifierAlarm( + m_notifier, static_cast(delay * 1e6), 0, false, false); + WPILIB_CheckErrorStatus(status, "SetNotifierAlarm"); } void Notifier::StartPeriodic(wpi::units::second_t period) { - int32_t status = 0; - HAL_SetNotifierAlarm(m_notifier, static_cast(period * 1e6), - static_cast(period * 1e6), false, false, - &status); + HAL_Status status = + HAL_SetNotifierAlarm(m_notifier, static_cast(period * 1e6), + static_cast(period * 1e6), false, false); + WPILIB_CheckErrorStatus(status, "SetNotifierAlarm"); } void Notifier::StartPeriodic(wpi::units::hertz_t frequency) { @@ -121,14 +121,13 @@ void Notifier::StartPeriodic(wpi::units::hertz_t frequency) { } void Notifier::Stop() { - int32_t status = 0; - HAL_CancelNotifierAlarm(m_notifier, false, &status); + HAL_Status status = HAL_CancelNotifierAlarm(m_notifier, false); WPILIB_CheckErrorStatus(status, "CancelNotifierAlarm"); } int32_t Notifier::GetOverrun() const { - int32_t status = 0; - int32_t overrun = HAL_GetNotifierOverrun(m_notifier, &status); + int32_t overrun = 0; + HAL_Status status = HAL_GetNotifierOverrun(m_notifier, &overrun); WPILIB_CheckErrorStatus(status, "GetNotifierOverrun"); return overrun; } diff --git a/wpilibc/src/main/native/cpp/system/Watchdog.cpp b/wpilibc/src/main/native/cpp/system/Watchdog.cpp index c2a444e4390..80f220d0361 100644 --- a/wpilibc/src/main/native/cpp/system/Watchdog.cpp +++ b/wpilibc/src/main/native/cpp/system/Watchdog.cpp @@ -48,10 +48,11 @@ class Watchdog::Impl { }; Watchdog::Impl::Impl() { - int32_t status = 0; - m_notifier = HAL_CreateNotifier(&status); + HAL_NotifierHandle notifier = 0; + HAL_Status status = HAL_CreateNotifier(¬ifier); WPILIB_CheckErrorStatus(status, "starting watchdog notifier"); - HAL_SetNotifierName(m_notifier, "Watchdog", &status); + m_notifier = notifier; + HAL_SetNotifierName(m_notifier, "Watchdog"); m_thread = std::thread([=, this] { Main(); }); } @@ -68,19 +69,20 @@ Watchdog::Impl::~Impl() { } void Watchdog::Impl::UpdateAlarm() { - int32_t status = 0; // Return if we are being destructed, or were not created successfully auto notifier = m_notifier.load(); if (notifier == 0) { return; } + HAL_Status status; if (m_watchdogs.empty()) { - HAL_CancelNotifierAlarm(notifier, true, &status); + status = HAL_CancelNotifierAlarm(notifier, true); } else { - HAL_SetNotifierAlarm(notifier, - static_cast( - m_watchdogs.top()->m_expirationTime.value() * 1e6), - 0, true, true, &status); + status = HAL_SetNotifierAlarm( + notifier, + static_cast(m_watchdogs.top()->m_expirationTime.value() * + 1e6), + 0, true, true); } WPILIB_CheckErrorStatus(status, "updating watchdog notifier alarm"); }