WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::GenericHID Class Reference

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

#include <wpi/driverstation/GenericHID.hpp>

Inheritance diagram for wpi::GenericHID:
wpi::Gamepad wpi::Joystick wpi::NiDsPS4Controller wpi::NiDsPS5Controller wpi::NiDsStadiaController wpi::NiDsXboxController

Public Types

enum  RumbleType { kLeftRumble , kRightRumble , kLeftTriggerRumble , kRightTriggerRumble }
 Represents a rumble output on the Joystick. More...
enum  SupportedOutputs {
  kNone = 0x0 , kMonoLed = 0x1 , kRgbLed = 0x2 , kPlayerLed = 0x4 ,
  kRumble = 0x8 , kTriggerRumble = 0x10
}
 Represents the various outputs that a HID may support. More...
enum  HIDType {
  kUnknown = 0 , kStandard , kXbox360 , kXboxOne ,
  kPS3 , kPS4 , kPS5 , kSwitchPro ,
  kSwitchJoyconLeft , kSwitchJoyconRight , kSwitchJoyconPair
}
 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).
bool GetRawButtonPressed (int button)
 Whether the button was pressed since the last check.
bool GetRawButtonReleased (int button)
 Whether the button was released since the last check.
BooleanEvent Button (int button, EventLoop *loop) const
 Constructs an event instance around this button's digital signal.
double GetRawAxis (int axis) const
 Get the value of the axis.
DriverStation::POVDirection GetPOV (int pov=0) const
 Get the angle of a POV on the HID.
BooleanEvent POV (DriverStation::POVDirection angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID.
BooleanEvent POV (int pov, DriverStation::POVDirection angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID.
BooleanEvent POVUp (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up direction of the default (index 0) POV on the HID.
BooleanEvent POVUpRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up right direction of the default (index 0) POV on the HID.
BooleanEvent POVRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the right direction of the default (index 0) POV on the HID.
BooleanEvent POVDownRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down right direction of the default (index 0) POV on the HID.
BooleanEvent POVDown (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down direction of the default (index 0) POV on the HID.
BooleanEvent POVDownLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down left direction of the default (index 0) POV on the HID.
BooleanEvent POVLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the left direction of the default (index 0) POV on the HID.
BooleanEvent POVUpLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up left direction of the default (index 0) POV on the HID.
BooleanEvent POVCenter (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID.
BooleanEvent AxisLessThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is less than threshold.
BooleanEvent AxisGreaterThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is greater than threshold.
int GetAxesMaximumIndex () const
int GetAxesAvailable () const
 Get the number of axes for the HID.
int GetPOVsMaximumIndex () const
int GetPOVsAvailable () const
 Get the number of POVs for the HID.
int GetButtonsMaximumIndex () const
uint64_t GetButtonsAvailable () const
 Get the number of buttons for the HID.
bool IsConnected () const
 Get if the HID is connected.
GenericHID::HIDType GetGamepadType () const
 Get the type of the HID.
GenericHID::SupportedOutputs GetSupportedOutputs () const
 Get the supported outputs of the HID.
std::string GetName () const
 Get the name of the HID.
int GetPort () const
 Get the port number of the HID.
void SetLeds (int r, int g, int b)
 Set leds on the controller.
void SetRumble (RumbleType type, double value)
 Set the rumble output for the HID.
bool GetTouchpadFingerAvailable (int touchpad, int finger) const
 Check if a touchpad finger is available.
DriverStation::TouchpadFinger GetTouchpadFinger (int touchpad, int finger) const
 Get the touchpad finger data.

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.

kStandard 

Standard HID device.

kXbox360 

Xbox 360 controller.

kXboxOne 

Xbox One controller.

kPS3 

PS3 controller.

kPS4 

PS4 controller.

kPS5 

PS5 controller.

kSwitchPro 

Nintendo Switch Pro controller.

kSwitchJoyconLeft 

Nintendo Switch Joycon Left controller.

kSwitchJoyconRight 

Nintendo Switch Joycon Right controller.

kSwitchJoyconPair 

Nintendo Switch Joycon controller pair.

◆ RumbleType

Represents a rumble output on the Joystick.

Enumerator
kLeftRumble 

Left rumble motor.

kRightRumble 

Right rumble motor.

kLeftTriggerRumble 

Left trigger rumble motor.

kRightTriggerRumble 

Right trigger rumble motor.

◆ SupportedOutputs

Represents the various outputs that a HID may support.

Enumerator
kNone 

No outputs supported.

kMonoLed 

Mono LED support.

kRgbLed 

RGB LED support.

kPlayerLed 

Player LED support.

kRumble 

Rumble support.

kTriggerRumble 

Trigger rumble support.

Constructor & Destructor Documentation

◆ GenericHID() [1/2]

wpi::GenericHID::GenericHID ( int port)
explicit

◆ ~GenericHID()

virtual wpi::GenericHID::~GenericHID ( )
virtualdefault

◆ GenericHID() [2/2]

wpi::GenericHID::GenericHID ( GenericHID && )
default

Member Function Documentation

◆ AxisGreaterThan()

BooleanEvent wpi::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 wpi::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 wpi::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.

◆ GetAxesAvailable()

int wpi::GenericHID::GetAxesAvailable ( ) const

Get the number of axes for the HID.

Returns
the number of axis for the current HID

◆ GetAxesMaximumIndex()

int wpi::GenericHID::GetAxesMaximumIndex ( ) const

◆ GetButtonsAvailable()

uint64_t wpi::GenericHID::GetButtonsAvailable ( ) const

Get the number of buttons for the HID.

Returns
the number of buttons on the current HID

◆ GetButtonsMaximumIndex()

int wpi::GenericHID::GetButtonsMaximumIndex ( ) const

◆ GetGamepadType()

GenericHID::HIDType wpi::GenericHID::GetGamepadType ( ) const

Get the type of the HID.

Returns
the type of the HID.

◆ GetName()

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

Get the name of the HID.

Returns
the name of the HID.

◆ GetPort()

int wpi::GenericHID::GetPort ( ) const

Get the port number of the HID.

Returns
The port number of the HID.

◆ GetPOV()

DriverStation::POVDirection wpi::GenericHID::GetPOV ( int pov = 0) const

Get the angle of a POV on the HID.

Parameters
povThe index of the POV to read (starting at 0)
Returns
the angle of the POV.

◆ GetPOVsAvailable()

int wpi::GenericHID::GetPOVsAvailable ( ) const

Get the number of POVs for the HID.

Returns
the number of POVs for the current HID

◆ GetPOVsMaximumIndex()

int wpi::GenericHID::GetPOVsMaximumIndex ( ) const

◆ GetRawAxis()

double wpi::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 wpi::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 wpi::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 0.
Returns
Whether the button was pressed since the last check.

◆ GetRawButtonReleased()

bool wpi::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 0.
Returns
Whether the button was released since the last check.

◆ GetSupportedOutputs()

GenericHID::SupportedOutputs wpi::GenericHID::GetSupportedOutputs ( ) const

Get the supported outputs of the HID.

Returns
the supported outputs of the HID.

◆ GetTouchpadFinger()

DriverStation::TouchpadFinger wpi::GenericHID::GetTouchpadFinger ( int touchpad,
int finger ) const

Get the touchpad finger data.

Parameters
touchpadThe touchpad to read.
fingerThe finger to read.
Returns
The touchpad finger data.

◆ GetTouchpadFingerAvailable()

bool wpi::GenericHID::GetTouchpadFingerAvailable ( int touchpad,
int finger ) const

Check if a touchpad finger is available.

Parameters
touchpadThe touchpad to check.
fingerThe finger to check.
Returns
true if the touchpad finger is available.

◆ IsConnected()

bool wpi::GenericHID::IsConnected ( ) const

Get if the HID is connected.

Returns
true if the HID is connected

◆ operator=()

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

◆ POV() [1/2]

BooleanEvent wpi::GenericHID::POV ( DriverStation::POVDirection angle,
EventLoop * loop ) const

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

Parameters
loopthe event loop instance to attach the event to.
anglePOV angle.
Returns
a BooleanEvent instance based around this angle of a POV on the HID.

◆ POV() [2/2]

BooleanEvent wpi::GenericHID::POV ( int pov,
DriverStation::POVDirection angle,
EventLoop * loop ) const

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

Parameters
loopthe event loop instance to attach the event to.
povindex of the POV to read (starting at 0). Defaults to 0.
anglePOV angle.
Returns
a BooleanEvent instance based around this angle of a POV on the HID.

◆ POVCenter()

BooleanEvent wpi::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 wpi::GenericHID::POVDown ( EventLoop * loop) const

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

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

◆ POVDownLeft()

BooleanEvent wpi::GenericHID::POVDownLeft ( EventLoop * loop) const

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

Returns
a BooleanEvent instance based around the down left direction of a POV on the HID.

◆ POVDownRight()

BooleanEvent wpi::GenericHID::POVDownRight ( EventLoop * loop) const

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

Returns
a BooleanEvent instance based around the down right direction of a POV on the HID.

◆ POVLeft()

BooleanEvent wpi::GenericHID::POVLeft ( EventLoop * loop) const

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

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

◆ POVRight()

BooleanEvent wpi::GenericHID::POVRight ( EventLoop * loop) const

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

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

◆ POVUp()

BooleanEvent wpi::GenericHID::POVUp ( EventLoop * loop) const

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

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

◆ POVUpLeft()

BooleanEvent wpi::GenericHID::POVUpLeft ( EventLoop * loop) const

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

Returns
a BooleanEvent instance based around the up left direction of a POV on the HID.

◆ POVUpRight()

BooleanEvent wpi::GenericHID::POVUpRight ( EventLoop * loop) const

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

Returns
a BooleanEvent instance based around the up right direction of a POV on the HID.

◆ SetLeds()

void wpi::GenericHID::SetLeds ( int r,
int g,
int b )

Set leds on the controller.

If only mono is supported, the system will use the highest value passed in.

Parameters
rRed value from 0-255
gGreen value from 0-255
bBlue value from 0-255

◆ SetRumble()

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

Set the rumble output for the HID.

The DS currently supports 4 rumble values: left rumble, right rumble, left trigger rumble, and right trigger 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: