![]() |
WPILibC++ 2027.0.0-alpha-4
|
Handle input from standard HID devices connected to the Driver Station. More...
#include <wpi/driverstation/GenericHID.hpp>
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 | |
| GenericHID & | operator= (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. | |
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.
USB HID interface type.
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. |
|
explicit |
|
virtualdefault |
|
default |
| 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.
| axis | The axis to read, starting at 0. |
| threshold | The value above which this trigger should return true. |
| loop | the event loop instance to attach the event to. |
| 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.
| axis | The axis to read, starting at 0. |
| threshold | The value below which this trigger should return true. |
| loop | the event loop instance to attach the event to. |
| BooleanEvent wpi::GenericHID::Button | ( | int | button, |
| EventLoop * | loop ) const |
Constructs an event instance around this button's digital signal.
| button | the button index |
| loop | the event loop instance to attach the event to. |
| int wpi::GenericHID::GetAxesAvailable | ( | ) | const |
Get the number of axes for the HID.
| int wpi::GenericHID::GetAxesMaximumIndex | ( | ) | const |
| uint64_t wpi::GenericHID::GetButtonsAvailable | ( | ) | const |
Get the number of buttons for the HID.
| int wpi::GenericHID::GetButtonsMaximumIndex | ( | ) | const |
| GenericHID::HIDType wpi::GenericHID::GetGamepadType | ( | ) | const |
Get the type of the HID.
| std::string wpi::GenericHID::GetName | ( | ) | const |
Get the name of the HID.
| int wpi::GenericHID::GetPort | ( | ) | const |
Get the port number of the HID.
| DriverStation::POVDirection wpi::GenericHID::GetPOV | ( | int | pov = 0 | ) | const |
Get the angle of a POV on the HID.
| pov | The index of the POV to read (starting at 0) |
| int wpi::GenericHID::GetPOVsAvailable | ( | ) | const |
Get the number of POVs for the HID.
| int wpi::GenericHID::GetPOVsMaximumIndex | ( | ) | const |
| double wpi::GenericHID::GetRawAxis | ( | int | axis | ) | const |
Get the value of the axis.
| axis | The axis to read, starting at 0. |
| 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.
| button | The button number to be read (starting at 1) |
| 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.
| button | The button index, beginning at 0. |
| 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.
| button | The button index, beginning at 0. |
| GenericHID::SupportedOutputs wpi::GenericHID::GetSupportedOutputs | ( | ) | const |
Get the supported outputs of the HID.
| DriverStation::TouchpadFinger wpi::GenericHID::GetTouchpadFinger | ( | int | touchpad, |
| int | finger ) const |
Get the touchpad finger data.
| touchpad | The touchpad to read. |
| finger | The finger to read. |
| bool wpi::GenericHID::GetTouchpadFingerAvailable | ( | int | touchpad, |
| int | finger ) const |
Check if a touchpad finger is available.
| touchpad | The touchpad to check. |
| finger | The finger to check. |
| bool wpi::GenericHID::IsConnected | ( | ) | const |
Get if the HID is connected.
|
default |
| BooleanEvent wpi::GenericHID::POV | ( | DriverStation::POVDirection | angle, |
| EventLoop * | loop ) const |
Constructs a BooleanEvent instance based around this angle of a POV on the HID.
| loop | the event loop instance to attach the event to. |
| angle | POV angle. |
| 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.
| loop | the event loop instance to attach the event to. |
| pov | index of the POV to read (starting at 0). Defaults to 0. |
| angle | POV angle. |
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| r | Red value from 0-255 |
| g | Green value from 0-255 |
| b | Blue value from 0-255 |
| 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.
| type | Which rumble value to set |
| value | The normalized value (0 to 1) to set the rumble to |