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

@@ -24,7 +24,6 @@ TLogLevel dsLogLevel = logDEBUG;
else Log().Get(level)
const uint32_t DriverStation::kJoystickPorts;
const uint32_t DriverStation::kJoystickAxes;
DriverStation* DriverStation::m_instance = NULL;
/**
@@ -46,6 +45,13 @@ DriverStation::DriverStation()
{
memset(&m_controlWord, 0, sizeof(m_controlWord));
// All joysticks should default to having zero axes and povs, so
// uninitialized memory doesn't get sent to speed controllers.
for(unsigned int i = 0; i < kJoystickPorts; i++) {
m_joystickAxes[i].count = 0;
m_joystickPOVs[i].count = 0;
}
// Create a new semaphore
m_packetDataAvailableSem = initializeMutexNormal();
m_newControlData = initializeSemaphore(SEMAPHORE_EMPTY);
@@ -135,7 +141,8 @@ void DriverStation::GetData()
for(uint8_t stick = 0; stick < kJoystickPorts; stick++) {
uint8_t count;
HALGetJoystickAxes(stick, &m_joystickAxes[stick], kJoystickAxes);
HALGetJoystickAxes(stick, &m_joystickAxes[stick]);
HALGetJoystickPOVs(stick, &m_joystickPOVs[stick]);
HALGetJoystickButtons(stick, &m_joystickButtons[stick], &count);
}
@@ -185,7 +192,7 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
return 0;
}
if (axis < 1 || axis > kJoystickAxes)
if (axis < 1 || axis > m_joystickAxes[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
return 0.0f;
@@ -203,6 +210,27 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
}
}
/**
* 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 DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
if (stick >= kJoystickPorts)
{
wpi_setWPIError(BadJoystickIndex);
return 0;
}
if (pov < 1 || pov > m_joystickPOVs[stick].count)
{
wpi_setWPIError(BadJoystickAxis);
return 0;
}
return m_joystickPOVs[stick].povs[pov - 1];
}
/**
* The state of the buttons on the joystick.
* 12 buttons (4 msb are unused) from the joystick.

View File

@@ -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(){