mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user