mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Merge "Implement Joystick Outputs and Rumble (fixes artf3807)"
This commit is contained in:
@@ -182,6 +182,16 @@ struct HALJoystickButtons {
|
||||
uint8_t count;
|
||||
};
|
||||
|
||||
struct HALJoystickDescriptor {
|
||||
uint8_t isXbox;
|
||||
uint8_t type;
|
||||
char name[256];
|
||||
uint8_t axisCount;
|
||||
uint8_t axisTypes;
|
||||
uint8_t buttonCount;
|
||||
uint8_t povCount;
|
||||
};
|
||||
|
||||
inline float intToFloat(int value)
|
||||
{
|
||||
return (float)value;
|
||||
@@ -216,6 +226,8 @@ extern "C"
|
||||
int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes *axes);
|
||||
int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs *povs);
|
||||
int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons);
|
||||
int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor *desc);
|
||||
int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs, uint16_t leftRumble, uint16_t rightRumble);
|
||||
int HALGetMatchTime(float *matchTime);
|
||||
|
||||
void HALSetNewDataSem(pthread_cond_t *);
|
||||
|
||||
@@ -207,6 +207,17 @@ int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons)
|
||||
return FRC_NetworkCommunication_getJoystickButtons(joystickNum, &buttons->buttons, &buttons->count);
|
||||
}
|
||||
|
||||
int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor *desc)
|
||||
{
|
||||
return FRC_NetworkCommunication_getJoystickDesc(joystickNum, &desc->isXbox, &desc->type, (char *)(&desc->name),
|
||||
&desc->axisCount, &desc->axisTypes, &desc->buttonCount, &desc->povCount);
|
||||
}
|
||||
|
||||
int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs, uint16_t leftRumble, uint16_t rightRumble)
|
||||
{
|
||||
return FRC_NetworkCommunication_setJoystickOutputs(joystickNum, outputs, leftRumble, rightRumble);
|
||||
}
|
||||
|
||||
int HALGetMatchTime(float *matchTime)
|
||||
{
|
||||
return FRC_NetworkCommunication_getMatchTime(matchTime);
|
||||
|
||||
@@ -37,6 +37,10 @@ public:
|
||||
{
|
||||
kTriggerButton, kTopButton, kNumButtonTypes
|
||||
} ButtonType;
|
||||
typedef enum
|
||||
{
|
||||
kLeftRumble, kRightRumble
|
||||
} RumbleType;
|
||||
|
||||
explicit Joystick(uint32_t port);
|
||||
Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes);
|
||||
@@ -64,6 +68,10 @@ public:
|
||||
virtual float GetMagnitude();
|
||||
virtual float GetDirectionRadians();
|
||||
virtual float GetDirectionDegrees();
|
||||
|
||||
void SetRumble(RumbleType type, float value);
|
||||
void SetOutput(uint8_t outputNumber, bool value);
|
||||
void SetOutputs(uint32_t value);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Joystick);
|
||||
@@ -73,6 +81,9 @@ private:
|
||||
uint32_t m_port;
|
||||
uint32_t *m_axes;
|
||||
uint32_t *m_buttons;
|
||||
uint32_t m_outputs;
|
||||
uint16_t m_leftRumble;
|
||||
uint16_t m_rightRumble;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,9 @@ Joystick::Joystick(uint32_t port)
|
||||
, m_port (port)
|
||||
, m_axes (NULL)
|
||||
, m_buttons (NULL)
|
||||
, m_outputs (0)
|
||||
, m_leftRumble (0)
|
||||
, m_rightRumble (0)
|
||||
{
|
||||
InitJoystick(kNumAxisTypes, kNumButtonTypes);
|
||||
|
||||
@@ -305,7 +308,7 @@ 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 accessible Pi
|
||||
* constant in C++
|
||||
*
|
||||
* @return The direction of the vector in degrees
|
||||
@@ -313,3 +316,38 @@ float Joystick::GetDirectionRadians(){
|
||||
float Joystick::GetDirectionDegrees(){
|
||||
return (180/acos(-1))*GetDirectionRadians();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the joystick. The DS currently supports 2 rumble values,
|
||||
* left rumble and right rumble
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
void Joystick::SetRumble(RumbleType type, float value) {
|
||||
if (type == kLeftRumble)
|
||||
m_leftRumble = value*65535;
|
||||
else
|
||||
m_rightRumble = value*65535;
|
||||
HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single HID output value for the joystick.
|
||||
* @param outputNumber The index of the output to set (1-32)
|
||||
* @param value The value to set the output to
|
||||
*/
|
||||
|
||||
void Joystick::SetOutput(uint8_t outputNumber, bool value) {
|
||||
m_outputs = (m_outputs & ~(1 << (outputNumber-1))) | (value << (outputNumber-1));
|
||||
|
||||
HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all HID output values for the joystick.
|
||||
* @param value The 32 bit output value (1 bit for each output)
|
||||
*/
|
||||
void Joystick::SetOutputs(uint32_t value) {
|
||||
m_outputs = value;
|
||||
HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
|
||||
/**
|
||||
@@ -99,10 +100,40 @@ public class Joystick extends GenericHID {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a rumble output on the JoyStick
|
||||
*/
|
||||
public static class RumbleType {
|
||||
|
||||
/**
|
||||
* The integer value representing this enumeration
|
||||
*/
|
||||
public final int value;
|
||||
static final int kLeftRumble_val = 0;
|
||||
static final int kRightRumble_val = 1;
|
||||
/**
|
||||
* Left Rumble
|
||||
*/
|
||||
public static final RumbleType kLeftRumble = new RumbleType((kLeftRumble_val));
|
||||
/**
|
||||
* Right Rumble
|
||||
*/
|
||||
public static final RumbleType kRightRumble = new RumbleType(kRightRumble_val);
|
||||
|
||||
private RumbleType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private DriverStation m_ds;
|
||||
private final int m_port;
|
||||
private final byte[] m_axes;
|
||||
private final byte[] m_buttons;
|
||||
private int m_outputs;
|
||||
private short m_leftRumble;
|
||||
private short m_rightRumble;
|
||||
|
||||
/**
|
||||
* Construct an instance of a joystick.
|
||||
@@ -359,4 +390,38 @@ public class Joystick extends GenericHID {
|
||||
public void setAxisChannel(AxisType axis, int channel) {
|
||||
m_axes[axis.value] = (byte) channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rumble output for the joystick. The DS currently supports 2 rumble values,
|
||||
* left rumble and right rumble
|
||||
* @param type Which rumble value to set
|
||||
* @param value The normalized value (0 to 1) to set the rumble to
|
||||
*/
|
||||
public void setRumble(RumbleType type, float value) {
|
||||
if (type.value == RumbleType.kLeftRumble_val)
|
||||
m_leftRumble = (short)(value*65535);
|
||||
else
|
||||
m_rightRumble = (short)(value*65535);
|
||||
FRCNetworkCommunicationsLibrary.HALSetJoystickOutputs((byte)m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single HID output value for the joystick.
|
||||
* @param outputNumber The index of the output to set (1-32)
|
||||
* @param value The value to set the output to
|
||||
*/
|
||||
|
||||
public void setOutput(int outputNumber, boolean value) {
|
||||
m_outputs = (m_outputs & ~(1 << (outputNumber-1))) | ((value?1:0) << (outputNumber-1));
|
||||
FRCNetworkCommunicationsLibrary.HALSetJoystickOutputs((byte)m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all HID output values for the joystick.
|
||||
* @param value The 32 bit output value (1 bit for each output)
|
||||
*/
|
||||
public void setOutputs(int value) {
|
||||
m_outputs = value;
|
||||
FRCNetworkCommunicationsLibrary.HALSetJoystickOutputs((byte)m_port, m_outputs, m_leftRumble, m_rightRumble);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,6 +468,7 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
return HALAllianceStationID.Blue2;
|
||||
case 5:
|
||||
return HALAllianceStationID.Blue3;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +341,20 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommun
|
||||
return joystickButtons.buttons;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
|
||||
* Method: HALSetJoystickOutputs
|
||||
* Signature: (BISS)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALSetJoystickOutputs
|
||||
(JNIEnv *, jclass, jbyte port, jint outputs, jshort leftRumble, jshort rightRumble)
|
||||
{
|
||||
NETCOMM_LOG(logDEBUG) << "Calling HALSetJoystickOutputs on port " << port;
|
||||
NETCOMM_LOG(logDEBUG) << "Outputs: " << outputs;
|
||||
NETCOMM_LOG(logDEBUG) << "Left Rumble: " << leftRumble << " Right Rumble: " << rightRumble;
|
||||
return HALSetJoystickOutputs(port, outputs, leftRumble, rightRumble);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
|
||||
* Method: setNewDataSem
|
||||
|
||||
Reference in New Issue
Block a user