From fa229f2b136fffb3f256d2d56e0223cf4d714749 Mon Sep 17 00:00:00 2001 From: Brad Miller Date: Wed, 3 Dec 2014 11:02:12 -0500 Subject: [PATCH] Added java joystick message spam fix (artf3836) Change-Id: I1e29aea00dc61574272f47fc3e1bcd98bd825d22 --- wpilibc/wpilibC++Devices/src/DriverStation.cpp | 2 +- .../edu/wpi/first/wpilibj/DriverStation.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wpilibc/wpilibC++Devices/src/DriverStation.cpp b/wpilibc/wpilibC++Devices/src/DriverStation.cpp index a0b24aa289..a73a81ebe8 100644 --- a/wpilibc/wpilibC++Devices/src/DriverStation.cpp +++ b/wpilibc/wpilibC++Devices/src/DriverStation.cpp @@ -18,7 +18,7 @@ // set the logging level TLogLevel dsLogLevel = logDEBUG; -const double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0e06; +const double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0; #define DS_LOG(level) \ if (level > dsLogLevel) ; \ diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index ae949eb598..9c639b0a04 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -31,6 +31,9 @@ public class DriverStation implements RobotState.Interface { */ public enum Alliance { Red, Blue, Invalid } + private static final double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0; + private double m_nextMessageTime = 0.0; + private static class DriverStationTask implements Runnable { private DriverStation m_ds; @@ -160,6 +163,14 @@ public class DriverStation implements RobotState.Interface { return voltage; } + private void reportJoystickUnpluggedError(String message) { + double currentTime = Timer.getFPGATimestamp(); + if (currentTime > m_nextMessageTime) { + reportError(message, false); + m_nextMessageTime = currentTime + JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL; + } + } + /** * Get the value of the axis on a joystick. * This depends on the mapping of the joystick connected to the specified port. @@ -180,7 +191,7 @@ public class DriverStation implements RobotState.Interface { short[] joystickAxes = FRCNetworkCommunicationsLibrary.HALGetJoystickAxes((byte)stick); if (axis >= joystickAxes.length) { - reportError("WARNING: Joystick axis " + axis + " on port " + stick + " not available, check if controller is plugged in\n", false); + reportJoystickUnpluggedError("WARNING: Joystick axis " + axis + " on port " + stick + " not available, check if controller is plugged in\n"); return 0.0; } @@ -210,7 +221,7 @@ public class DriverStation implements RobotState.Interface { short[] joystickPOVs = FRCNetworkCommunicationsLibrary.HALGetJoystickPOVs((byte)stick); if (pov >= joystickPOVs.length) { - reportError("WARNING: Joystick POV " + pov + " on port " + stick + " not available, check if controller is plugged in\n", false); + reportJoystickUnpluggedError("WARNING: Joystick POV " + pov + " on port " + stick + " not available, check if controller is plugged in\n"); return 0; } @@ -234,7 +245,7 @@ public class DriverStation implements RobotState.Interface { byte count = 0; count = countBuffer.get(); if(button >= count) { - reportError("WARNING: Joystick Button " + button + " on port " + stick + " not available, check if controller is plugged in\n", false); + reportJoystickUnpluggedError("WARNING: Joystick Button " + button + " on port " + stick + " not available, check if controller is plugged in\n"); return false; } return ((0x1 << (button - 1)) & buttons) != 0;