WPILibC++ 2024.3.2
frc::GenericHID Class Reference

Handle input from standard HID devices connected to the Driver Station. More...

#include <frc/GenericHID.h>

Inheritance diagram for frc::GenericHID:
frc2::CommandGenericHID frc::Joystick frc::PS4Controller frc::PS5Controller frc::StadiaController frc::XboxController frc2::CommandJoystick frc2::CommandPS4Controller frc2::CommandPS5Controller frc2::CommandStadiaController frc2::CommandXboxController

Public Types

enum  RumbleType { kLeftRumble , kRightRumble , kBothRumble }
 Represents a rumble output on the Joystick. More...
 
enum  HIDType {
  kUnknown = -1 , kXInputUnknown = 0 , kXInputGamepad = 1 , kXInputWheel = 2 ,
  kXInputArcadeStick = 3 , kXInputFlightStick = 4 , kXInputDancePad = 5 , kXInputGuitar = 6 ,
  kXInputGuitar2 = 7 , kXInputDrumKit = 8 , kXInputGuitar3 = 11 , kXInputArcadePad = 19 ,
  kHIDJoystick = 20 , kHIDGamepad = 21 , kHIDDriving = 22 , kHIDFlight = 23 ,
  kHID1stPerson = 24
}
 USB HID interface type. More...
 

Public Member Functions

 GenericHID (int port)
 
virtual ~GenericHID ()=default
 
 GenericHID (GenericHID &&)=default
 
GenericHIDoperator= (GenericHID &&)=default
 
bool GetRawButton (int button) const
 Get the button value (starting at button 1). More...
 
bool GetRawButtonPressed (int button)
 Whether the button was pressed since the last check. More...
 
bool GetRawButtonReleased (int button)
 Whether the button was released since the last check. More...
 
BooleanEvent Button (int button, EventLoop *loop) const
 Constructs an event instance around this button's digital signal. More...
 
double GetRawAxis (int axis) const
 Get the value of the axis. More...
 
int GetPOV (int pov=0) const
 Get the angle in degrees of a POV on the HID. More...
 
BooleanEvent POV (int angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID. More...
 
BooleanEvent POV (int pov, int angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID. More...
 
BooleanEvent POVUp (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 0 degree angle (up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVUpRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 45 degree angle (right up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 90 degree angle (right) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDownRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 135 degree angle (right down) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDown (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 180 degree angle (down) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVDownLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 225 degree angle (down left) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 270 degree angle (left) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVUpLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the 315 degree angle (left up) of the default (index 0) POV on the HID. More...
 
BooleanEvent POVCenter (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID. More...
 
BooleanEvent AxisLessThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is less than threshold. More...
 
BooleanEvent AxisGreaterThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is greater than threshold. More...
 
int GetAxisCount () const
 Get the number of axes for the HID. More...
 
int GetPOVCount () const
 Get the number of POVs for the HID. More...
 
int GetButtonCount () const
 Get the number of buttons for the HID. More...
 
bool IsConnected () const
 Get if the HID is connected. More...
 
GenericHID::HIDType GetType () const
 Get the type of the HID. More...
 
std::string GetName () const
 Get the name of the HID. More...
 
int GetAxisType (int axis) const
 Get the axis type of a joystick axis. More...
 
int GetPort () const
 Get the port number of the HID. More...
 
void SetOutput (int outputNumber, bool value)
 Set a single HID output value for the HID. More...
 
void SetOutputs (int value)
 Set all output values for the HID. More...
 
void SetRumble (RumbleType type, double value)
 Set the rumble output for the HID. More...
 

Detailed Description

Handle input from standard HID devices connected to the Driver Station.

This class handles standard input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each device and the mapping of ports to hardware buttons depends on the code in the Driver Station.

Member Enumeration Documentation

◆ HIDType

USB HID interface type.

Enumerator
kUnknown 

Unknown.

kXInputUnknown 

XInputUnknown.

kXInputGamepad 

XInputGamepad.

kXInputWheel 

XInputWheel.

kXInputArcadeStick 

XInputArcadeStick.

kXInputFlightStick 

XInputFlightStick.

kXInputDancePad 

XInputDancePad.

kXInputGuitar 

XInputGuitar.

kXInputGuitar2 

XInputGuitar2.

kXInputDrumKit 

XInputDrumKit.

kXInputGuitar3 

XInputGuitar3.

kXInputArcadePad 

XInputArcadePad.

kHIDJoystick 

HIDJoystick.

kHIDGamepad 

HIDGamepad.

kHIDDriving 

HIDDriving.

kHIDFlight 

HIDFlight.

kHID1stPerson 

HID1stPerson.

◆ RumbleType

Represents a rumble output on the Joystick.

Enumerator
kLeftRumble 

Left rumble motor.

kRightRumble 

Right rumble motor.

kBothRumble 

Both left and right rumble motors.

Constructor & Destructor Documentation

◆ GenericHID() [1/2]

frc::GenericHID::GenericHID ( int  port)
explicit

◆ ~GenericHID()

virtual frc::GenericHID::~GenericHID ( )
virtualdefault

◆ GenericHID() [2/2]

frc::GenericHID::GenericHID ( GenericHID &&  )
default

Member Function Documentation

◆ AxisGreaterThan()

BooleanEvent frc::GenericHID::AxisGreaterThan ( int  axis,
double  threshold,
EventLoop loop 
) const

Constructs an event instance that is true when the axis value is greater than threshold.

Parameters
axisThe axis to read, starting at 0.
thresholdThe value above which this trigger should return true.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the axis value is greater than the provided threshold.

◆ AxisLessThan()

BooleanEvent frc::GenericHID::AxisLessThan ( int  axis,
double  threshold,
EventLoop loop 
) const

Constructs an event instance that is true when the axis value is less than threshold.

Parameters
axisThe axis to read, starting at 0.
thresholdThe value below which this trigger should return true.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the axis value is less than the provided threshold.

◆ Button()

BooleanEvent frc::GenericHID::Button ( int  button,
EventLoop loop 
) const

Constructs an event instance around this button's digital signal.

Parameters
buttonthe button index
loopthe event loop instance to attach the event to.
Returns
an event instance representing the button's digital signal attached to the given loop.

◆ GetAxisCount()

int frc::GenericHID::GetAxisCount ( ) const

Get the number of axes for the HID.

Returns
the number of axis for the current HID

◆ GetAxisType()

int frc::GenericHID::GetAxisType ( int  axis) const

Get the axis type of a joystick axis.

Returns
the axis type of a joystick axis.

◆ GetButtonCount()

int frc::GenericHID::GetButtonCount ( ) const

Get the number of buttons for the HID.

Returns
the number of buttons on the current HID

◆ GetName()

std::string frc::GenericHID::GetName ( ) const

Get the name of the HID.

Returns
the name of the HID.

◆ GetPort()

int frc::GenericHID::GetPort ( ) const

Get the port number of the HID.

Returns
The port number of the HID.

◆ GetPOV()

int frc::GenericHID::GetPOV ( int  pov = 0) const

Get the angle in degrees of a POV on the HID.

The POV angles start at 0 in the up direction, and increase clockwise (e.g. right is 90, upper-left is 315).

Parameters
povThe index of the POV to read (starting at 0)
Returns
the angle of the POV in degrees, or -1 if the POV is not pressed.

◆ GetPOVCount()

int frc::GenericHID::GetPOVCount ( ) const

Get the number of POVs for the HID.

Returns
the number of POVs for the current HID

◆ GetRawAxis()

double frc::GenericHID::GetRawAxis ( int  axis) const

Get the value of the axis.

Parameters
axisThe axis to read, starting at 0.
Returns
The value of the axis.

◆ GetRawButton()

bool frc::GenericHID::GetRawButton ( int  button) const

Get the button value (starting at button 1).

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.

This method returns true if the button is being held down at the time that this method is being called.

Parameters
buttonThe button number to be read (starting at 1)
Returns
The state of the button.

◆ GetRawButtonPressed()

bool frc::GenericHID::GetRawButtonPressed ( int  button)

Whether the button was pressed since the last check.

Button indexes begin at 1.

This method returns true if the button went from not pressed to held down since the last time this method was called. This is useful if you only want to call a function once when you press the button.

Parameters
buttonThe button index, beginning at 1.
Returns
Whether the button was pressed since the last check.

◆ GetRawButtonReleased()

bool frc::GenericHID::GetRawButtonReleased ( int  button)

Whether the button was released since the last check.

Button indexes begin at 1.

This method returns true if the button went from held down to not pressed since the last time this method was called. This is useful if you only want to call a function once when you release the button.

Parameters
buttonThe button index, beginning at 1.
Returns
Whether the button was released since the last check.

◆ GetType()

GenericHID::HIDType frc::GenericHID::GetType ( ) const

Get the type of the HID.

Returns
the type of the HID.

◆ IsConnected()

bool frc::GenericHID::IsConnected ( ) const

Get if the HID is connected.

Returns
true if the HID is connected

◆ operator=()

GenericHID & frc::GenericHID::operator= ( GenericHID &&  )
default

◆ POV() [1/2]

BooleanEvent frc::GenericHID::POV ( int  angle,
EventLoop loop 
) const

Constructs a BooleanEvent instance based around this angle of a POV on the HID.

The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90, upper-left is 315).

Parameters
loopthe event loop instance to attach the event to.
anglePOV angle in degrees, or -1 for the center / not pressed.
Returns
a BooleanEvent instance based around this angle of a POV on the HID.

◆ POV() [2/2]

BooleanEvent frc::GenericHID::POV ( int  pov,
int  angle,
EventLoop loop 
) const

Constructs a BooleanEvent instance based around this angle of a POV on the HID.

The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90, upper-left is 315).

Parameters
loopthe event loop instance to attach the event to.
povindex of the POV to read (starting at 0). Defaults to 0.
anglePOV angle in degrees, or -1 for the center / not pressed.
Returns
a BooleanEvent instance based around this angle of a POV on the HID.

◆ POVCenter()

BooleanEvent frc::GenericHID::POVCenter ( EventLoop loop) const

Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the center of a POV on the HID.

◆ POVDown()

BooleanEvent frc::GenericHID::POVDown ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 180 degree angle (down) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 180 degree angle of a POV on the HID.

◆ POVDownLeft()

BooleanEvent frc::GenericHID::POVDownLeft ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 225 degree angle (down left) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 225 degree angle of a POV on the HID.

◆ POVDownRight()

BooleanEvent frc::GenericHID::POVDownRight ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 135 degree angle (right down) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 135 degree angle of a POV on the HID.

◆ POVLeft()

BooleanEvent frc::GenericHID::POVLeft ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 270 degree angle (left) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 270 degree angle of a POV on the HID.

◆ POVRight()

BooleanEvent frc::GenericHID::POVRight ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 90 degree angle (right) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 90 degree angle of a POV on the HID.

◆ POVUp()

BooleanEvent frc::GenericHID::POVUp ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 0 degree angle (up) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 0 degree angle of a POV on the HID.

◆ POVUpLeft()

BooleanEvent frc::GenericHID::POVUpLeft ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 315 degree angle (left up) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 315 degree angle of a POV on the HID.

◆ POVUpRight()

BooleanEvent frc::GenericHID::POVUpRight ( EventLoop loop) const

Constructs a BooleanEvent instance based around the 45 degree angle (right up) of the default (index 0) POV on the HID.

Returns
a BooleanEvent instance based around the 45 degree angle of a POV on the HID.

◆ SetOutput()

void frc::GenericHID::SetOutput ( int  outputNumber,
bool  value 
)

Set a single HID output value for the HID.

Parameters
outputNumberThe index of the output to set (1-32)
valueThe value to set the output to

◆ SetOutputs()

void frc::GenericHID::SetOutputs ( int  value)

Set all output values for the HID.

Parameters
valueThe 32 bit output value (1 bit for each output)

◆ SetRumble()

void frc::GenericHID::SetRumble ( RumbleType  type,
double  value 
)

Set the rumble output for the HID.

The DS currently supports 2 rumble values, left rumble and right rumble.

Parameters
typeWhich rumble value to set
valueThe normalized value (0 to 1) to set the rumble to

The documentation for this class was generated from the following file: