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.