mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Don't raise exception for Joystick axis/POV out of active range. Shorten error message and change to Warning (filtered by DS by default)
Return 0.0 in this case (as it can be commonly caused by the joystick not being plugged in). Still raise exception (Java) / set error (C++) if the asked-for axis/POV is higher than kMaxJoystickAxes/kMaxJoystickPOVs. See artf3673. Change-Id: I4847c5badb358ed08f01170724ec1446af2e4ab9
This commit is contained in:
committed by
Kevin O'Connor
parent
5b2520c35f
commit
7f30b6bff4
@@ -223,13 +223,18 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public double getStickAxis(int stick, int axis) {
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
if (axis < 0 || axis >= m_joystickAxes[stick].length) {
|
||||
if (axis < 0 || axis >= FRCNetworkCommunicationsLibrary.kMaxJoystickAxes) {
|
||||
throw new RuntimeException("Joystick axis is out of range");
|
||||
}
|
||||
|
||||
if (axis >= m_joystickAxes[stick].length) {
|
||||
reportError("WARNING: Joystick axis " + axis + " on port " + stick + " not available, check if controller is plugged in\n", false);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
byte value = (byte)m_joystickAxes[stick][axis];
|
||||
|
||||
if(value < 0) {
|
||||
@@ -246,13 +251,18 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickPOV(int stick, int pov) {
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
if (pov < 0 || pov >= m_joystickPOVs[stick].length) {
|
||||
if (pov < 0 || pov >= FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs) {
|
||||
throw new RuntimeException("Joystick POV is out of range");
|
||||
}
|
||||
|
||||
if (pov >= m_joystickPOVs[stick].length) {
|
||||
reportError("WARNING: Joystick POV " + pov + " on port " + stick + " not available, check if controller is plugged in\n", false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_joystickPOVs[stick][pov];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user