mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Adds function to HAL to free malloc'd joystick name (#543)
No safe way to do this with interop, so a function is needed.
This commit is contained in:
committed by
Peter Johnson
parent
e4a918850f
commit
462b231dac
@@ -99,6 +99,7 @@ int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum);
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum);
|
||||
char* HAL_GetJoystickName(int32_t joystickNum);
|
||||
void HAL_FreeJoystickName(char* name);
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis);
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
|
||||
@@ -205,6 +205,8 @@ char* HAL_GetJoystickName(int32_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_FreeJoystickName(char* name) { std::free(name); }
|
||||
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
|
||||
@@ -259,7 +259,7 @@ Java_edu_wpi_first_wpilibj_hal_HAL_getJoystickName(JNIEnv* env, jclass,
|
||||
NETCOMM_LOG(logDEBUG) << "Calling HAL_GetJoystickName";
|
||||
char *joystickName = HAL_GetJoystickName(port);
|
||||
jstring str = MakeJString(env, joystickName);
|
||||
std::free(joystickName);
|
||||
HAL_FreeJoystickName(joystickName);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user