Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions hal/src/main/native/cpp/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
29 changes: 14 additions & 15 deletions hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<jint>(handle);
}

/*
Expand All @@ -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<HAL_AddressableLEDHandle>(handle),
start, &status);
HAL_Status status = HAL_SetAddressableLEDStart(static_cast<HAL_AddressableLEDHandle>(handle),
start);
CheckStatus(env, status);
}

Expand All @@ -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<HAL_AddressableLEDHandle>(handle),
length, &status);
HAL_Status status = HAL_SetAddressableLEDLength(static_cast<HAL_AddressableLEDHandle>(handle),
length);
CheckStatus(env, status);
}

Expand Down Expand Up @@ -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<HAL_AddressableLEDColorOrder>(colorOrder),
reinterpret_cast<const HAL_AddressableLEDData*>(rawdata.data()), &status);
reinterpret_cast<const HAL_AddressableLEDData*>(rawdata.data()));
CheckStatus(env, status);
}

/*
Expand Down Expand Up @@ -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<HAL_AddressableLEDColorOrder>(colorOrder),
reinterpret_cast<const HAL_AddressableLEDData*>(rawdata.data()), &status);
reinterpret_cast<const HAL_AddressableLEDData*>(rawdata.data()));
CheckStatus(env, status);
}
} // extern "C"
18 changes: 7 additions & 11 deletions hal/src/main/native/cpp/jni/AlertJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand Down
21 changes: 7 additions & 14 deletions hal/src/main/native/cpp/jni/NotifierJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<uint64_t>(alarmTime),
static_cast<uint64_t>(intervalTime), absolute, ack, &status);
static_cast<uint64_t>(intervalTime), absolute, ack);
CheckStatus(env, status);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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<jint>(count);
Expand Down
30 changes: 15 additions & 15 deletions hal/src/main/native/include/wpi/hal/AddressableLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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"
Expand Down
33 changes: 16 additions & 17 deletions hal/src/main/native/include/wpi/hal/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
PeterJohnson marked this conversation as resolved.

/**
* Destroys an alert.
Expand All @@ -69,40 +69,39 @@ 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
* displayed alert, such as including more details about the detected problem.
*
* @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"
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/include/wpi/hal/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading
Loading