[sim] Add joystick simulation support (#2595)

This adds joystick functions to DriverStationSim, and new GenericHIDSim,
JoystickSim, and XboxControllerSim classes.
This commit is contained in:
Peter Johnson
2020-07-15 00:33:57 -07:00
committed by GitHub
parent b06ddcdd86
commit b9feb81226
19 changed files with 1979 additions and 19 deletions

View File

@@ -45,6 +45,38 @@ void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {}
void HALSIM_NotifyDriverStationNewData(void) {}
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, int32_t 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_SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox) {}
void HALSIM_SetJoystickType(int32_t stick, int32_t type) {}
void HALSIM_SetJoystickName(int32_t stick, const char* name) {}
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {}
void HALSIM_SetGameSpecificMessage(const char* message) {}
void HALSIM_SetEventName(const char* name) {}
void HALSIM_SetMatchType(HAL_MatchType type) {}
void HALSIM_SetMatchNumber(int32_t matchNumber) {}
void HALSIM_SetReplayNumber(int32_t replayNumber) {}
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {}

View File

@@ -325,6 +325,109 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setDsAttached
HALSIM_SetDriverStationDsAttached(value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: registerAllianceStationIdCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_registerAllianceStationIdCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationAllianceStationIdCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: cancelAllianceStationIdCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_cancelAllianceStationIdCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationAllianceStationIdCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getAllianceStationId
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getAllianceStationId
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationAllianceStationId();
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setAllianceStationId
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setAllianceStationId
(JNIEnv*, jclass, jint value)
{
HALSIM_SetDriverStationAllianceStationId(
static_cast<HAL_AllianceStationID>(value));
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: registerMatchTimeCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_registerMatchTimeCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationMatchTimeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: cancelMatchTimeCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_cancelMatchTimeCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationMatchTimeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getMatchTime
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getMatchTime
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationMatchTime();
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchTime
* Signature: (D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchTime
(JNIEnv*, jclass, jdouble value)
{
HALSIM_SetDriverStationMatchTime(value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxes
@@ -393,6 +496,38 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtons
HALSIM_SetJoystickButtons(joystickNum, &joystickButtons);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getJoystickOutputs
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getJoystickOutputs
(JNIEnv* env, jclass, jint stick)
{
int64_t outputs = 0;
int32_t leftRumble;
int32_t rightRumble;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return outputs;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getJoystickRumble
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getJoystickRumble
(JNIEnv* env, jclass, jint stick, jint rumbleNum)
{
int64_t outputs;
int32_t leftRumble = 0;
int32_t rightRumble = 0;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return rumbleNum == 0 ? leftRumble : rightRumble;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchInfo
@@ -483,6 +618,198 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setSendConsoleLine
}
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButton
* Signature: (IIZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButton
(JNIEnv*, jclass, jint stick, jint button, jboolean state)
{
HALSIM_SetJoystickButton(stick, button, state);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxis
* Signature: (IID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxis
(JNIEnv*, jclass, jint stick, jint axis, jdouble value)
{
HALSIM_SetJoystickAxis(stick, axis, value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOV
* Signature: (III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOV
(JNIEnv*, jclass, jint stick, jint pov, jint value)
{
HALSIM_SetJoystickPOV(stick, pov, value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonsValue
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonsValue
(JNIEnv*, jclass, jint stick, jint buttons)
{
HALSIM_SetJoystickButtonsValue(stick, buttons);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxisCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxisCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickAxisCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOVCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickPOVCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickButtonCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickIsXbox
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickIsXbox
(JNIEnv*, jclass, jint stick, jboolean isXbox)
{
HALSIM_SetJoystickIsXbox(stick, isXbox);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickType
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickType
(JNIEnv*, jclass, jint stick, jint type)
{
HALSIM_SetJoystickType(stick, type);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickName
* Signature: (ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickName
(JNIEnv* env, jclass, jint stick, jstring name)
{
HALSIM_SetJoystickName(stick, JStringRef{env, name}.c_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
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setGameSpecificMessage
(JNIEnv* env, jclass, jstring message)
{
HALSIM_SetGameSpecificMessage(JStringRef{env, message}.c_str());
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setEventName
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setEventName
(JNIEnv* env, jclass, jstring name)
{
HALSIM_SetEventName(JStringRef{env, name}.c_str());
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchType
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchType
(JNIEnv*, jclass, jint type)
{
HALSIM_SetMatchType(static_cast<HAL_MatchType>(static_cast<int>(type)));
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchNumber
(JNIEnv*, jclass, jint matchNumber)
{
HALSIM_SetMatchNumber(matchNumber);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setReplayNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setReplayNumber
(JNIEnv*, jclass, jint replayNumber)
{
HALSIM_SetReplayNumber(replayNumber);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: resetData

View File

@@ -80,6 +80,25 @@ void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
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, int32_t 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_SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
void HALSIM_SetJoystickType(int32_t stick, int32_t type);
void HALSIM_SetJoystickName(int32_t stick, const char* name);
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
void HALSIM_SetGameSpecificMessage(const char* message);
void HALSIM_SetEventName(const char* name);
void HALSIM_SetMatchType(HAL_MatchType type);
void HALSIM_SetMatchNumber(int32_t matchNumber);
void HALSIM_SetReplayNumber(int32_t replayNumber);
void HALSIM_RegisterDriverStationAllCallbacks(HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -12,6 +12,8 @@
#include "DriverStationDataInternal.h"
#include "hal/DriverStation.h"
static constexpr int kNumJoysticks = 6;
namespace hal {
struct JoystickOutputStore {
int64_t outputs = 0;
@@ -47,13 +49,14 @@ void DriverStationData::ResetData() {
{
std::scoped_lock lock(m_joystickDataMutex);
m_joystickAxes = std::make_unique<HAL_JoystickAxes[]>(6);
m_joystickPOVs = std::make_unique<HAL_JoystickPOVs[]>(6);
m_joystickButtons = std::make_unique<HAL_JoystickButtons[]>(6);
m_joystickOutputs = std::make_unique<JoystickOutputStore[]>(6);
m_joystickDescriptor = std::make_unique<HAL_JoystickDescriptor[]>(6);
m_joystickAxes = std::make_unique<HAL_JoystickAxes[]>(kNumJoysticks);
m_joystickPOVs = std::make_unique<HAL_JoystickPOVs[]>(kNumJoysticks);
m_joystickButtons = std::make_unique<HAL_JoystickButtons[]>(kNumJoysticks);
m_joystickOutputs = std::make_unique<JoystickOutputStore[]>(kNumJoysticks);
m_joystickDescriptor =
std::make_unique<HAL_JoystickDescriptor[]>(kNumJoysticks);
for (int i = 0; i < 6; i++) {
for (int i = 0; i < kNumJoysticks; i++) {
m_joystickAxes[i].count = 0;
m_joystickPOVs[i].count = 0;
m_joystickButtons[i].count = 0;
@@ -71,21 +74,25 @@ void DriverStationData::ResetData() {
void DriverStationData::GetJoystickAxes(int32_t joystickNum,
HAL_JoystickAxes* axes) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
*axes = m_joystickAxes[joystickNum];
}
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
HAL_JoystickPOVs* povs) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
*povs = m_joystickPOVs[joystickNum];
}
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
HAL_JoystickButtons* buttons) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
*buttons = m_joystickButtons[joystickNum];
}
void DriverStationData::GetJoystickDescriptor(
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
*descriptor = m_joystickDescriptor[joystickNum];
// Always ensure name is null terminated
@@ -95,6 +102,7 @@ void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
int64_t* outputs,
int32_t* leftRumble,
int32_t* rightRumble) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
*leftRumble = m_joystickOutputs[joystickNum].leftRumble;
*outputs = m_joystickOutputs[joystickNum].outputs;
@@ -107,22 +115,26 @@ void DriverStationData::GetMatchInfo(HAL_MatchInfo* info) {
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
const HAL_JoystickAxes* axes) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickAxes[joystickNum] = *axes;
}
void DriverStationData::SetJoystickPOVs(int32_t joystickNum,
const HAL_JoystickPOVs* povs) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickPOVs[joystickNum] = *povs;
}
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
const HAL_JoystickButtons* buttons) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickButtons[joystickNum] = *buttons;
}
void DriverStationData::SetJoystickDescriptor(
int32_t joystickNum, const HAL_JoystickDescriptor* descriptor) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickDescriptor[joystickNum] = *descriptor;
}
@@ -130,6 +142,7 @@ void DriverStationData::SetJoystickDescriptor(
void DriverStationData::SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
int32_t leftRumble,
int32_t rightRumble) {
if (joystickNum < 0 || joystickNum >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickOutputs[joystickNum].leftRumble = leftRumble;
m_joystickOutputs[joystickNum].outputs = outputs;
@@ -144,6 +157,116 @@ void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
void DriverStationData::NotifyNewData() { HAL_ReleaseDSMutex(); }
void DriverStationData::SetJoystickButton(int32_t stick, int32_t button,
HAL_Bool state) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
if (state)
m_joystickButtons[stick].buttons |= 1 << (button - 1);
else
m_joystickButtons[stick].buttons &= ~(1 << (button - 1));
}
void DriverStationData::SetJoystickAxis(int32_t stick, int32_t axis,
double value) {
if (stick < 0 || stick >= kNumJoysticks) return;
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickAxes[stick].axes[axis] = value;
}
void DriverStationData::SetJoystickPOV(int32_t stick, int32_t pov,
int32_t value) {
if (stick < 0 || stick >= kNumJoysticks) return;
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickPOVs[stick].povs[pov] = value;
}
void DriverStationData::SetJoystickButtons(int32_t stick, uint32_t buttons) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickButtons[stick].buttons = buttons;
}
void DriverStationData::SetJoystickAxisCount(int32_t stick, int32_t count) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickAxes[stick].count = count;
m_joystickDescriptor[stick].axisCount = count;
}
void DriverStationData::SetJoystickPOVCount(int32_t stick, int32_t count) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickPOVs[stick].count = count;
m_joystickDescriptor[stick].povCount = count;
}
void DriverStationData::SetJoystickButtonCount(int32_t stick, int32_t count) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickButtons[stick].count = count;
m_joystickDescriptor[stick].buttonCount = count;
}
void DriverStationData::SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickDescriptor[stick].isXbox = isXbox;
}
void DriverStationData::SetJoystickType(int32_t stick, int32_t type) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
m_joystickDescriptor[stick].type = type;
}
void DriverStationData::SetJoystickName(int32_t stick, const char* name) {
if (stick < 0 || stick >= kNumJoysticks) return;
std::scoped_lock lock(m_joystickDataMutex);
std::strncpy(m_joystickDescriptor[stick].name, name,
sizeof(m_joystickDescriptor[stick].name) - 1);
}
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_joystickDescriptor[stick].axisTypes[axis] = type;
}
void DriverStationData::SetGameSpecificMessage(const char* message) {
std::scoped_lock lock(m_matchInfoMutex);
std::strncpy(reinterpret_cast<char*>(m_matchInfo->gameSpecificMessage),
message, sizeof(m_matchInfo->gameSpecificMessage) - 1);
*(std::end(m_matchInfo->gameSpecificMessage) - 1) = '\0';
m_matchInfo->gameSpecificMessageSize = std::strlen(message);
}
void DriverStationData::SetEventName(const char* name) {
std::scoped_lock lock(m_matchInfoMutex);
std::strncpy(m_matchInfo->eventName, name,
sizeof(m_matchInfo->eventName) - 1);
*(std::end(m_matchInfo->eventName) - 1) = '\0';
}
void DriverStationData::SetMatchType(HAL_MatchType type) {
std::scoped_lock lock(m_matchInfoMutex);
m_matchInfo->matchType = type;
}
void DriverStationData::SetMatchNumber(int32_t matchNumber) {
std::scoped_lock lock(m_matchInfoMutex);
m_matchInfo->matchNumber = matchNumber;
}
void DriverStationData::SetReplayNumber(int32_t replayNumber) {
std::scoped_lock lock(m_matchInfoMutex);
m_matchInfo->replayNumber = replayNumber;
}
extern "C" {
void HALSIM_ResetDriverStationData(void) { SimDriverStationData->ResetData(); }
@@ -191,6 +314,70 @@ void HALSIM_NotifyDriverStationNewData(void) {
SimDriverStationData->NotifyNewData();
}
void HALSIM_SetJoystickButton(int32_t stick, int32_t button, HAL_Bool state) {
SimDriverStationData->SetJoystickButton(stick, button, state);
}
void HALSIM_SetJoystickAxis(int32_t stick, int32_t axis, double value) {
SimDriverStationData->SetJoystickAxis(stick, axis, value);
}
void HALSIM_SetJoystickPOV(int32_t stick, int32_t pov, int32_t value) {
SimDriverStationData->SetJoystickPOV(stick, pov, value);
}
void HALSIM_SetJoystickButtonsValue(int32_t stick, uint32_t buttons) {
SimDriverStationData->SetJoystickButtons(stick, buttons);
}
void HALSIM_SetJoystickAxisCount(int32_t stick, int32_t count) {
SimDriverStationData->SetJoystickAxisCount(stick, count);
}
void HALSIM_SetJoystickPOVCount(int32_t stick, int32_t count) {
SimDriverStationData->SetJoystickPOVCount(stick, count);
}
void HALSIM_SetJoystickButtonCount(int32_t stick, int32_t count) {
SimDriverStationData->SetJoystickButtonCount(stick, count);
}
void HALSIM_SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox) {
SimDriverStationData->SetJoystickIsXbox(stick, isXbox);
}
void HALSIM_SetJoystickType(int32_t stick, int32_t type) {
SimDriverStationData->SetJoystickType(stick, type);
}
void HALSIM_SetJoystickName(int32_t stick, const char* name) {
SimDriverStationData->SetJoystickName(stick, name);
}
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {
SimDriverStationData->SetJoystickAxisType(stick, axis, type);
}
void HALSIM_SetGameSpecificMessage(const char* message) {
SimDriverStationData->SetGameSpecificMessage(message);
}
void HALSIM_SetEventName(const char* name) {
SimDriverStationData->SetEventName(name);
}
void HALSIM_SetMatchType(HAL_MatchType type) {
SimDriverStationData->SetMatchType(type);
}
void HALSIM_SetMatchNumber(int32_t matchNumber) {
SimDriverStationData->SetMatchNumber(matchNumber);
}
void HALSIM_SetReplayNumber(int32_t replayNumber) {
SimDriverStationData->SetReplayNumber(replayNumber);
}
#define REGISTER(NAME) \
SimDriverStationData->NAME.RegisterCallback(callback, param, initialNotify)

View File

@@ -58,6 +58,25 @@ class DriverStationData {
void NotifyNewData();
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, int32_t 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 SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
void SetJoystickType(int32_t stick, int32_t type);
void SetJoystickName(int32_t stick, const char* name);
void SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
void SetGameSpecificMessage(const char* message);
void SetEventName(const char* name);
void SetMatchType(HAL_MatchType type);
void SetMatchNumber(int32_t matchNumber);
void SetReplayNumber(int32_t replayNumber);
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetEnabledName> enabled{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetAutonomousName> autonomous{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetTestName> test{false};