diff --git a/hal/include/HAL/HAL.hpp b/hal/include/HAL/HAL.hpp index 8d5e537ae0..f8c6694618 100644 --- a/hal/include/HAL/HAL.hpp +++ b/hal/include/HAL/HAL.hpp @@ -174,7 +174,7 @@ static const size_t kMaxJoystickPOVs = 12; struct HALJoystickAxes { uint16_t count; - int16_t axes[kMaxJoystickAxes]; + float axes[kMaxJoystickAxes]; }; struct HALJoystickPOVs { diff --git a/hal/lib/Shared/HAL.cpp b/hal/lib/Shared/HAL.cpp index 4f89206c02..edc4040b04 100644 --- a/hal/lib/Shared/HAL.cpp +++ b/hal/lib/Shared/HAL.cpp @@ -4,6 +4,11 @@ #include #include "FRC_NetworkCommunication/FRCComm.h" +struct HALJoystickAxesInt { + uint16_t count; + int16_t axes[kMaxJoystickAxes]; +}; + extern "C" { int HALGetControlWord(HALControlWord* data) { @@ -17,9 +22,26 @@ int HALGetAllianceStation(enum HALAllianceStationID* allianceStation) { (AllianceStationID_t*)allianceStation); } -int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes* axes) { - return FRC_NetworkCommunication_getJoystickAxes( - joystickNum, (JoystickAxes_t*)axes, kMaxJoystickAxes); +int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes *axes) { + HALJoystickAxesInt axesInt; + + int retVal = FRC_NetworkCommunication_getJoystickAxes( + joystickNum, (JoystickAxes_t*) &axesInt, kMaxJoystickAxes); + + // copy int values to float values + axes->count = axesInt.count; + // current scaling is -128 to 127, can easily be patched in the future by + // changing this function. + for (unsigned int i = 0; i < axesInt.count; i++) { + int8_t value = axesInt.axes[i]; + if (value < 0) { + axes->axes[i] = value / 128.0f; + } else { + axes->axes[i] = value / 127.0f; + } + } + + return retVal; } int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs* povs) { diff --git a/wpilibc/Athena/src/DriverStation.cpp b/wpilibc/Athena/src/DriverStation.cpp index 474dce30bd..14a962dcbc 100644 --- a/wpilibc/Athena/src/DriverStation.cpp +++ b/wpilibc/Athena/src/DriverStation.cpp @@ -303,14 +303,8 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis) { "Joystick Axis missing, check if all controllers are plugged in"); return 0.0f; } - - int8_t value = m_joystickAxes[stick].axes[axis]; - - if (value < 0) { - return value / 128.0f; - } else { - return value / 127.0f; - } + + return m_joystickAxes[stick].axes[axis]; } /** diff --git a/wpilibj/src/athena/cpp/lib/FRCNetworkCommunicationsLibrary.cpp b/wpilibj/src/athena/cpp/lib/FRCNetworkCommunicationsLibrary.cpp index 4c403f1a67..e9ec7f2f6f 100644 --- a/wpilibj/src/athena/cpp/lib/FRCNetworkCommunicationsLibrary.cpp +++ b/wpilibj/src/athena/cpp/lib/FRCNetworkCommunicationsLibrary.cpp @@ -146,7 +146,7 @@ Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_NativeH */ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickAxes( - JNIEnv * env, jclass, jbyte joystickNum, jshortArray axesArray) { + JNIEnv * env, jclass, jbyte joystickNum, jfloatArray axesArray) { NETCOMM_LOG(logDEBUG) << "Calling HALJoystickAxes"; HALJoystickAxes axes; HALGetJoystickAxes(joystickNum, &axes); @@ -157,7 +157,7 @@ Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJ ThrowIllegalArgumentException(env, "Native array size larger then passed in java array size"); } - env->SetShortArrayRegion(axesArray, 0, axes.count, axes.axes); + env->SetFloatArrayRegion(axesArray, 0, axes.count, axes.axes); return axes.count; } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/DriverStation.java index 530066c4a5..d2349a0065 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/DriverStation.java @@ -31,11 +31,11 @@ public class DriverStation implements RobotState.Interface { } private class HALJoystickAxes { - public short[] m_axes; + public float[] m_axes; public byte m_count; public HALJoystickAxes(int count) { - m_axes = new short[count]; + m_axes = new float[count]; } } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java index cb821efef8..2f1ef7f1d4 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java @@ -224,8 +224,8 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper { public static int kMaxJoystickAxes = 12; public static int kMaxJoystickPOVs = 12; - - public static native byte HALGetJoystickAxes(byte joystickNum, short[] axesArray); + + public static native byte HALGetJoystickAxes(byte joystickNum, float[] axesArray); public static native byte HALGetJoystickPOVs(byte joystickNum, short[] povsArray);