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:
Thomas Clark
2014-10-17 14:46:25 -04:00
parent 08c8723174
commit 8a541a67ca
16 changed files with 199 additions and 74 deletions

View File

@@ -22,7 +22,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)
@@ -38,17 +38,17 @@ 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;
}
/**
* 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.
@@ -71,7 +71,7 @@ void Joystick::InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes)
joySticksInitialized = true;
}
joysticks[m_port - 1] = this;
m_ds = DriverStation::GetInstance();
m_axes = new uint32_t[numAxisTypes];
m_buttons = new uint32_t[numButtonTypes];
@@ -141,7 +141,7 @@ float Joystick::GetThrottle()
/**
* Get the value of the axis.
*
*
* @param axis The axis to read [1-6].
* @return The value of the axis.
*/
@@ -152,10 +152,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.
*/
@@ -176,9 +176,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.
*/
@@ -189,9 +189,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.
*/
@@ -212,10 +212,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.
**/
@@ -224,11 +224,20 @@ bool Joystick::GetRawButton(uint32_t button)
return m_ds->GetStickButton(m_port, button);
}
/**
* 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 0; // TODO
}
/**
* 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.
*/
@@ -245,7 +254,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.
*/
@@ -256,7 +265,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.
*/
@@ -268,7 +277,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(){
@@ -278,7 +287,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(){
@@ -288,10 +297,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(){