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

Handle input from NiDsXbox controllers connected to the Driver Station. More...

#include <wpi/driverstation/NiDsXboxController.hpp>

Inheritance diagram for wpi::NiDsXboxController:
wpi::GenericHID wpi::util::Sendable wpi::util::SendableHelper< NiDsXboxController >

Classes

struct  Button
 Represents a digital button on an NiDsXboxController. More...
struct  Axis
 Represents an axis on an NiDsXboxController. More...

Public Member Functions

 NiDsXboxController (int port)
 Construct an instance of a controller.
 ~NiDsXboxController () override=default
 NiDsXboxController (NiDsXboxController &&)=default
NiDsXboxControlleroperator= (NiDsXboxController &&)=default
double GetLeftX () const
 Get the X axis value of left side of the controller.
double GetRightX () const
 Get the X axis value of right side of the controller.
double GetLeftY () const
 Get the Y axis value of left side of the controller.
double GetRightY () const
 Get the Y axis value of right side of the controller.
double GetLeftTriggerAxis () const
 Get the left trigger axis value of the controller.
BooleanEvent LeftTrigger (double threshold, EventLoop *loop) const
 Constructs an event instance around the axis value of the left trigger.
BooleanEvent LeftTrigger (EventLoop *loop) const
 Constructs an event instance around the axis value of the left trigger.
double GetRightTriggerAxis () const
 Get the right trigger axis value of the controller.
BooleanEvent RightTrigger (double threshold, EventLoop *loop) const
 Constructs an event instance around the axis value of the right trigger.
BooleanEvent RightTrigger (EventLoop *loop) const
 Constructs an event instance around the axis value of the right trigger.
bool GetAButton () const
 Read the value of the A button on the controller.
bool GetAButtonPressed ()
 Whether the A button was pressed since the last check.
bool GetAButtonReleased ()
 Whether the A button was released since the last check.
BooleanEvent A (EventLoop *loop) const
 Constructs an event instance around the A button's digital signal.
bool GetBButton () const
 Read the value of the B button on the controller.
bool GetBButtonPressed ()
 Whether the B button was pressed since the last check.
bool GetBButtonReleased ()
 Whether the B button was released since the last check.
BooleanEvent B (EventLoop *loop) const
 Constructs an event instance around the B button's digital signal.
bool GetXButton () const
 Read the value of the X button on the controller.
bool GetXButtonPressed ()
 Whether the X button was pressed since the last check.
bool GetXButtonReleased ()
 Whether the X button was released since the last check.
BooleanEvent X (EventLoop *loop) const
 Constructs an event instance around the X button's digital signal.
bool GetYButton () const
 Read the value of the Y button on the controller.
bool GetYButtonPressed ()
 Whether the Y button was pressed since the last check.
bool GetYButtonReleased ()
 Whether the Y button was released since the last check.
BooleanEvent Y (EventLoop *loop) const
 Constructs an event instance around the Y button's digital signal.
bool GetLeftBumperButton () const
 Read the value of the left bumper button on the controller.
bool GetLeftBumperButtonPressed ()
 Whether the left bumper button was pressed since the last check.
bool GetLeftBumperButtonReleased ()
 Whether the left bumper button was released since the last check.
BooleanEvent LeftBumper (EventLoop *loop) const
 Constructs an event instance around the left bumper button's digital signal.
bool GetRightBumperButton () const
 Read the value of the right bumper button on the controller.
bool GetRightBumperButtonPressed ()
 Whether the right bumper button was pressed since the last check.
bool GetRightBumperButtonReleased ()
 Whether the right bumper button was released since the last check.
BooleanEvent RightBumper (EventLoop *loop) const
 Constructs an event instance around the right bumper button's digital signal.
bool GetBackButton () const
 Read the value of the back button on the controller.
bool GetBackButtonPressed ()
 Whether the back button was pressed since the last check.
bool GetBackButtonReleased ()
 Whether the back button was released since the last check.
BooleanEvent Back (EventLoop *loop) const
 Constructs an event instance around the back button's digital signal.
bool GetStartButton () const
 Read the value of the start button on the controller.
bool GetStartButtonPressed ()
 Whether the start button was pressed since the last check.
bool GetStartButtonReleased ()
 Whether the start button was released since the last check.
BooleanEvent Start (EventLoop *loop) const
 Constructs an event instance around the start button's digital signal.
bool GetLeftStickButton () const
 Read the value of the left stick button on the controller.
bool GetLeftStickButtonPressed ()
 Whether the left stick button was pressed since the last check.
bool GetLeftStickButtonReleased ()
 Whether the left stick button was released since the last check.
BooleanEvent LeftStick (EventLoop *loop) const
 Constructs an event instance around the left stick button's digital signal.
bool GetRightStickButton () const
 Read the value of the right stick button on the controller.
bool GetRightStickButtonPressed ()
 Whether the right stick button was pressed since the last check.
bool GetRightStickButtonReleased ()
 Whether the right stick button was released since the last check.
BooleanEvent RightStick (EventLoop *loop) const
 Constructs an event instance around the right stick button's digital signal.
void InitSendable (wpi::util::SendableBuilder &builder) override
 Initializes this Sendable object.
Public Member Functions inherited from wpi::GenericHID
 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.
Public Member Functions inherited from wpi::util::Sendable
virtual constexpr ~Sendable ()=default
Public Member Functions inherited from wpi::util::SendableHelper< NiDsXboxController >
constexpr SendableHelper (const SendableHelper &rhs)=default
constexpr SendableHelperoperator= (const SendableHelper &rhs)=default

Additional Inherited Members

Public Types inherited from wpi::GenericHID
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...
Protected Member Functions inherited from wpi::util::SendableHelper< NiDsXboxController >
constexpr ~SendableHelper ()

Detailed Description

Handle input from NiDsXbox controllers connected to the Driver Station.

This class handles NiDsXbox 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 controller and the mapping of ports to hardware buttons depends on the code in the Driver Station.

Only first party controllers from Microsoft are guaranteed to have the correct mapping, and only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd party controllers.

Constructor & Destructor Documentation

◆ NiDsXboxController() [1/2]

wpi::NiDsXboxController::NiDsXboxController ( int port)
explicit

Construct an instance of a controller.

The controller index is the USB port on the Driver Station.

Parameters
portThe port on the Driver Station that the controller is plugged into (0-5).

◆ ~NiDsXboxController()

wpi::NiDsXboxController::~NiDsXboxController ( )
overridedefault

◆ NiDsXboxController() [2/2]

wpi::NiDsXboxController::NiDsXboxController ( NiDsXboxController && )
default

Member Function Documentation

◆ A()

BooleanEvent wpi::NiDsXboxController::A ( EventLoop * loop) const

Constructs an event instance around the A button's digital signal.

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

◆ B()

BooleanEvent wpi::NiDsXboxController::B ( EventLoop * loop) const

Constructs an event instance around the B button's digital signal.

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

◆ Back()

BooleanEvent wpi::NiDsXboxController::Back ( EventLoop * loop) const

Constructs an event instance around the back button's digital signal.

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

◆ GetAButton()

bool wpi::NiDsXboxController::GetAButton ( ) const

Read the value of the A button on the controller.

Returns
The state of the button.

◆ GetAButtonPressed()

bool wpi::NiDsXboxController::GetAButtonPressed ( )

Whether the A button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetAButtonReleased()

bool wpi::NiDsXboxController::GetAButtonReleased ( )

Whether the A button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetBackButton()

bool wpi::NiDsXboxController::GetBackButton ( ) const

Read the value of the back button on the controller.

Returns
The state of the button.

◆ GetBackButtonPressed()

bool wpi::NiDsXboxController::GetBackButtonPressed ( )

Whether the back button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetBackButtonReleased()

bool wpi::NiDsXboxController::GetBackButtonReleased ( )

Whether the back button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetBButton()

bool wpi::NiDsXboxController::GetBButton ( ) const

Read the value of the B button on the controller.

Returns
The state of the button.

◆ GetBButtonPressed()

bool wpi::NiDsXboxController::GetBButtonPressed ( )

Whether the B button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetBButtonReleased()

bool wpi::NiDsXboxController::GetBButtonReleased ( )

Whether the B button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetLeftBumperButton()

bool wpi::NiDsXboxController::GetLeftBumperButton ( ) const

Read the value of the left bumper button on the controller.

Returns
The state of the button.

◆ GetLeftBumperButtonPressed()

bool wpi::NiDsXboxController::GetLeftBumperButtonPressed ( )

Whether the left bumper button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetLeftBumperButtonReleased()

bool wpi::NiDsXboxController::GetLeftBumperButtonReleased ( )

Whether the left bumper button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetLeftStickButton()

bool wpi::NiDsXboxController::GetLeftStickButton ( ) const

Read the value of the left stick button on the controller.

Returns
The state of the button.

◆ GetLeftStickButtonPressed()

bool wpi::NiDsXboxController::GetLeftStickButtonPressed ( )

Whether the left stick button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetLeftStickButtonReleased()

bool wpi::NiDsXboxController::GetLeftStickButtonReleased ( )

Whether the left stick button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetLeftTriggerAxis()

double wpi::NiDsXboxController::GetLeftTriggerAxis ( ) const

Get the left trigger axis value of the controller.

Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].

Returns
the axis value.

◆ GetLeftX()

double wpi::NiDsXboxController::GetLeftX ( ) const

Get the X axis value of left side of the controller.

Right is positive.

Returns
the axis value.

◆ GetLeftY()

double wpi::NiDsXboxController::GetLeftY ( ) const

Get the Y axis value of left side of the controller.

Back is positive.

Returns
the axis value.

◆ GetRightBumperButton()

bool wpi::NiDsXboxController::GetRightBumperButton ( ) const

Read the value of the right bumper button on the controller.

Returns
The state of the button.

◆ GetRightBumperButtonPressed()

bool wpi::NiDsXboxController::GetRightBumperButtonPressed ( )

Whether the right bumper button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetRightBumperButtonReleased()

bool wpi::NiDsXboxController::GetRightBumperButtonReleased ( )

Whether the right bumper button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetRightStickButton()

bool wpi::NiDsXboxController::GetRightStickButton ( ) const

Read the value of the right stick button on the controller.

Returns
The state of the button.

◆ GetRightStickButtonPressed()

bool wpi::NiDsXboxController::GetRightStickButtonPressed ( )

Whether the right stick button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetRightStickButtonReleased()

bool wpi::NiDsXboxController::GetRightStickButtonReleased ( )

Whether the right stick button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetRightTriggerAxis()

double wpi::NiDsXboxController::GetRightTriggerAxis ( ) const

Get the right trigger axis value of the controller.

Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].

Returns
the axis value.

◆ GetRightX()

double wpi::NiDsXboxController::GetRightX ( ) const

Get the X axis value of right side of the controller.

Right is positive.

Returns
the axis value.

◆ GetRightY()

double wpi::NiDsXboxController::GetRightY ( ) const

Get the Y axis value of right side of the controller.

Back is positive.

Returns
the axis value.

◆ GetStartButton()

bool wpi::NiDsXboxController::GetStartButton ( ) const

Read the value of the start button on the controller.

Returns
The state of the button.

◆ GetStartButtonPressed()

bool wpi::NiDsXboxController::GetStartButtonPressed ( )

Whether the start button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetStartButtonReleased()

bool wpi::NiDsXboxController::GetStartButtonReleased ( )

Whether the start button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetXButton()

bool wpi::NiDsXboxController::GetXButton ( ) const

Read the value of the X button on the controller.

Returns
The state of the button.

◆ GetXButtonPressed()

bool wpi::NiDsXboxController::GetXButtonPressed ( )

Whether the X button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetXButtonReleased()

bool wpi::NiDsXboxController::GetXButtonReleased ( )

Whether the X button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetYButton()

bool wpi::NiDsXboxController::GetYButton ( ) const

Read the value of the Y button on the controller.

Returns
The state of the button.

◆ GetYButtonPressed()

bool wpi::NiDsXboxController::GetYButtonPressed ( )

Whether the Y button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetYButtonReleased()

bool wpi::NiDsXboxController::GetYButtonReleased ( )

Whether the Y button was released since the last check.

Returns
Whether the button was released since the last check.

◆ InitSendable()

void wpi::NiDsXboxController::InitSendable ( wpi::util::SendableBuilder & builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::util::Sendable.

◆ LeftBumper()

BooleanEvent wpi::NiDsXboxController::LeftBumper ( EventLoop * loop) const

Constructs an event instance around the left bumper button's digital signal.

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

◆ LeftStick()

BooleanEvent wpi::NiDsXboxController::LeftStick ( EventLoop * loop) const

Constructs an event instance around the left stick button's digital signal.

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

◆ LeftTrigger() [1/2]

BooleanEvent wpi::NiDsXboxController::LeftTrigger ( double threshold,
EventLoop * loop ) const

Constructs an event instance around the axis value of the left trigger.

The returned trigger will be true when the axis value is greater than threshold.

Parameters
thresholdthe minimum axis value for the returned event to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop

◆ LeftTrigger() [2/2]

BooleanEvent wpi::NiDsXboxController::LeftTrigger ( EventLoop * loop) const

Constructs an event instance around the axis value of the left trigger.

The returned trigger will be true when the axis value is greater than 0.5.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the left trigger's axis exceeds 0.5, attached to the given event loop

◆ operator=()

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

◆ RightBumper()

BooleanEvent wpi::NiDsXboxController::RightBumper ( EventLoop * loop) const

Constructs an event instance around the right bumper button's digital signal.

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

◆ RightStick()

BooleanEvent wpi::NiDsXboxController::RightStick ( EventLoop * loop) const

Constructs an event instance around the right stick button's digital signal.

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

◆ RightTrigger() [1/2]

BooleanEvent wpi::NiDsXboxController::RightTrigger ( double threshold,
EventLoop * loop ) const

Constructs an event instance around the axis value of the right trigger.

The returned trigger will be true when the axis value is greater than threshold.

Parameters
thresholdthe minimum axis value for the returned event to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop

◆ RightTrigger() [2/2]

BooleanEvent wpi::NiDsXboxController::RightTrigger ( EventLoop * loop) const

Constructs an event instance around the axis value of the right trigger.

The returned trigger will be true when the axis value is greater than 0.5.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance that is true when the right trigger's axis exceeds 0.5, attached to the given event loop

◆ Start()

BooleanEvent wpi::NiDsXboxController::Start ( EventLoop * loop) const

Constructs an event instance around the start button's digital signal.

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

◆ X()

BooleanEvent wpi::NiDsXboxController::X ( EventLoop * loop) const

Constructs an event instance around the X button's digital signal.

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

◆ Y()

BooleanEvent wpi::NiDsXboxController::Y ( EventLoop * loop) const

Constructs an event instance around the Y button's digital signal.

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

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