[wpilib] Add IsJoystickConnected method (#2847)

This commit is contained in:
Austin Shalit
2020-11-13 14:11:10 -05:00
committed by GitHub
parent 6b5e83ce1d
commit de17422793
8 changed files with 129 additions and 0 deletions

View File

@@ -331,6 +331,11 @@ int DriverStation::GetJoystickAxisType(int stick, int axis) const {
return static_cast<bool>(descriptor.axisTypes);
}
bool DriverStation::IsJoystickConnected(int stick) const {
return GetStickAxisCount(stick) > 0 || GetStickButtonCount(stick) > 0 ||
GetStickPOVCount(stick) > 0;
}
bool DriverStation::IsEnabled() const {
HAL_ControlWord controlWord;
HAL_GetControlWord(&controlWord);

View File

@@ -47,6 +47,10 @@ int GenericHID::GetButtonCount() const {
return m_ds->GetStickButtonCount(m_port);
}
bool GenericHID::IsConnected() const {
return m_ds->IsJoystickConnected(m_port);
}
GenericHID::HIDType GenericHID::GetType() const {
return static_cast<HIDType>(m_ds->GetJoystickType(m_port));
}

View File

@@ -181,6 +181,17 @@ class DriverStation : public ErrorBase {
*/
int GetJoystickAxisType(int stick, int axis) const;
/**
* Returns if a joystick is connected to the Driver Station.
*
* This makes a best effort guess by looking at the reported number of axis,
* buttons, and POVs attached.
*
* @param stick The joystick port number
* @return true if a joystick is connected
*/
bool IsJoystickConnected(int stick) const;
/**
* Check if the DS has enabled the robot.
*

View File

@@ -136,6 +136,13 @@ class GenericHID : public ErrorBase {
*/
int GetButtonCount() const;
/**
* Get if the HID is connected.
*
* @return true if the HID is connected
*/
bool IsConnected() const;
/**
* Get the type of the HID.
*