mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +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);
|
||||
|
||||
@@ -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