WPILibC++  unspecified
XboxController.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "GenericHID.h"
11 
12 namespace frc {
13 
23 class XboxController : public GenericHID {
24  public:
33  explicit XboxController(int port);
34 
35  virtual ~XboxController() = default;
36 
37  XboxController(const XboxController&) = delete;
38  XboxController& operator=(const XboxController&) = delete;
39 
45  double GetX(JoystickHand hand) const override;
46 
52  double GetY(JoystickHand hand) const override;
53 
59  double GetTriggerAxis(JoystickHand hand) const;
60 
66  bool GetBumper(JoystickHand hand) const;
67 
74  bool GetBumperPressed(JoystickHand hand);
75 
82  bool GetBumperReleased(JoystickHand hand);
83 
90  bool GetStickButton(JoystickHand hand) const;
91 
98  bool GetStickButtonPressed(JoystickHand hand);
99 
106  bool GetStickButtonReleased(JoystickHand hand);
107 
113  bool GetAButton() const;
114 
120  bool GetAButtonPressed();
121 
127  bool GetAButtonReleased();
128 
134  bool GetBButton() const;
135 
141  bool GetBButtonPressed();
142 
148  bool GetBButtonReleased();
149 
155  bool GetXButton() const;
156 
162  bool GetXButtonPressed();
163 
169  bool GetXButtonReleased();
170 
176  bool GetYButton() const;
177 
183  bool GetYButtonPressed();
184 
190  bool GetYButtonReleased();
191 
197  bool GetBackButton() const;
198 
204  bool GetBackButtonPressed();
205 
211  bool GetBackButtonReleased();
212 
219  bool GetStartButton() const;
220 
226  bool GetStartButtonPressed();
227 
233  bool GetStartButtonReleased();
234 
235  private:
236  enum class Button {
237  kBumperLeft = 5,
238  kBumperRight = 6,
239  kStickLeft = 9,
240  kStickRight = 10,
241  kA = 1,
242  kB = 2,
243  kX = 3,
244  kY = 4,
245  kBack = 7,
246  kStart = 8
247  };
248 };
249 
250 } // namespace frc
bool GetStartButton() const
Read the value of the start button on the controller.
Definition: XboxController.cpp:151
bool GetAButtonReleased()
Whether the A button was released since the last check.
Definition: XboxController.cpp:99
Definition: Utility.cpp:119
bool GetBButton() const
Read the value of the B button on the controller.
Definition: XboxController.cpp:103
bool GetBButtonPressed()
Whether the B button was pressed since the last check.
Definition: XboxController.cpp:107
bool GetStartButtonPressed()
Whether the start button was pressed since the last check.
Definition: XboxController.cpp:155
Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station.
Definition: XboxController.h:23
double GetX(JoystickHand hand) const override
Get the X axis value of the controller.
Definition: XboxController.cpp:19
bool GetBButtonReleased()
Whether the B button was released since the last check.
Definition: XboxController.cpp:111
bool GetXButtonPressed()
Whether the X button was pressed since the last check.
Definition: XboxController.cpp:119
double GetTriggerAxis(JoystickHand hand) const
Get the trigger axis value of the controller.
Definition: XboxController.cpp:35
bool GetYButton() const
Read the value of the Y button on the controller.
Definition: XboxController.cpp:127
XboxController(int port)
Construct an instance of an Xbox controller.
Definition: XboxController.cpp:14
bool GetBumper(JoystickHand hand) const
Read the value of the bumper button on the controller.
Definition: XboxController.cpp:43
double GetY(JoystickHand hand) const override
Get the Y axis value of the controller.
Definition: XboxController.cpp:27
bool GetStickButtonPressed(JoystickHand hand)
Whether the stick button was pressed since the last check.
Definition: XboxController.cpp:75
bool GetYButtonPressed()
Whether the Y button was pressed since the last check.
Definition: XboxController.cpp:131
bool GetXButtonReleased()
Whether the X button was released since the last check.
Definition: XboxController.cpp:123
bool GetStartButtonReleased()
Whether the start button was released since the last check.
Definition: XboxController.cpp:159
bool GetBackButtonPressed()
Whether the back button was pressed since the last check.
Definition: XboxController.cpp:143
bool GetStickButtonReleased(JoystickHand hand)
Whether the stick button was released since the last check.
Definition: XboxController.cpp:83
bool GetXButton() const
Read the value of the X button on the controller.
Definition: XboxController.cpp:115
bool GetBumperReleased(JoystickHand hand)
Whether the bumper was released since the last check.
Definition: XboxController.cpp:59
bool GetStickButton(JoystickHand hand) const
Read the value of the stick button on the controller.
Definition: XboxController.cpp:67
bool GetBumperPressed(JoystickHand hand)
Whether the bumper was pressed since the last check.
Definition: XboxController.cpp:51
bool GetBackButton() const
Whether the Y button was released since the last check.
Definition: XboxController.cpp:139
bool GetBackButtonReleased()
Whether the back button was released since the last check.
Definition: XboxController.cpp:147
GenericHID Interface.
Definition: GenericHID.h:23
bool GetAButton() const
Read the value of the A button on the controller.
Definition: XboxController.cpp:91
bool GetYButtonReleased()
Whether the Y button was released since the last check.
Definition: XboxController.cpp:135
bool GetAButtonPressed()
Whether the A button was pressed since the last check.
Definition: XboxController.cpp:95