added joystick and driverstation counts for POV, buttons, and axis

This commit is contained in:
PetaroMitaro
2014-12-05 15:40:54 -05:00
parent 52408e2658
commit 4f6fa2482b
2 changed files with 67 additions and 0 deletions

View File

@@ -204,6 +204,20 @@ public class DriverStation implements RobotState.Interface {
}
}
/**
* Returns the number of axis on a given joystick port
*
* @param stick The joystick port number
*/
public int getStickAxisCount(int stick){
if(stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
}
return FRCNetworkCommunicationsLibrary.HALGetJoystickAxes((byte)stick).length;
}
/**
* Get the state of a POV on the joystick.
*
@@ -228,6 +242,20 @@ public class DriverStation implements RobotState.Interface {
return joystickPOVs[pov];
}
/**
* Returns the number of POVs on a given joystick port
*
* @param stick The joystick port number
*/
public int getStickPOVCount(int stick){
if(stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
}
return FRCNetworkCommunicationsLibrary.HALGetJoystickPOVs((byte)stick).length;
}
/**
* The state of the buttons on the joystick.
* 12 buttons (4 msb are unused) from the joystick.
@@ -251,6 +279,24 @@ public class DriverStation implements RobotState.Interface {
return ((0x1 << (button - 1)) & buttons) != 0;
}
/**
* Gets the number of buttons on a joystick
*
* @param stick the joystick port number
*/
public int getStickButtonCount(int stick){
if(stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
}
ByteBuffer countBuffer = ByteBuffer.allocateDirect(1);
int buttons = FRCNetworkCommunicationsLibrary.HALGetJoystickButtons((byte)stick, countBuffer);
byte count = countBuffer.get();
return count;
}
/**
* Gets a value indicating whether the Driver Station requires the
* robot to be enabled.

View File

@@ -262,6 +262,13 @@ public class Joystick extends GenericHID {
}
}
/**
* For the current joystick, return the number of axis
*/
public int getAxisCount(){
return m_ds.getStickAxisCount(m_port);
}
/**
* Read the state of the trigger on the joystick.
*
@@ -310,6 +317,13 @@ public class Joystick extends GenericHID {
return m_ds.getStickButton(m_port, (byte)button);
}
/**
* For the current joystick, return the number of buttons
*/
public int getButtonCount(){
return m_ds.getStickButtonCount(m_port);
}
/**
* Get the state of a POV on the joystick.
*
@@ -319,6 +333,13 @@ public class Joystick extends GenericHID {
return m_ds.getStickPOV(m_port, pov);
}
/**
* For the current joystick, return the number of POVs
*/
public int getPOVCount(){
return m_ds.getStickPOVCount(m_port);
}
/**
* Get buttons based on an enumerated type.
*