mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21: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:
@@ -23,7 +23,7 @@ static bool joySticksInitialized = false;
|
||||
/**
|
||||
* Construct an instance of a joystick.
|
||||
* The joystick index is the usb port on the drivers station.
|
||||
*
|
||||
*
|
||||
* @param port The port on the driver station that the joystick is plugged into.
|
||||
*/
|
||||
Joystick::Joystick(uint32_t port)
|
||||
@@ -39,7 +39,7 @@ Joystick::Joystick(uint32_t port)
|
||||
m_axes[kZAxis] = kDefaultZAxis;
|
||||
m_axes[kTwistAxis] = kDefaultTwistAxis;
|
||||
m_axes[kThrottleAxis] = kDefaultThrottleAxis;
|
||||
|
||||
|
||||
m_buttons[kTriggerButton] = kDefaultTriggerButton;
|
||||
m_buttons[kTopButton] = kDefaultTopButton;
|
||||
|
||||
@@ -48,10 +48,10 @@ Joystick::Joystick(uint32_t port)
|
||||
|
||||
/**
|
||||
* Version of the constructor to be called by sub-classes.
|
||||
*
|
||||
*
|
||||
* This constructor allows the subclass to configure the number of constants
|
||||
* for axes and buttons.
|
||||
*
|
||||
*
|
||||
* @param port The port on the driver station that the joystick is plugged into.
|
||||
* @param numAxisTypes The number of axis types in the enum.
|
||||
* @param numButtonTypes The number of button types in the enum.
|
||||
@@ -148,7 +148,7 @@ float Joystick::GetThrottle()
|
||||
|
||||
/**
|
||||
* Get the value of the axis.
|
||||
*
|
||||
*
|
||||
* @param axis The axis to read [1-6].
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
@@ -159,10 +159,10 @@ float Joystick::GetRawAxis(uint32_t axis)
|
||||
|
||||
/**
|
||||
* For the current joystick, return the axis determined by the argument.
|
||||
*
|
||||
*
|
||||
* This is for cases where the joystick axis is returned programatically, otherwise one of the
|
||||
* previous functions would be preferable (for example GetX()).
|
||||
*
|
||||
*
|
||||
* @param axis The axis to read.
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
@@ -183,9 +183,9 @@ float Joystick::GetAxis(AxisType axis)
|
||||
|
||||
/**
|
||||
* Read the state of the trigger on the joystick.
|
||||
*
|
||||
*
|
||||
* Look up which button has been assigned to the trigger and read its state.
|
||||
*
|
||||
*
|
||||
* @param hand This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
|
||||
* @return The state of the trigger.
|
||||
*/
|
||||
@@ -196,9 +196,9 @@ bool Joystick::GetTrigger(JoystickHand hand)
|
||||
|
||||
/**
|
||||
* Read the state of the top button on the joystick.
|
||||
*
|
||||
*
|
||||
* Look up which button has been assigned to the top and read its state.
|
||||
*
|
||||
*
|
||||
* @param hand This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
|
||||
* @return The state of the top button.
|
||||
*/
|
||||
@@ -219,10 +219,10 @@ bool Joystick::GetBumper(JoystickHand hand)
|
||||
|
||||
/**
|
||||
* Get the button value for buttons 1 through 12.
|
||||
*
|
||||
*
|
||||
* The buttons are returned in a single 16 bit value with one bit representing the state
|
||||
* of each button. The appropriate button is returned as a boolean value.
|
||||
*
|
||||
* of each button. The appropriate button is returned as a boolean value.
|
||||
*
|
||||
* @param button The button number to be read.
|
||||
* @return The state of the button.
|
||||
**/
|
||||
@@ -231,11 +231,20 @@ bool Joystick::GetRawButton(uint32_t button)
|
||||
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.
|
||||
*/
|
||||
int Joystick::GetPOV(uint32_t pov) {
|
||||
return m_ds->GetStickPOV(m_port, pov);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buttons based on an enumerated type.
|
||||
*
|
||||
*
|
||||
* The button type will be looked up in the list of buttons and then read.
|
||||
*
|
||||
*
|
||||
* @param button The type of button to read.
|
||||
* @return The state of the button.
|
||||
*/
|
||||
@@ -252,7 +261,7 @@ bool Joystick::GetButton(ButtonType button)
|
||||
|
||||
/**
|
||||
* Get the channel currently associated with the specified axis.
|
||||
*
|
||||
*
|
||||
* @param axis The axis to look up the channel for.
|
||||
* @return The channel fr the axis.
|
||||
*/
|
||||
@@ -263,7 +272,7 @@ uint32_t Joystick::GetAxisChannel(AxisType axis)
|
||||
|
||||
/**
|
||||
* Set the channel associated with a specified axis.
|
||||
*
|
||||
*
|
||||
* @param axis The axis to set the channel for.
|
||||
* @param channel The channel to set the axis to.
|
||||
*/
|
||||
@@ -275,7 +284,7 @@ void Joystick::SetAxisChannel(AxisType axis, uint32_t channel)
|
||||
/**
|
||||
* Get the magnitude of the direction vector formed by the joystick's
|
||||
* current position relative to its origin
|
||||
*
|
||||
*
|
||||
* @return The magnitude of the direction vector
|
||||
*/
|
||||
float Joystick::GetMagnitude(){
|
||||
@@ -285,7 +294,7 @@ float Joystick::GetMagnitude(){
|
||||
/**
|
||||
* Get the direction of the vector formed by the joystick and its origin
|
||||
* in radians
|
||||
*
|
||||
*
|
||||
* @return The direction of the vector in radians
|
||||
*/
|
||||
float Joystick::GetDirectionRadians(){
|
||||
@@ -295,10 +304,10 @@ float Joystick::GetDirectionRadians(){
|
||||
/**
|
||||
* Get the direction of the vector formed by the joystick and its origin
|
||||
* in degrees
|
||||
*
|
||||
* uses acos(-1) to represent Pi due to absence of readily accessable Pi
|
||||
*
|
||||
* uses acos(-1) to represent Pi due to absence of readily accessable Pi
|
||||
* constant in C++
|
||||
*
|
||||
*
|
||||
* @return The direction of the vector in degrees
|
||||
*/
|
||||
float Joystick::GetDirectionDegrees(){
|
||||
|
||||
Reference in New Issue
Block a user