mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[hal,wpilib] Use new DS available API from mrccomm (#8302)
Instead of just having a max count for joystick values, there's an available mask of values. This is because in the future we're expecting there to be holes in the list of available buttons and axes. This updates everything to support that scenario. Also, Joystick buttons, axes, and POVs all now start at 0 instead of 1.
This commit is contained in:
@@ -133,142 +133,39 @@ Java_edu_wpi_first_hal_DriverStationJNI_nativeGetAllianceStation
|
||||
return static_cast<jint>(allianceStation);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickAxesRaw
|
||||
* Signature: (B[S)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxesRaw
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jshortArray axesRawArray)
|
||||
{
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(joystickNum, &axes);
|
||||
|
||||
jsize javaSize = env->GetArrayLength(axesRawArray);
|
||||
if (axes.count > javaSize) {
|
||||
ThrowIllegalArgumentException(
|
||||
env,
|
||||
fmt::format("Native array size larger then passed in java array "
|
||||
"size\nNative Size: {} Java Size: {}",
|
||||
static_cast<int>(axes.count), static_cast<int>(javaSize)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
env->SetShortArrayRegion(axesRawArray, 0, axes.count, axes.raw);
|
||||
|
||||
return axes.count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickAxes
|
||||
* Signature: (B[F)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxes
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jfloatArray axesArray)
|
||||
{
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(joystickNum, &axes);
|
||||
|
||||
jsize javaSize = env->GetArrayLength(axesArray);
|
||||
if (axes.count > javaSize) {
|
||||
ThrowIllegalArgumentException(
|
||||
env,
|
||||
fmt::format("Native array size larger then passed in java array "
|
||||
"size\nNative Size: {} Java Size: {}",
|
||||
static_cast<int>(axes.count), static_cast<int>(javaSize)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
env->SetFloatArrayRegion(axesArray, 0, axes.count, axes.axes);
|
||||
|
||||
return axes.count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickPOVs
|
||||
* Signature: (B[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickPOVs
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray)
|
||||
{
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_GetJoystickPOVs(joystickNum, &povs);
|
||||
|
||||
jsize javaSize = env->GetArrayLength(povsArray);
|
||||
if (povs.count > javaSize) {
|
||||
ThrowIllegalArgumentException(
|
||||
env,
|
||||
fmt::format("Native array size larger then passed in java array "
|
||||
"size\nNative Size: {} Java Size: {}",
|
||||
static_cast<int>(povs.count), static_cast<int>(javaSize)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
env->SetByteArrayRegion(povsArray, 0, povs.count,
|
||||
reinterpret_cast<const jbyte*>(povs.povs));
|
||||
|
||||
return povs.count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getAllJoystickData
|
||||
* Signature: ([F[S[B[J)V
|
||||
* Signature: (I[F[S[B[J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getAllJoystickData
|
||||
(JNIEnv* env, jclass cls, jfloatArray axesArray, jshortArray rawAxesArray,
|
||||
jbyteArray povsArray, jlongArray buttonsAndMetadataArray)
|
||||
(JNIEnv* env, jclass cls, jint stick, jfloatArray axesArray,
|
||||
jshortArray rawAxesArray, jbyteArray povsArray,
|
||||
jlongArray buttonsAndMetadataArray)
|
||||
{
|
||||
HAL_JoystickAxes axes[HAL_kMaxJoysticks];
|
||||
HAL_JoystickPOVs povs[HAL_kMaxJoysticks];
|
||||
HAL_JoystickButtons buttons[HAL_kMaxJoysticks];
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_JoystickButtons buttons;
|
||||
|
||||
HAL_GetAllJoystickData(axes, povs, buttons);
|
||||
HAL_GetAllJoystickData(stick, &axes, &povs, &buttons);
|
||||
|
||||
CriticalJSpan<jfloat> jAxes(env, axesArray);
|
||||
CriticalJSpan<jshort> jRawAxes(env, rawAxesArray);
|
||||
CriticalJSpan<jbyte> jPovs(env, povsArray);
|
||||
CriticalJSpan<jlong> jButtons(env, buttonsAndMetadataArray);
|
||||
|
||||
static_assert(sizeof(jAxes[0]) == sizeof(axes[0].axes[0]));
|
||||
static_assert(sizeof(jRawAxes[0]) == sizeof(axes[0].raw[0]));
|
||||
static_assert(sizeof(jPovs[0]) == sizeof(povs[0].povs[0]));
|
||||
static_assert(sizeof(jAxes[0]) == sizeof(axes.axes[0]));
|
||||
static_assert(sizeof(jRawAxes[0]) == sizeof(axes.raw[0]));
|
||||
static_assert(sizeof(jPovs[0]) == sizeof(povs.povs[0]));
|
||||
|
||||
for (size_t i = 0; i < HAL_kMaxJoysticks; i++) {
|
||||
std::memcpy(&jAxes[i * HAL_kMaxJoystickAxes], axes[i].axes,
|
||||
sizeof(axes[i].axes));
|
||||
std::memcpy(&jRawAxes[i * HAL_kMaxJoystickAxes], axes[i].raw,
|
||||
sizeof(axes[i].raw));
|
||||
std::memcpy(&jPovs[i * HAL_kMaxJoystickPOVs], povs[i].povs,
|
||||
sizeof(povs[i].povs));
|
||||
jButtons[i * 4] = axes[i].count;
|
||||
jButtons[(i * 4) + 1] = povs[i].count;
|
||||
jButtons[(i * 4) + 2] = buttons[i].count;
|
||||
jButtons[(i * 4) + 3] = buttons[i].buttons;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickButtons
|
||||
* Signature: (BLjava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickButtons
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jobject count)
|
||||
{
|
||||
HAL_JoystickButtons joystickButtons;
|
||||
HAL_GetJoystickButtons(joystickNum, &joystickButtons);
|
||||
jbyte* countPtr =
|
||||
reinterpret_cast<jbyte*>(env->GetDirectBufferAddress(count));
|
||||
*countPtr = joystickButtons.count;
|
||||
return joystickButtons.buttons;
|
||||
std::memcpy(&jAxes[0], axes.axes, sizeof(axes.axes));
|
||||
std::memcpy(&jRawAxes[0], axes.raw, sizeof(axes.raw));
|
||||
std::memcpy(&jPovs[0], povs.povs, sizeof(povs.povs));
|
||||
jButtons[0] = axes.available;
|
||||
jButtons[1] = povs.available;
|
||||
jButtons[2] = buttons.available;
|
||||
jButtons[3] = buttons.buttons;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -323,18 +220,6 @@ Java_edu_wpi_first_hal_DriverStationJNI_getJoystickName
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickAxisType
|
||||
* Signature: (BB)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxisType
|
||||
(JNIEnv*, jclass, jbyte joystickNum, jbyte axis)
|
||||
{
|
||||
return HAL_GetJoystickAxisType(joystickNum, axis);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getMatchTime
|
||||
|
||||
@@ -427,11 +427,12 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchTime
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickAxes
|
||||
* Signature: (B[F)V
|
||||
* Signature: (B[FS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxes
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jfloatArray axesArray)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jfloatArray axesArray,
|
||||
jshort availableAxes)
|
||||
{
|
||||
HAL_JoystickAxes axes;
|
||||
{
|
||||
@@ -440,7 +441,7 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxes
|
||||
auto arraySize = arrayRef.size();
|
||||
int maxCount =
|
||||
arraySize < HAL_kMaxJoystickAxes ? arraySize : HAL_kMaxJoystickAxes;
|
||||
axes.count = maxCount;
|
||||
axes.available = availableAxes;
|
||||
for (int i = 0; i < maxCount; i++) {
|
||||
axes.axes[i] = arrayRef[i];
|
||||
}
|
||||
@@ -452,11 +453,12 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxes
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickPOVs
|
||||
* Signature: (B[B)V
|
||||
* Signature: (B[BS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVs
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray,
|
||||
jshort availablePovs)
|
||||
{
|
||||
HAL_JoystickPOVs povs;
|
||||
{
|
||||
@@ -465,7 +467,7 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVs
|
||||
auto arraySize = arrayRef.size();
|
||||
int maxCount =
|
||||
arraySize < HAL_kMaxJoystickPOVs ? arraySize : HAL_kMaxJoystickPOVs;
|
||||
povs.count = maxCount;
|
||||
povs.available = availablePovs;
|
||||
for (int i = 0; i < maxCount; i++) {
|
||||
povs.povs[i] = static_cast<HAL_JoystickPOV>(arrayRef[i]);
|
||||
}
|
||||
@@ -477,17 +479,15 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVs
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickButtons
|
||||
* Signature: (BII)V
|
||||
* Signature: (BJJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtons
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jint buttons, jint count)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jlong buttons,
|
||||
jlong availableButtons)
|
||||
{
|
||||
if (count > 32) {
|
||||
count = 32;
|
||||
}
|
||||
HAL_JoystickButtons joystickButtons;
|
||||
joystickButtons.count = count;
|
||||
joystickButtons.available = availableButtons;
|
||||
joystickButtons.buttons = buttons;
|
||||
HALSIM_SetJoystickButtons(joystickNum, &joystickButtons);
|
||||
}
|
||||
@@ -654,49 +654,49 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOV
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickButtonsValue
|
||||
* Signature: (II)V
|
||||
* Signature: (IJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonsValue
|
||||
(JNIEnv*, jclass, jint stick, jint buttons)
|
||||
(JNIEnv*, jclass, jint stick, jlong buttons)
|
||||
{
|
||||
HALSIM_SetJoystickButtonsValue(stick, buttons);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickAxisCount
|
||||
* Method: setJoystickAxesAvailable
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxisCount
|
||||
(JNIEnv*, jclass, jint stick, jint count)
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxesAvailable
|
||||
(JNIEnv*, jclass, jint stick, jint available)
|
||||
{
|
||||
HALSIM_SetJoystickAxisCount(stick, count);
|
||||
HALSIM_SetJoystickAxesAvailable(stick, available);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickPOVCount
|
||||
* Method: setJoystickPOVsAvailable
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVCount
|
||||
(JNIEnv*, jclass, jint stick, jint count)
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVsAvailable
|
||||
(JNIEnv*, jclass, jint stick, jint available)
|
||||
{
|
||||
HALSIM_SetJoystickPOVCount(stick, count);
|
||||
HALSIM_SetJoystickPOVsAvailable(stick, available);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickButtonCount
|
||||
* Signature: (II)V
|
||||
* Method: setJoystickButtonsAvailable
|
||||
* Signature: (IJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonCount
|
||||
(JNIEnv*, jclass, jint stick, jint count)
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonsAvailable
|
||||
(JNIEnv*, jclass, jint stick, jlong available)
|
||||
{
|
||||
HALSIM_SetJoystickButtonCount(stick, count);
|
||||
HALSIM_SetJoystickButtonsAvailable(stick, available);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -737,18 +737,6 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickName
|
||||
HALSIM_SetJoystickName(stick, &str);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickAxisType
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxisType
|
||||
(JNIEnv*, jclass, jint stick, jint axis, jint type)
|
||||
{
|
||||
HALSIM_SetJoystickAxisType(stick, axis, type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setGameSpecificMessage
|
||||
|
||||
@@ -102,7 +102,8 @@ int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
|
||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons);
|
||||
|
||||
void HAL_GetAllJoystickData(HAL_JoystickAxes* axes, HAL_JoystickPOVs* povs,
|
||||
void HAL_GetAllJoystickData(int32_t joystickNum, HAL_JoystickAxes* axes,
|
||||
HAL_JoystickPOVs* povs,
|
||||
HAL_JoystickButtons* buttons);
|
||||
|
||||
/**
|
||||
@@ -150,18 +151,6 @@ int32_t HAL_GetJoystickType(int32_t joystickNum);
|
||||
*/
|
||||
void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum);
|
||||
|
||||
/**
|
||||
* Gets the type of a specific joystick axis.
|
||||
*
|
||||
* This is device specific, and different depending on what system input type
|
||||
* the joystick uses.
|
||||
*
|
||||
* @param joystickNum the joystick number
|
||||
* @param axis the axis number
|
||||
* @return the enumerated axis type
|
||||
*/
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis);
|
||||
|
||||
/**
|
||||
* Set joystick outputs.
|
||||
*
|
||||
|
||||
@@ -21,7 +21,8 @@ struct HAL_ControlWord {
|
||||
uint32_t eStop : 1;
|
||||
uint32_t fmsAttached : 1;
|
||||
uint32_t dsAttached : 1;
|
||||
uint32_t control_reserved : 26;
|
||||
uint32_t watchdogEnabled : 1;
|
||||
uint32_t control_reserved : 25;
|
||||
};
|
||||
typedef struct HAL_ControlWord HAL_ControlWord;
|
||||
|
||||
@@ -67,7 +68,7 @@ HAL_ENUM(HAL_MatchType) {
|
||||
#define HAL_kMaxJoysticks 6
|
||||
|
||||
struct HAL_JoystickAxes {
|
||||
int16_t count;
|
||||
uint16_t available;
|
||||
float axes[HAL_kMaxJoystickAxes];
|
||||
int16_t raw[HAL_kMaxJoystickAxes];
|
||||
};
|
||||
@@ -95,14 +96,14 @@ HAL_ENUM_WITH_UNDERLYING_TYPE(HAL_JoystickPOV, uint8_t){
|
||||
};
|
||||
|
||||
struct HAL_JoystickPOVs {
|
||||
int16_t count;
|
||||
uint8_t available;
|
||||
HAL_JoystickPOV povs[HAL_kMaxJoystickPOVs];
|
||||
};
|
||||
typedef struct HAL_JoystickPOVs HAL_JoystickPOVs;
|
||||
|
||||
struct HAL_JoystickButtons {
|
||||
uint32_t buttons;
|
||||
uint8_t count;
|
||||
uint64_t buttons;
|
||||
uint64_t available;
|
||||
};
|
||||
typedef struct HAL_JoystickButtons HAL_JoystickButtons;
|
||||
|
||||
@@ -110,10 +111,6 @@ struct HAL_JoystickDescriptor {
|
||||
uint8_t isGamepad;
|
||||
uint8_t type;
|
||||
char name[256];
|
||||
uint8_t axisCount;
|
||||
uint8_t axisTypes[HAL_kMaxJoystickAxes];
|
||||
uint8_t buttonCount;
|
||||
uint8_t povCount;
|
||||
};
|
||||
typedef struct HAL_JoystickDescriptor HAL_JoystickDescriptor;
|
||||
|
||||
|
||||
@@ -140,17 +140,17 @@ void HALSIM_SetMatchInfo(const HAL_MatchInfo* info);
|
||||
void HALSIM_SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state);
|
||||
void HALSIM_SetJoystickAxis(int32_t stick, int32_t axis, double value);
|
||||
void HALSIM_SetJoystickPOV(int32_t stick, int32_t pov, HAL_JoystickPOV value);
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint32_t buttons);
|
||||
void HALSIM_SetJoystickAxisCount(int32_t stick, int32_t count);
|
||||
void HALSIM_SetJoystickPOVCount(int32_t stick, int32_t count);
|
||||
void HALSIM_SetJoystickButtonCount(int32_t stick, int32_t count);
|
||||
void HALSIM_GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
int32_t* buttonCount, int32_t* povCount);
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint64_t buttons);
|
||||
void HALSIM_SetJoystickAxesAvailable(int32_t stick, uint16_t available);
|
||||
void HALSIM_SetJoystickPOVsAvailable(int32_t stick, uint8_t available);
|
||||
void HALSIM_SetJoystickButtonsAvailable(int32_t stick, uint64_t available);
|
||||
void HALSIM_GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
uint64_t* buttonsAvailable,
|
||||
uint8_t* povsAvailable);
|
||||
|
||||
void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad);
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const struct WPI_String* name);
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const struct WPI_String* message);
|
||||
void HALSIM_SetEventName(const struct WPI_String* name);
|
||||
|
||||
@@ -266,15 +266,16 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_GetAllJoystickData(HAL_JoystickAxes* axes, HAL_JoystickPOVs* povs,
|
||||
void HAL_GetAllJoystickData(int32_t joystickNum, HAL_JoystickAxes* axes,
|
||||
HAL_JoystickPOVs* povs,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
if (gShutdown) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock{driverStation->cacheMutex};
|
||||
std::memcpy(axes, currentRead->axes, sizeof(currentRead->axes));
|
||||
std::memcpy(povs, currentRead->povs, sizeof(currentRead->povs));
|
||||
std::memcpy(buttons, currentRead->buttons, sizeof(currentRead->buttons));
|
||||
*axes = currentRead->axes[joystickNum];
|
||||
*povs = currentRead->povs[joystickNum];
|
||||
*buttons = currentRead->buttons[joystickNum];
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
@@ -314,15 +315,6 @@ void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum) {
|
||||
std::memcpy(write, cName, len);
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.axisTypes[axis];
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
SimDriverStationData->SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
|
||||
@@ -230,9 +230,9 @@ void DriverStationData::SetJoystickButton(int32_t stick, int32_t button,
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
if (state) {
|
||||
m_joystickData[stick].buttons.buttons |= 1 << (button - 1);
|
||||
m_joystickData[stick].buttons.buttons |= 1llu << button;
|
||||
} else {
|
||||
m_joystickData[stick].buttons.buttons &= ~(1 << (button - 1));
|
||||
m_joystickData[stick].buttons.buttons &= ~(1llu << button);
|
||||
}
|
||||
m_joystickButtonsCallbacks(stick, &m_joystickData[stick].buttons);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void DriverStationData::SetJoystickPOV(int32_t stick, int32_t pov,
|
||||
m_joystickPOVsCallbacks(stick, &m_joystickData[stick].povs);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickButtons(int32_t stick, uint32_t buttons) {
|
||||
void DriverStationData::SetJoystickButtons(int32_t stick, uint64_t buttons) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
@@ -272,52 +272,50 @@ void DriverStationData::SetJoystickButtons(int32_t stick, uint32_t buttons) {
|
||||
m_joystickButtonsCallbacks(stick, &m_joystickData[stick].buttons);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickAxisCount(int32_t stick, int32_t count) {
|
||||
void DriverStationData::SetJoystickAxesAvailable(int32_t stick,
|
||||
uint16_t available) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].axes.count = count;
|
||||
m_joystickData[stick].descriptor.axisCount = count;
|
||||
m_joystickData[stick].axes.available = available;
|
||||
m_joystickAxesCallbacks(stick, &m_joystickData[stick].axes);
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickPOVCount(int32_t stick, int32_t count) {
|
||||
void DriverStationData::SetJoystickPOVsAvailable(int32_t stick,
|
||||
uint8_t available) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].povs.count = count;
|
||||
m_joystickData[stick].descriptor.povCount = count;
|
||||
m_joystickData[stick].povs.available = available;
|
||||
m_joystickPOVsCallbacks(stick, &m_joystickData[stick].povs);
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickButtonCount(int32_t stick, int32_t count) {
|
||||
void DriverStationData::SetJoystickButtonsAvailable(int32_t stick,
|
||||
uint64_t available) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].buttons.count = count;
|
||||
m_joystickData[stick].descriptor.buttonCount = count;
|
||||
m_joystickData[stick].buttons.available = available;
|
||||
m_joystickButtonsCallbacks(stick, &m_joystickData[stick].buttons);
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
int32_t* buttonCount,
|
||||
int32_t* povCount) {
|
||||
void DriverStationData::GetJoystickAvailables(int32_t stick,
|
||||
uint16_t* axesAvailable,
|
||||
uint64_t* buttonsAvailable,
|
||||
uint8_t* povsAvailable) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
*axisCount = 0;
|
||||
*buttonCount = 0;
|
||||
*povCount = 0;
|
||||
*axesAvailable = 0;
|
||||
*buttonsAvailable = 0;
|
||||
*povsAvailable = 0;
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
*axisCount = m_joystickData[stick].axes.count;
|
||||
*buttonCount = m_joystickData[stick].buttons.count;
|
||||
*povCount = m_joystickData[stick].povs.count;
|
||||
*axesAvailable = m_joystickData[stick].axes.available;
|
||||
*buttonsAvailable = m_joystickData[stick].buttons.available;
|
||||
*povsAvailable = m_joystickData[stick].povs.available;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickIsGamepad(int32_t stick,
|
||||
@@ -350,19 +348,6 @@ void DriverStationData::SetJoystickName(int32_t stick, std::string_view name) {
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickAxisType(int32_t stick, int32_t axis,
|
||||
int32_t type) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].descriptor.axisTypes[axis] = type;
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetGameSpecificMessage(std::string_view message) {
|
||||
std::scoped_lock lock(m_matchInfoMutex);
|
||||
auto copied =
|
||||
@@ -511,26 +496,27 @@ void HALSIM_SetJoystickPOV(int32_t stick, int32_t pov, HAL_JoystickPOV value) {
|
||||
SimDriverStationData->SetJoystickPOV(stick, pov, value);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint32_t buttons) {
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint64_t buttons) {
|
||||
SimDriverStationData->SetJoystickButtons(stick, buttons);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickAxisCount(int32_t stick, int32_t count) {
|
||||
SimDriverStationData->SetJoystickAxisCount(stick, count);
|
||||
void HALSIM_SetJoystickAxesAvailable(int32_t stick, uint16_t available) {
|
||||
SimDriverStationData->SetJoystickAxesAvailable(stick, available);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickPOVCount(int32_t stick, int32_t count) {
|
||||
SimDriverStationData->SetJoystickPOVCount(stick, count);
|
||||
void HALSIM_SetJoystickPOVsAvailable(int32_t stick, uint8_t available) {
|
||||
SimDriverStationData->SetJoystickPOVsAvailable(stick, available);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickButtonCount(int32_t stick, int32_t count) {
|
||||
SimDriverStationData->SetJoystickButtonCount(stick, count);
|
||||
void HALSIM_SetJoystickButtonsAvailable(int32_t stick, uint64_t available) {
|
||||
SimDriverStationData->SetJoystickButtonsAvailable(stick, available);
|
||||
}
|
||||
|
||||
void HALSIM_GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
int32_t* buttonCount, int32_t* povCount) {
|
||||
SimDriverStationData->GetJoystickCounts(stick, axisCount, buttonCount,
|
||||
povCount);
|
||||
void HALSIM_GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
uint64_t* buttonsAvailable,
|
||||
uint8_t* povsAvailable) {
|
||||
SimDriverStationData->GetJoystickAvailables(stick, axesAvailable,
|
||||
buttonsAvailable, povsAvailable);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad) {
|
||||
@@ -545,10 +531,6 @@ void HALSIM_SetJoystickName(int32_t stick, const WPI_String* name) {
|
||||
SimDriverStationData->SetJoystickName(stick, wpi::to_string_view(name));
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {
|
||||
SimDriverStationData->SetJoystickAxisType(stick, axis, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const WPI_String* message) {
|
||||
SimDriverStationData->SetGameSpecificMessage(wpi::to_string_view(message));
|
||||
}
|
||||
|
||||
@@ -98,17 +98,17 @@ class DriverStationData {
|
||||
void SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state);
|
||||
void SetJoystickAxis(int32_t stick, int32_t axis, double value);
|
||||
void SetJoystickPOV(int32_t stick, int32_t pov, HAL_JoystickPOV value);
|
||||
void SetJoystickButtons(int32_t stick, uint32_t buttons);
|
||||
void SetJoystickAxisCount(int32_t stick, int32_t count);
|
||||
void SetJoystickPOVCount(int32_t stick, int32_t count);
|
||||
void SetJoystickButtonCount(int32_t stick, int32_t count);
|
||||
void GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
int32_t* buttonCount, int32_t* povCount);
|
||||
void SetJoystickButtons(int32_t stick, uint64_t buttons);
|
||||
void SetJoystickAxesAvailable(int32_t stick, uint16_t available);
|
||||
void SetJoystickPOVsAvailable(int32_t stick, uint8_t available);
|
||||
void SetJoystickButtonsAvailable(int32_t stick, uint64_t available);
|
||||
void GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
uint64_t* buttonsAvailable,
|
||||
uint8_t* povsAvailable);
|
||||
|
||||
void SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad);
|
||||
void SetJoystickType(int32_t stick, int32_t type);
|
||||
void SetJoystickName(int32_t stick, std::string_view message);
|
||||
void SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
||||
|
||||
void SetGameSpecificMessage(std::string_view message);
|
||||
void SetEventName(std::string_view name);
|
||||
|
||||
@@ -256,7 +256,8 @@ void JoystickDataCache::Update(const mrc::ControlData& data) {
|
||||
auto newAxes = newStick.Axes.Axes();
|
||||
auto newPovs = newStick.Povs.Povs();
|
||||
|
||||
axes[count].count = newAxes.size();
|
||||
axes[count].available = newStick.Axes.GetAvailable();
|
||||
|
||||
for (size_t i = 0; i < newAxes.size(); i++) {
|
||||
axes[count].raw[i] = newAxes[i];
|
||||
int16_t axisValue = newAxes[i];
|
||||
@@ -267,12 +268,13 @@ void JoystickDataCache::Update(const mrc::ControlData& data) {
|
||||
}
|
||||
}
|
||||
|
||||
povs[count].count = newPovs.size();
|
||||
// When mrccomm switches this to available, move to available
|
||||
povs[count].available = (1lu << newPovs.size()) - 1;
|
||||
for (size_t i = 0; i < newPovs.size(); i++) {
|
||||
povs[count].povs[i] = static_cast<HAL_JoystickPOV>(newPovs[i]);
|
||||
}
|
||||
|
||||
buttons[count].count = newStick.Buttons.GetMaxAvailableCount();
|
||||
buttons[count].available = newStick.Buttons.GetAvailable();
|
||||
buttons[count].buttons = newStick.Buttons.Buttons;
|
||||
}
|
||||
}
|
||||
@@ -339,8 +341,6 @@ void TcpCache::Update() {
|
||||
|
||||
desc.isGamepad = newDesc.IsGamepad;
|
||||
desc.type = newDesc.Type;
|
||||
desc.buttonCount = newDesc.GetButtonsCount();
|
||||
desc.povCount = newDesc.GetPovsCount();
|
||||
|
||||
auto joystickName = newDesc.GetName();
|
||||
auto joystickNameLen =
|
||||
@@ -350,14 +350,6 @@ void TcpCache::Update() {
|
||||
std::memcpy(desc.name, joystickName.data(), joystickNameLen);
|
||||
}
|
||||
desc.name[joystickNameLen] = '\0';
|
||||
|
||||
auto sticks = newDesc.AxesTypes();
|
||||
|
||||
desc.axisCount = sticks.size();
|
||||
|
||||
for (size_t i = 0; i < sticks.size(); i++) {
|
||||
desc.axisTypes[i] = sticks[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,12 +482,13 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_GetAllJoystickData(HAL_JoystickAxes* axes, HAL_JoystickPOVs* povs,
|
||||
void HAL_GetAllJoystickData(int32_t joystickNum, HAL_JoystickAxes* axes,
|
||||
HAL_JoystickPOVs* povs,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
std::scoped_lock lock{cacheMutex};
|
||||
std::memcpy(axes, currentRead->axes, sizeof(currentRead->axes));
|
||||
std::memcpy(povs, currentRead->povs, sizeof(currentRead->povs));
|
||||
std::memcpy(buttons, currentRead->buttons, sizeof(currentRead->buttons));
|
||||
*axes = currentRead->axes[joystickNum];
|
||||
*povs = currentRead->povs[joystickNum];
|
||||
*buttons = currentRead->buttons[joystickNum];
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
@@ -546,15 +539,6 @@ void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum) {
|
||||
std::memcpy(write, cName, len);
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.axisTypes[axis];
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
CHECK_JOYSTICK_NUMBER(joystickNum);
|
||||
|
||||
@@ -84,19 +84,20 @@ void HALSIM_SetJoystickAxis(int32_t stick, int32_t axis, double value) {}
|
||||
|
||||
void HALSIM_SetJoystickPOV(int32_t stick, int32_t pov, HAL_JoystickPOV value) {}
|
||||
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint32_t buttons) {}
|
||||
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint64_t buttons) {}
|
||||
|
||||
void HALSIM_SetJoystickAxisCount(int32_t stick, int32_t count) {}
|
||||
void HALSIM_SetJoystickAxesAvailable(int32_t stick, uint16_t available) {}
|
||||
|
||||
void HALSIM_SetJoystickPOVCount(int32_t stick, int32_t count) {}
|
||||
void HALSIM_SetJoystickPOVsAvailable(int32_t stick, uint8_t available) {}
|
||||
|
||||
void HALSIM_SetJoystickButtonCount(int32_t stick, int32_t count) {}
|
||||
void HALSIM_SetJoystickButtonsAvailable(int32_t stick, uint64_t available) {}
|
||||
|
||||
void HALSIM_GetJoystickCounts(int32_t stick, int32_t* axisCount,
|
||||
int32_t* buttonCount, int32_t* povCount) {
|
||||
*axisCount = 0;
|
||||
*buttonCount = 0;
|
||||
*povCount = 0;
|
||||
void HALSIM_GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
uint64_t* buttonsAvailable,
|
||||
uint8_t* povsAvailable) {
|
||||
*axesAvailable = 0;
|
||||
*buttonsAvailable = 0;
|
||||
*povsAvailable = 0;
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad) {}
|
||||
@@ -105,8 +106,6 @@ void HALSIM_SetJoystickType(int32_t stick, int32_t type) {}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const struct WPI_String* name) {}
|
||||
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const struct WPI_String* message) {}
|
||||
|
||||
void HALSIM_SetEventName(const struct WPI_String* name) {}
|
||||
|
||||
Reference in New Issue
Block a user