mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Added functions to get names, HID types and isXbox descriptors from joysticks.
Change-Id: I3cd6ebc04d64398f05001cd008696e13ee1ab6ea
This commit is contained in:
@@ -57,6 +57,10 @@ public class DriverStation implements RobotState.Interface {
|
||||
private short[][] m_joystickAxes = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickAxes];
|
||||
private short[][] m_joystickPOVs = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs];
|
||||
private HALJoystickButtons[] m_joystickButtons = new HALJoystickButtons[kJoystickPorts];
|
||||
private int[] m_joystickIsXbox = new int[kJoystickPorts];
|
||||
private int[] m_joystickType = new int[kJoystickPorts];
|
||||
private String[] m_joystickName = new String[kJoystickPorts];
|
||||
private int[][] m_joystickAxisType = new int[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickAxes];
|
||||
|
||||
private Thread m_thread;
|
||||
private final Object m_dataSem;
|
||||
@@ -273,7 +277,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
return m_joystickPOVs[stick][pov];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the number of POVs on a given joystick port
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
@@ -343,6 +347,68 @@ public class DriverStation implements RobotState.Interface {
|
||||
return m_joystickButtons[stick].count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of isXbox on a joystick
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return A boolean that returns the value of isXbox
|
||||
*/
|
||||
public synchronized boolean getJoystickIsXbox(int stick){
|
||||
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
//TODO: Remove this when calling for descriptor on empty stick no longer crashes
|
||||
if(1 > m_joystickButtons[stick].count && 1 > m_joystickAxes[stick].length) {
|
||||
reportJoystickUnpluggedError("WARNING: Joystick on port " + stick + " not available, check if controller is plugged in\n");
|
||||
return false;
|
||||
}
|
||||
boolean retVal = false;
|
||||
if(FRCNetworkCommunicationsLibrary.HALGetJoystickIsXbox((byte)stick)==1)
|
||||
{
|
||||
retVal = true;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of type on a joystick
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The value of type
|
||||
*/
|
||||
public synchronized int getJoystickType(int stick){
|
||||
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
//TODO: Remove this when calling for descriptor on empty stick no longer crashes
|
||||
if(1 > m_joystickButtons[stick].count && 1 > m_joystickAxes[stick].length) {
|
||||
reportJoystickUnpluggedError("WARNING: Joystick on port " + stick + " not available, check if controller is plugged in\n");
|
||||
return -1;
|
||||
}
|
||||
return FRCNetworkCommunicationsLibrary.HALGetJoystickType((byte) stick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the joystick at a port
|
||||
*
|
||||
* @param stick The joystick port number
|
||||
* @return The value of name
|
||||
*/
|
||||
public synchronized String getJoystickName(int stick){
|
||||
|
||||
if(stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
//TODO: Remove this when calling for descriptor on empty stick no longer crashes
|
||||
if(1 > m_joystickButtons[stick].count && 1 > m_joystickAxes[stick].length) {
|
||||
reportJoystickUnpluggedError("WARNING: Joystick on port " + stick + " not available, check if controller is plugged in\n");
|
||||
return "";
|
||||
}
|
||||
return FRCNetworkCommunicationsLibrary.HALGetJoystickName((byte)stick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether the Driver Station requires the
|
||||
* robot to be enabled.
|
||||
|
||||
@@ -412,6 +412,33 @@ public class Joystick extends GenericHID {
|
||||
m_axes[axis.value] = (byte) channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of isXbox for the current joystick.
|
||||
*
|
||||
* @param value A boolean that is true if the controller is an xbox controller.
|
||||
*/
|
||||
public boolean getIsXbox() {
|
||||
return m_ds.getJoystickIsXbox(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HID type of the current joystick.
|
||||
*
|
||||
* @param value The HID type value of the current joystick.
|
||||
*/
|
||||
public int getType() {
|
||||
return m_ds.getJoystickType(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the current joystick.
|
||||
*
|
||||
* @param value The name of the current joystick.
|
||||
*/
|
||||
public String getName() {
|
||||
return m_ds.getJoystickName(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the joystick. The DS currently supports 2 rumble values,
|
||||
* left rumble and right rumble
|
||||
|
||||
@@ -477,6 +477,9 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
case 5:
|
||||
return HALAllianceStationID.Blue3;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int kMaxJoystickAxes = 12;
|
||||
public static int kMaxJoystickPOVs = 12;
|
||||
|
||||
Reference in New Issue
Block a user