Merge "Don't raise exception for Joystick axis/POV out of active range. Shorten error message and change to Warning (filtered by DS by default)"

This commit is contained in:
Brad Miller (WPI)
2014-11-05 07:17:09 -08:00
committed by Gerrit Code Review
2 changed files with 22 additions and 6 deletions

View File

@@ -194,7 +194,10 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
if (axis >= m_joystickAxes[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
if (axis >= kMaxJoystickAxes)
wpi_setWPIError(BadJoystickAxis);
else
ReportError("WARNING: Joystick Axis missing, check if all controllers are plugged in\n");
return 0.0f;
}
@@ -224,7 +227,10 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
if (pov >= m_joystickPOVs[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
if (pov >= kMaxJoystickPOVs)
wpi_setWPIError(BadJoystickAxis);
else
ReportError("WARNING: Joystick POV missing, check if all controllers are plugged in\n");
return 0;
}

View File

@@ -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];
}