mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add new joystick features
Axis counts other than six and POVs are both present in C++ and Java now Add dynamic joystick axis counts, up to 12 Change-Id: Ieade5e61a89df822df8702cb32326e4635558778 Add support for POVs in C++ Change-Id: I12dc0fcaca605a256ddcf990eebde45767229171 Make POVs work in Java Change-Id: Ie2d98adb416c1930f058bdd21c3e7d26289df503
This commit is contained in:
@@ -30,10 +30,6 @@ public class DriverStation implements RobotState.Interface {
|
||||
* Number of Joystick Ports
|
||||
*/
|
||||
public static final int kJoystickPorts = 4;
|
||||
/**
|
||||
* Number of Joystick Axes
|
||||
*/
|
||||
public static final int kJoystickAxes = 6;
|
||||
/**
|
||||
* Convert from raw values to volts
|
||||
*/
|
||||
@@ -61,7 +57,8 @@ public class DriverStation implements RobotState.Interface {
|
||||
|
||||
private HALControlWord m_controlWord;
|
||||
private HALAllianceStationID m_allianceStationID;
|
||||
private short[][] m_joystickAxes = new short[kJoystickAxes][kJoystickPorts];
|
||||
private short[][] m_joystickAxes = new short[FRCNetworkCommunicationsLibrary.kMaxJoystickAxes][kJoystickPorts];
|
||||
private short[][] m_joystickPOVs = new short[FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs][kJoystickPorts];
|
||||
private int[] m_joystickButtons = new int[kJoystickPorts];
|
||||
|
||||
private Thread m_thread;
|
||||
@@ -185,6 +182,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
for(byte stick = 0; stick < kJoystickPorts; stick++) {
|
||||
m_joystickButtons[stick] = FRCNetworkCommunicationsLibrary.HALGetJoystickButtons(stick);
|
||||
m_joystickAxes[stick] = FRCNetworkCommunicationsLibrary.HALGetJoystickAxes(stick);
|
||||
m_joystickPOVs[stick] = FRCNetworkCommunicationsLibrary.HALGetJoystickPOVs(stick);
|
||||
}
|
||||
|
||||
if (!lastEnabled && isEnabled()) {
|
||||
@@ -228,7 +226,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
|
||||
if (axis < 1 || axis > kJoystickAxes) {
|
||||
if (axis < 1 || axis > m_joystickAxes[stick].length) {
|
||||
throw new RuntimeException("Joystick axis is out of range");
|
||||
}
|
||||
|
||||
@@ -241,6 +239,23 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of a POV on the joystick.
|
||||
*
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
if (pov < 1 || pov > m_joystickPOVs[stick].length) {
|
||||
throw new RuntimeException("Joystick POV is out of range");
|
||||
}
|
||||
|
||||
return m_joystickPOVs[stick][pov - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* The state of the buttons on the joystick.
|
||||
* 12 buttons (4 msb are unused) from the joystick.
|
||||
|
||||
@@ -279,6 +279,15 @@ public class Joystick extends GenericHID {
|
||||
return ((0x1 << (button - 1)) & m_ds.getStickButtons(m_port)) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of a POV on the joystick.
|
||||
*
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
*/
|
||||
public int getPOV(int pov) {
|
||||
return m_ds.getStickPOV(m_port, pov - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buttons based on an enumerated type.
|
||||
*
|
||||
|
||||
@@ -463,7 +463,10 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
case 2:
|
||||
return HALAllianceStationID.Red3;
|
||||
case 3:
|
||||
return HALAllianceStationID.Blue1;
|
||||
case 4:
|
||||
return HALAllianceStationID.Blue2;
|
||||
case 5:
|
||||
return HALAllianceStationID.Blue3;
|
||||
default:
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user