WPILibC++ 2023.4.3
|
Handle input from standard HID devices connected to the Driver Station. More...
#include <frc/GenericHID.h>
Public Types | |
enum | RumbleType { kLeftRumble , kRightRumble , kBothRumble } |
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 } |
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). 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... | |
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.
|
explicit |
|
virtualdefault |
|
default |
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.
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 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.
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 frc::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 frc::GenericHID::GetAxisCount | ( | ) | const |
Get the number of axes for the HID.
int frc::GenericHID::GetAxisType | ( | int | axis | ) | const |
Get the axis type of a joystick axis.
int frc::GenericHID::GetButtonCount | ( | ) | const |
Get the number of buttons for the HID.
std::string frc::GenericHID::GetName | ( | ) | const |
Get the name of the HID.
int frc::GenericHID::GetPort | ( | ) | const |
Get the port number of the HID.
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).
pov | The index of the POV to read (starting at 0) |
int frc::GenericHID::GetPOVCount | ( | ) | const |
Get the number of POVs for the HID.
double frc::GenericHID::GetRawAxis | ( | int | axis | ) | const |
Get the value of the axis.
axis | The axis to read, starting at 0. |
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.
button | The button number to be read (starting at 1) |
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.
button | The button index, beginning at 1. |
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.
button | The button index, beginning at 1. |
GenericHID::HIDType frc::GenericHID::GetType | ( | ) | const |
Get the type of the HID.
bool frc::GenericHID::IsConnected | ( | ) | const |
Get if the HID is connected.
|
default |
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).
loop | the event loop instance to attach the event to. |
angle | POV angle in degrees, or -1 for the center / not pressed. |
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).
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 in degrees, or -1 for the center / not pressed. |
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.
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.
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.
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.
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.
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.
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.
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.
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.
void frc::GenericHID::SetOutput | ( | int | outputNumber, |
bool | value | ||
) |
Set a single HID output value for the HID.
outputNumber | The index of the output to set (1-32) |
value | The value to set the output to |
void frc::GenericHID::SetOutputs | ( | int | value | ) |
Set all output values for the HID.
value | The 32 bit output value (1 bit for each output) |
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.
type | Which rumble value to set |
value | The normalized value (0 to 1) to set the rumble to |