WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
NiDsXboxController.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY
6
7#pragma once
8
11
13
14namespace wpi {
15
16/**
17 * Handle input from NiDsXbox controllers connected to the Driver Station.
18 *
19 * This class handles NiDsXbox input that comes from the Driver Station. Each
20 * time a value is requested the most recent value is returned. There is a
21 * single class instance for each controller and the mapping of ports to
22 * hardware buttons depends on the code in the Driver Station.
23 *
24 * Only first party controllers from Microsoft are guaranteed to have the
25 * correct mapping, and only through the official NI DS. Sim is not guaranteed
26 * to have the same mapping, as well as any 3rd party controllers.
27 */
30 public wpi::util::SendableHelper<NiDsXboxController> {
31 public:
32 /**
33 * Construct an instance of a controller.
34 *
35 * The controller index is the USB port on the Driver Station.
36 *
37 * @param port The port on the Driver Station that the controller is plugged
38 * into (0-5).
39 */
40 explicit NiDsXboxController(int port);
41
42 ~NiDsXboxController() override = default;
43
46
47 /**
48 * Get the X axis value of left side of the controller. Right is positive.
49 *
50 * @return the axis value.
51 */
52 double GetLeftX() const;
53
54 /**
55 * Get the X axis value of right side of the controller. Right is positive.
56 *
57 * @return the axis value.
58 */
59 double GetRightX() const;
60
61 /**
62 * Get the Y axis value of left side of the controller. Back is positive.
63 *
64 * @return the axis value.
65 */
66 double GetLeftY() const;
67
68 /**
69 * Get the Y axis value of right side of the controller. Back is positive.
70 *
71 * @return the axis value.
72 */
73 double GetRightY() const;
74
75 /**
76 * Get the left trigger axis value of the controller. Note that this axis
77 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
78 *
79 * @return the axis value.
80 */
81 double GetLeftTriggerAxis() const;
82
83 /**
84 * Constructs an event instance around the axis value of the left trigger.
85 * The returned trigger will be true when the axis value is greater than
86 * {@code threshold}.
87 * @param threshold the minimum axis value for the returned event to be true.
88 * This value should be in the range [0, 1] where 0 is the unpressed state of
89 * the axis.
90 * @param loop the event loop instance to attach the event to.
91 * @return an event instance that is true when the left trigger's axis
92 * exceeds the provided threshold, attached to the given event loop
93 */
94 BooleanEvent LeftTrigger(double threshold, EventLoop* loop) const;
95
96 /**
97 * Constructs an event instance around the axis value of the left trigger.
98 * The returned trigger will be true when the axis value is greater than 0.5.
99 * @param loop the event loop instance to attach the event to.
100 * @return an event instance that is true when the left trigger's axis
101 * exceeds 0.5, attached to the given event loop
102 */
104
105 /**
106 * Get the right trigger axis value of the controller. Note that this axis
107 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
108 *
109 * @return the axis value.
110 */
111 double GetRightTriggerAxis() const;
112
113 /**
114 * Constructs an event instance around the axis value of the right trigger.
115 * The returned trigger will be true when the axis value is greater than
116 * {@code threshold}.
117 * @param threshold the minimum axis value for the returned event to be true.
118 * This value should be in the range [0, 1] where 0 is the unpressed state of
119 * the axis.
120 * @param loop the event loop instance to attach the event to.
121 * @return an event instance that is true when the right trigger's axis
122 * exceeds the provided threshold, attached to the given event loop
123 */
124 BooleanEvent RightTrigger(double threshold, EventLoop* loop) const;
125
126 /**
127 * Constructs an event instance around the axis value of the right trigger.
128 * The returned trigger will be true when the axis value is greater than 0.5.
129 * @param loop the event loop instance to attach the event to.
130 * @return an event instance that is true when the right trigger's axis
131 * exceeds 0.5, attached to the given event loop
132 */
134
135 /**
136 * Read the value of the A button on the controller.
137 *
138 * @return The state of the button.
139 */
140 bool GetAButton() const;
141
142 /**
143 * Whether the A button was pressed since the last check.
144 *
145 * @return Whether the button was pressed since the last check.
146 */
148
149 /**
150 * Whether the A button was released since the last check.
151 *
152 * @return Whether the button was released since the last check.
153 */
155
156 /**
157 * Constructs an event instance around the A button's
158 * digital signal.
159 *
160 * @param loop the event loop instance to attach the event to.
161 * @return an event instance representing the A button's
162 * digital signal attached to the given loop.
163 */
165
166 /**
167 * Read the value of the B button on the controller.
168 *
169 * @return The state of the button.
170 */
171 bool GetBButton() const;
172
173 /**
174 * Whether the B button was pressed since the last check.
175 *
176 * @return Whether the button was pressed since the last check.
177 */
179
180 /**
181 * Whether the B button was released since the last check.
182 *
183 * @return Whether the button was released since the last check.
184 */
186
187 /**
188 * Constructs an event instance around the B button's
189 * digital signal.
190 *
191 * @param loop the event loop instance to attach the event to.
192 * @return an event instance representing the B button's
193 * digital signal attached to the given loop.
194 */
196
197 /**
198 * Read the value of the X button on the controller.
199 *
200 * @return The state of the button.
201 */
202 bool GetXButton() const;
203
204 /**
205 * Whether the X button was pressed since the last check.
206 *
207 * @return Whether the button was pressed since the last check.
208 */
210
211 /**
212 * Whether the X button was released since the last check.
213 *
214 * @return Whether the button was released since the last check.
215 */
217
218 /**
219 * Constructs an event instance around the X button's
220 * digital signal.
221 *
222 * @param loop the event loop instance to attach the event to.
223 * @return an event instance representing the X button's
224 * digital signal attached to the given loop.
225 */
227
228 /**
229 * Read the value of the Y button on the controller.
230 *
231 * @return The state of the button.
232 */
233 bool GetYButton() const;
234
235 /**
236 * Whether the Y button was pressed since the last check.
237 *
238 * @return Whether the button was pressed since the last check.
239 */
241
242 /**
243 * Whether the Y button was released since the last check.
244 *
245 * @return Whether the button was released since the last check.
246 */
248
249 /**
250 * Constructs an event instance around the Y button's
251 * digital signal.
252 *
253 * @param loop the event loop instance to attach the event to.
254 * @return an event instance representing the Y button's
255 * digital signal attached to the given loop.
256 */
258
259 /**
260 * Read the value of the left bumper button on the controller.
261 *
262 * @return The state of the button.
263 */
265
266 /**
267 * Whether the left bumper button was pressed since the last check.
268 *
269 * @return Whether the button was pressed since the last check.
270 */
272
273 /**
274 * Whether the left bumper button was released since the last check.
275 *
276 * @return Whether the button was released since the last check.
277 */
279
280 /**
281 * Constructs an event instance around the left bumper button's
282 * digital signal.
283 *
284 * @param loop the event loop instance to attach the event to.
285 * @return an event instance representing the left bumper button's
286 * digital signal attached to the given loop.
287 */
289
290 /**
291 * Read the value of the right bumper button on the controller.
292 *
293 * @return The state of the button.
294 */
296
297 /**
298 * Whether the right bumper button was pressed since the last check.
299 *
300 * @return Whether the button was pressed since the last check.
301 */
303
304 /**
305 * Whether the right bumper button was released since the last check.
306 *
307 * @return Whether the button was released since the last check.
308 */
310
311 /**
312 * Constructs an event instance around the right bumper button's
313 * digital signal.
314 *
315 * @param loop the event loop instance to attach the event to.
316 * @return an event instance representing the right bumper button's
317 * digital signal attached to the given loop.
318 */
320
321 /**
322 * Read the value of the back button on the controller.
323 *
324 * @return The state of the button.
325 */
326 bool GetBackButton() const;
327
328 /**
329 * Whether the back button was pressed since the last check.
330 *
331 * @return Whether the button was pressed since the last check.
332 */
334
335 /**
336 * Whether the back button was released since the last check.
337 *
338 * @return Whether the button was released since the last check.
339 */
341
342 /**
343 * Constructs an event instance around the back button's
344 * digital signal.
345 *
346 * @param loop the event loop instance to attach the event to.
347 * @return an event instance representing the back button's
348 * digital signal attached to the given loop.
349 */
351
352 /**
353 * Read the value of the start button on the controller.
354 *
355 * @return The state of the button.
356 */
357 bool GetStartButton() const;
358
359 /**
360 * Whether the start button was pressed since the last check.
361 *
362 * @return Whether the button was pressed since the last check.
363 */
365
366 /**
367 * Whether the start button was released since the last check.
368 *
369 * @return Whether the button was released since the last check.
370 */
372
373 /**
374 * Constructs an event instance around the start button's
375 * digital signal.
376 *
377 * @param loop the event loop instance to attach the event to.
378 * @return an event instance representing the start button's
379 * digital signal attached to the given loop.
380 */
382
383 /**
384 * Read the value of the left stick button on the controller.
385 *
386 * @return The state of the button.
387 */
388 bool GetLeftStickButton() const;
389
390 /**
391 * Whether the left stick button was pressed since the last check.
392 *
393 * @return Whether the button was pressed since the last check.
394 */
396
397 /**
398 * Whether the left stick button was released since the last check.
399 *
400 * @return Whether the button was released since the last check.
401 */
403
404 /**
405 * Constructs an event instance around the left stick button's
406 * digital signal.
407 *
408 * @param loop the event loop instance to attach the event to.
409 * @return an event instance representing the left stick button's
410 * digital signal attached to the given loop.
411 */
413
414 /**
415 * Read the value of the right stick button on the controller.
416 *
417 * @return The state of the button.
418 */
420
421 /**
422 * Whether the right stick button was pressed since the last check.
423 *
424 * @return Whether the button was pressed since the last check.
425 */
427
428 /**
429 * Whether the right stick button was released since the last check.
430 *
431 * @return Whether the button was released since the last check.
432 */
434
435 /**
436 * Constructs an event instance around the right stick button's
437 * digital signal.
438 *
439 * @param loop the event loop instance to attach the event to.
440 * @return an event instance representing the right stick button's
441 * digital signal attached to the given loop.
442 */
444
445 /** Represents a digital button on an NiDsXboxController. */
446 struct Button {
447 /// A button.
448 static constexpr int kA = 0;
449 /// B button.
450 static constexpr int kB = 1;
451 /// X button.
452 static constexpr int kX = 2;
453 /// Y button.
454 static constexpr int kY = 3;
455 /// Left bumper button.
456 static constexpr int kLeftBumper = 4;
457 /// Right bumper button.
458 static constexpr int kRightBumper = 5;
459 /// Back button.
460 static constexpr int kBack = 6;
461 /// Start button.
462 static constexpr int kStart = 7;
463 /// Left stick button.
464 static constexpr int kLeftStick = 8;
465 /// Right stick button.
466 static constexpr int kRightStick = 9;
467 };
468
469 /** Represents an axis on an NiDsXboxController. */
470 struct Axis {
471 /// Left X axis.
472 static constexpr int kLeftX = 0;
473 /// Right X axis.
474 static constexpr int kRightX = 4;
475 /// Left Y axis.
476 static constexpr int kLeftY = 1;
477 /// Right Y axis.
478 static constexpr int kRightY = 5;
479 /// Left trigger.
480 static constexpr int kLeftTrigger = 2;
481 /// Right trigger.
482 static constexpr int kRightTrigger = 3;
483 };
484
486};
487
488} // namespace wpi
This class provides an easy way to link actions to active high logic signals.
Definition BooleanEvent.hpp:28
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.hpp:15
GenericHID(int port)
bool GetAButton() const
Read the value of the A button on the controller.
bool GetBButtonReleased()
Whether the B button was released since the last check.
bool GetLeftBumperButton() const
Read the value of the left bumper button on the controller.
BooleanEvent Y(EventLoop *loop) const
Constructs an event instance around the Y button's digital signal.
bool GetRightStickButton() const
Read the value of the right stick button on the controller.
BooleanEvent Back(EventLoop *loop) const
Constructs an event instance around the back button's digital signal.
bool GetLeftBumperButtonReleased()
Whether the left bumper button was released since the last check.
BooleanEvent RightTrigger(EventLoop *loop) const
Constructs an event instance around the axis value of the right trigger.
bool GetStartButtonPressed()
Whether the start button was pressed since the last check.
double GetLeftY() const
Get the Y axis value of left side of the controller.
BooleanEvent RightBumper(EventLoop *loop) const
Constructs an event instance around the right bumper button's digital signal.
bool GetRightStickButtonReleased()
Whether the right stick button was released since the last check.
BooleanEvent LeftTrigger(double threshold, EventLoop *loop) const
Constructs an event instance around the axis value of the left trigger.
double GetLeftTriggerAxis() const
Get the left trigger axis value of the controller.
bool GetBButtonPressed()
Whether the B button was pressed since the last check.
NiDsXboxController(int port)
Construct an instance of a controller.
bool GetRightBumperButton() const
Read the value of the right bumper button on the controller.
double GetRightY() const
Get the Y axis value of right side of the controller.
bool GetLeftStickButtonPressed()
Whether the left stick button was pressed since the last check.
double GetRightX() const
Get the X axis value of right side of the controller.
bool GetBackButtonPressed()
Whether the back button was pressed since the last check.
bool GetYButton() const
Read the value of the Y button on the controller.
double GetLeftX() const
Get the X axis value of left side of the controller.
bool GetAButtonReleased()
Whether the A button was released since the last check.
bool GetRightBumperButtonPressed()
Whether the right bumper button was pressed since the last check.
bool GetLeftStickButtonReleased()
Whether the left stick button was released since the last check.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
BooleanEvent X(EventLoop *loop) const
Constructs an event instance around the X button's digital signal.
BooleanEvent A(EventLoop *loop) const
Constructs an event instance around the A button's digital signal.
bool GetStartButtonReleased()
Whether the start button was released since the last check.
bool GetXButton() const
Read the value of the X button on the controller.
BooleanEvent RightTrigger(double threshold, EventLoop *loop) const
Constructs an event instance around the axis value of the right trigger.
bool GetBackButton() const
Read the value of the back button on the controller.
bool GetYButtonPressed()
Whether the Y button was pressed since the last check.
BooleanEvent RightStick(EventLoop *loop) const
Constructs an event instance around the right stick button's digital signal.
bool GetXButtonPressed()
Whether the X button was pressed since the last check.
bool GetBackButtonReleased()
Whether the back button was released since the last check.
BooleanEvent LeftBumper(EventLoop *loop) const
Constructs an event instance around the left bumper button's digital signal.
BooleanEvent B(EventLoop *loop) const
Constructs an event instance around the B button's digital signal.
~NiDsXboxController() override=default
bool GetBButton() const
Read the value of the B button on the controller.
double GetRightTriggerAxis() const
Get the right trigger axis value of the controller.
bool GetStartButton() const
Read the value of the start button on the controller.
BooleanEvent LeftTrigger(EventLoop *loop) const
Constructs an event instance around the axis value of the left trigger.
BooleanEvent LeftStick(EventLoop *loop) const
Constructs an event instance around the left stick button's digital signal.
NiDsXboxController(NiDsXboxController &&)=default
bool GetYButtonReleased()
Whether the Y button was released since the last check.
NiDsXboxController & operator=(NiDsXboxController &&)=default
bool GetXButtonReleased()
Whether the X button was released since the last check.
bool GetLeftBumperButtonPressed()
Whether the left bumper button was pressed since the last check.
bool GetLeftStickButton() const
Read the value of the left stick button on the controller.
bool GetAButtonPressed()
Whether the A button was pressed since the last check.
BooleanEvent Start(EventLoop *loop) const
Constructs an event instance around the start button's digital signal.
bool GetRightStickButtonPressed()
Whether the right stick button was pressed since the last check.
bool GetRightBumperButtonReleased()
Whether the right bumper button was released since the last check.
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
Interface for Sendable objects.
Definition Sendable.hpp:16
Definition CvSource.hpp:15
Represents an axis on an NiDsXboxController.
Definition NiDsXboxController.hpp:470
static constexpr int kRightX
Right X axis.
Definition NiDsXboxController.hpp:474
static constexpr int kLeftTrigger
Left trigger.
Definition NiDsXboxController.hpp:480
static constexpr int kRightY
Right Y axis.
Definition NiDsXboxController.hpp:478
static constexpr int kLeftY
Left Y axis.
Definition NiDsXboxController.hpp:476
static constexpr int kRightTrigger
Right trigger.
Definition NiDsXboxController.hpp:482
static constexpr int kLeftX
Left X axis.
Definition NiDsXboxController.hpp:472
Represents a digital button on an NiDsXboxController.
Definition NiDsXboxController.hpp:446
static constexpr int kRightBumper
Right bumper button.
Definition NiDsXboxController.hpp:458
static constexpr int kBack
Back button.
Definition NiDsXboxController.hpp:460
static constexpr int kStart
Start button.
Definition NiDsXboxController.hpp:462
static constexpr int kRightStick
Right stick button.
Definition NiDsXboxController.hpp:466
static constexpr int kY
Y button.
Definition NiDsXboxController.hpp:454
static constexpr int kA
A button.
Definition NiDsXboxController.hpp:448
static constexpr int kB
B button.
Definition NiDsXboxController.hpp:450
static constexpr int kX
X button.
Definition NiDsXboxController.hpp:452
static constexpr int kLeftBumper
Left bumper button.
Definition NiDsXboxController.hpp:456
static constexpr int kLeftStick
Left stick button.
Definition NiDsXboxController.hpp:464