WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
NiDsPS4Controller.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 NiDsPS4 controllers connected to the Driver Station.
18 *
19 * This class handles NiDsPS4 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 Sony 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<NiDsPS4Controller> {
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 NiDsPS4Controller(int port);
41
42 ~NiDsPS4Controller() 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 Y axis value of left side of the controller. Back is positive.
56 *
57 * @return the axis value.
58 */
59 double GetLeftY() const;
60
61 /**
62 * Get the X axis value of right side of the controller. Right is positive.
63 *
64 * @return the axis value.
65 */
66 double GetRightX() 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 2 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 GetL2Axis() const;
82
83 /**
84 * Get the right trigger 2 axis value of the controller. Note that this axis
85 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
86 *
87 * @return the axis value.
88 */
89 double GetR2Axis() const;
90
91 /**
92 * Read the value of the square button on the controller.
93 *
94 * @return The state of the button.
95 */
96 bool GetSquareButton() const;
97
98 /**
99 * Whether the square button was pressed since the last check.
100 *
101 * @return Whether the button was pressed since the last check.
102 */
104
105 /**
106 * Whether the square button was released since the last check.
107 *
108 * @return Whether the button was released since the last check.
109 */
111
112 /**
113 * Constructs an event instance around the square button's
114 * digital signal.
115 *
116 * @param loop the event loop instance to attach the event to.
117 * @return an event instance representing the square button's
118 * digital signal attached to the given loop.
119 */
121
122 /**
123 * Read the value of the cross button on the controller.
124 *
125 * @return The state of the button.
126 */
127 bool GetCrossButton() const;
128
129 /**
130 * Whether the cross button was pressed since the last check.
131 *
132 * @return Whether the button was pressed since the last check.
133 */
135
136 /**
137 * Whether the cross button was released since the last check.
138 *
139 * @return Whether the button was released since the last check.
140 */
142
143 /**
144 * Constructs an event instance around the cross button's
145 * digital signal.
146 *
147 * @param loop the event loop instance to attach the event to.
148 * @return an event instance representing the cross button's
149 * digital signal attached to the given loop.
150 */
152
153 /**
154 * Read the value of the circle button on the controller.
155 *
156 * @return The state of the button.
157 */
158 bool GetCircleButton() const;
159
160 /**
161 * Whether the circle button was pressed since the last check.
162 *
163 * @return Whether the button was pressed since the last check.
164 */
166
167 /**
168 * Whether the circle button was released since the last check.
169 *
170 * @return Whether the button was released since the last check.
171 */
173
174 /**
175 * Constructs an event instance around the circle button's
176 * digital signal.
177 *
178 * @param loop the event loop instance to attach the event to.
179 * @return an event instance representing the circle button's
180 * digital signal attached to the given loop.
181 */
183
184 /**
185 * Read the value of the triangle button on the controller.
186 *
187 * @return The state of the button.
188 */
189 bool GetTriangleButton() const;
190
191 /**
192 * Whether the triangle button was pressed since the last check.
193 *
194 * @return Whether the button was pressed since the last check.
195 */
197
198 /**
199 * Whether the triangle button was released since the last check.
200 *
201 * @return Whether the button was released since the last check.
202 */
204
205 /**
206 * Constructs an event instance around the triangle button's
207 * digital signal.
208 *
209 * @param loop the event loop instance to attach the event to.
210 * @return an event instance representing the triangle button's
211 * digital signal attached to the given loop.
212 */
214
215 /**
216 * Read the value of the left trigger 1 button on the controller.
217 *
218 * @return The state of the button.
219 */
220 bool GetL1Button() const;
221
222 /**
223 * Whether the left trigger 1 button was pressed since the last check.
224 *
225 * @return Whether the button was pressed since the last check.
226 */
228
229 /**
230 * Whether the left trigger 1 button was released since the last check.
231 *
232 * @return Whether the button was released since the last check.
233 */
235
236 /**
237 * Constructs an event instance around the left trigger 1 button's
238 * digital signal.
239 *
240 * @param loop the event loop instance to attach the event to.
241 * @return an event instance representing the left trigger 1 button's
242 * digital signal attached to the given loop.
243 */
245
246 /**
247 * Read the value of the right trigger 1 button on the controller.
248 *
249 * @return The state of the button.
250 */
251 bool GetR1Button() const;
252
253 /**
254 * Whether the right trigger 1 button was pressed since the last check.
255 *
256 * @return Whether the button was pressed since the last check.
257 */
259
260 /**
261 * Whether the right trigger 1 button was released since the last check.
262 *
263 * @return Whether the button was released since the last check.
264 */
266
267 /**
268 * Constructs an event instance around the right trigger 1 button's
269 * digital signal.
270 *
271 * @param loop the event loop instance to attach the event to.
272 * @return an event instance representing the right trigger 1 button's
273 * digital signal attached to the given loop.
274 */
276
277 /**
278 * Read the value of the left trigger 2 button on the controller.
279 *
280 * @return The state of the button.
281 */
282 bool GetL2Button() const;
283
284 /**
285 * Whether the left trigger 2 button was pressed since the last check.
286 *
287 * @return Whether the button was pressed since the last check.
288 */
290
291 /**
292 * Whether the left trigger 2 button was released since the last check.
293 *
294 * @return Whether the button was released since the last check.
295 */
297
298 /**
299 * Constructs an event instance around the left trigger 2 button's
300 * digital signal.
301 *
302 * @param loop the event loop instance to attach the event to.
303 * @return an event instance representing the left trigger 2 button's
304 * digital signal attached to the given loop.
305 */
307
308 /**
309 * Read the value of the right trigger 2 button on the controller.
310 *
311 * @return The state of the button.
312 */
313 bool GetR2Button() const;
314
315 /**
316 * Whether the right trigger 2 button was pressed since the last check.
317 *
318 * @return Whether the button was pressed since the last check.
319 */
321
322 /**
323 * Whether the right trigger 2 button was released since the last check.
324 *
325 * @return Whether the button was released since the last check.
326 */
328
329 /**
330 * Constructs an event instance around the right trigger 2 button's
331 * digital signal.
332 *
333 * @param loop the event loop instance to attach the event to.
334 * @return an event instance representing the right trigger 2 button's
335 * digital signal attached to the given loop.
336 */
338
339 /**
340 * Read the value of the share button on the controller.
341 *
342 * @return The state of the button.
343 */
344 bool GetShareButton() const;
345
346 /**
347 * Whether the share button was pressed since the last check.
348 *
349 * @return Whether the button was pressed since the last check.
350 */
352
353 /**
354 * Whether the share button was released since the last check.
355 *
356 * @return Whether the button was released since the last check.
357 */
359
360 /**
361 * Constructs an event instance around the share button's
362 * digital signal.
363 *
364 * @param loop the event loop instance to attach the event to.
365 * @return an event instance representing the share button's
366 * digital signal attached to the given loop.
367 */
369
370 /**
371 * Read the value of the options button on the controller.
372 *
373 * @return The state of the button.
374 */
375 bool GetOptionsButton() const;
376
377 /**
378 * Whether the options button was pressed since the last check.
379 *
380 * @return Whether the button was pressed since the last check.
381 */
383
384 /**
385 * Whether the options button was released since the last check.
386 *
387 * @return Whether the button was released since the last check.
388 */
390
391 /**
392 * Constructs an event instance around the options button's
393 * digital signal.
394 *
395 * @param loop the event loop instance to attach the event to.
396 * @return an event instance representing the options button's
397 * digital signal attached to the given loop.
398 */
400
401 /**
402 * Read the value of the L3 (left stick) button on the controller.
403 *
404 * @return The state of the button.
405 */
406 bool GetL3Button() const;
407
408 /**
409 * Whether the L3 (left stick) button was pressed since the last check.
410 *
411 * @return Whether the button was pressed since the last check.
412 */
414
415 /**
416 * Whether the L3 (left stick) button was released since the last check.
417 *
418 * @return Whether the button was released since the last check.
419 */
421
422 /**
423 * Constructs an event instance around the L3 (left stick) button's
424 * digital signal.
425 *
426 * @param loop the event loop instance to attach the event to.
427 * @return an event instance representing the L3 (left stick) button's
428 * digital signal attached to the given loop.
429 */
431
432 /**
433 * Read the value of the R3 (right stick) button on the controller.
434 *
435 * @return The state of the button.
436 */
437 bool GetR3Button() const;
438
439 /**
440 * Whether the R3 (right stick) button was pressed since the last check.
441 *
442 * @return Whether the button was pressed since the last check.
443 */
445
446 /**
447 * Whether the R3 (right stick) button was released since the last check.
448 *
449 * @return Whether the button was released since the last check.
450 */
452
453 /**
454 * Constructs an event instance around the R3 (right stick) button's
455 * digital signal.
456 *
457 * @param loop the event loop instance to attach the event to.
458 * @return an event instance representing the R3 (right stick) button's
459 * digital signal attached to the given loop.
460 */
462
463 /**
464 * Read the value of the PlayStation button on the controller.
465 *
466 * @return The state of the button.
467 */
468 bool GetPSButton() const;
469
470 /**
471 * Whether the PlayStation button was pressed since the last check.
472 *
473 * @return Whether the button was pressed since the last check.
474 */
476
477 /**
478 * Whether the PlayStation button was released since the last check.
479 *
480 * @return Whether the button was released since the last check.
481 */
483
484 /**
485 * Constructs an event instance around the PlayStation button's
486 * digital signal.
487 *
488 * @param loop the event loop instance to attach the event to.
489 * @return an event instance representing the PlayStation button's
490 * digital signal attached to the given loop.
491 */
493
494 /**
495 * Read the value of the touchpad button on the controller.
496 *
497 * @return The state of the button.
498 */
499 bool GetTouchpadButton() const;
500
501 /**
502 * Whether the touchpad button was pressed since the last check.
503 *
504 * @return Whether the button was pressed since the last check.
505 */
507
508 /**
509 * Whether the touchpad button was released since the last check.
510 *
511 * @return Whether the button was released since the last check.
512 */
514
515 /**
516 * Constructs an event instance around the touchpad button's
517 * digital signal.
518 *
519 * @param loop the event loop instance to attach the event to.
520 * @return an event instance representing the touchpad button's
521 * digital signal attached to the given loop.
522 */
524
525 /** Represents a digital button on an NiDsPS4Controller. */
526 struct Button {
527 /// Square button.
528 static constexpr int kSquare = 0;
529 /// Cross button.
530 static constexpr int kCross = 1;
531 /// Circle button.
532 static constexpr int kCircle = 2;
533 /// Triangle button.
534 static constexpr int kTriangle = 3;
535 /// Left trigger 1 button.
536 static constexpr int kL1 = 4;
537 /// Right trigger 1 button.
538 static constexpr int kR1 = 5;
539 /// Left trigger 2 button.
540 static constexpr int kL2 = 6;
541 /// Right trigger 2 button.
542 static constexpr int kR2 = 7;
543 /// Share button.
544 static constexpr int kShare = 8;
545 /// Options button.
546 static constexpr int kOptions = 9;
547 /// L3 (left stick) button.
548 static constexpr int kL3 = 10;
549 /// R3 (right stick) button.
550 static constexpr int kR3 = 11;
551 /// PlayStation button.
552 static constexpr int kPS = 12;
553 /// Touchpad button.
554 static constexpr int kTouchpad = 13;
555 };
556
557 /** Represents an axis on an NiDsPS4Controller. */
558 struct Axis {
559 /// Left X axis.
560 static constexpr int kLeftX = 0;
561 /// Left Y axis.
562 static constexpr int kLeftY = 1;
563 /// Right X axis.
564 static constexpr int kRightX = 2;
565 /// Right Y axis.
566 static constexpr int kRightY = 5;
567 /// Left trigger 2.
568 static constexpr int kL2 = 3;
569 /// Right trigger 2.
570 static constexpr int kR2 = 4;
571 };
572
574};
575
576} // 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 GetShareButtonReleased()
Whether the share button was released since the last check.
BooleanEvent L2(EventLoop *loop) const
Constructs an event instance around the left trigger 2 button's digital signal.
bool GetR1ButtonReleased()
Whether the right trigger 1 button was released since the last check.
BooleanEvent L1(EventLoop *loop) const
Constructs an event instance around the left trigger 1 button's digital signal.
bool GetR1ButtonPressed()
Whether the right trigger 1 button was pressed since the last check.
bool GetCircleButton() const
Read the value of the circle button on the controller.
bool GetTriangleButton() const
Read the value of the triangle button on the controller.
~NiDsPS4Controller() override=default
bool GetL1ButtonReleased()
Whether the left trigger 1 button was released since the last check.
bool GetR3Button() const
Read the value of the R3 (right stick) button on the controller.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
bool GetTouchpadButtonReleased()
Whether the touchpad button was released since the last check.
bool GetSquareButtonPressed()
Whether the square button was pressed since the last check.
bool GetR2ButtonPressed()
Whether the right trigger 2 button was pressed since the last check.
bool GetL3Button() const
Read the value of the L3 (left stick) button on the controller.
bool GetTouchpadButton() const
Read the value of the touchpad button on the controller.
double GetRightX() const
Get the X axis value of right side of the controller.
bool GetTouchpadButtonPressed()
Whether the touchpad button was pressed since the last check.
BooleanEvent R1(EventLoop *loop) const
Constructs an event instance around the right trigger 1 button's digital signal.
bool GetShareButton() const
Read the value of the share button on the controller.
BooleanEvent L3(EventLoop *loop) const
Constructs an event instance around the L3 (left stick) button's digital signal.
BooleanEvent Cross(EventLoop *loop) const
Constructs an event instance around the cross button's digital signal.
bool GetCrossButtonPressed()
Whether the cross button was pressed since the last check.
bool GetL3ButtonReleased()
Whether the L3 (left stick) button was released since the last check.
double GetLeftX() const
Get the X axis value of left side of the controller.
bool GetTriangleButtonPressed()
Whether the triangle button was pressed since the last check.
bool GetL1Button() const
Read the value of the left trigger 1 button on the controller.
bool GetShareButtonPressed()
Whether the share button was pressed since the last check.
bool GetR1Button() const
Read the value of the right trigger 1 button on the controller.
BooleanEvent Square(EventLoop *loop) const
Constructs an event instance around the square button's digital signal.
bool GetR3ButtonReleased()
Whether the R3 (right stick) button was released since the last check.
NiDsPS4Controller(NiDsPS4Controller &&)=default
bool GetR2ButtonReleased()
Whether the right trigger 2 button was released since the last check.
bool GetTriangleButtonReleased()
Whether the triangle button was released since the last check.
bool GetCrossButtonReleased()
Whether the cross button was released since the last check.
bool GetCircleButtonPressed()
Whether the circle button was pressed since the last check.
NiDsPS4Controller & operator=(NiDsPS4Controller &&)=default
bool GetSquareButtonReleased()
Whether the square button was released since the last check.
BooleanEvent PS(EventLoop *loop) const
Constructs an event instance around the PlayStation button's digital signal.
bool GetL1ButtonPressed()
Whether the left trigger 1 button was pressed since the last check.
bool GetL2ButtonPressed()
Whether the left trigger 2 button was pressed since the last check.
BooleanEvent Options(EventLoop *loop) const
Constructs an event instance around the options button's digital signal.
double GetRightY() const
Get the Y axis value of right side of the controller.
BooleanEvent R2(EventLoop *loop) const
Constructs an event instance around the right trigger 2 button's digital signal.
bool GetCircleButtonReleased()
Whether the circle button was released since the last check.
BooleanEvent Triangle(EventLoop *loop) const
Constructs an event instance around the triangle button's digital signal.
bool GetPSButtonPressed()
Whether the PlayStation button was pressed since the last check.
bool GetOptionsButton() const
Read the value of the options button on the controller.
bool GetL2ButtonReleased()
Whether the left trigger 2 button was released since the last check.
bool GetOptionsButtonReleased()
Whether the options button was released since the last check.
bool GetR3ButtonPressed()
Whether the R3 (right stick) button was pressed since the last check.
bool GetPSButton() const
Read the value of the PlayStation button on the controller.
bool GetCrossButton() const
Read the value of the cross button on the controller.
bool GetPSButtonReleased()
Whether the PlayStation button was released since the last check.
double GetL2Axis() const
Get the left trigger 2 axis value of the controller.
bool GetL3ButtonPressed()
Whether the L3 (left stick) button was pressed since the last check.
BooleanEvent Touchpad(EventLoop *loop) const
Constructs an event instance around the touchpad button's digital signal.
NiDsPS4Controller(int port)
Construct an instance of a controller.
bool GetL2Button() const
Read the value of the left trigger 2 button on the controller.
bool GetSquareButton() const
Read the value of the square button on the controller.
BooleanEvent Share(EventLoop *loop) const
Constructs an event instance around the share button's digital signal.
double GetLeftY() const
Get the Y axis value of left side of the controller.
bool GetR2Button() const
Read the value of the right trigger 2 button on the controller.
double GetR2Axis() const
Get the right trigger 2 axis value of the controller.
BooleanEvent R3(EventLoop *loop) const
Constructs an event instance around the R3 (right stick) button's digital signal.
bool GetOptionsButtonPressed()
Whether the options button was pressed since the last check.
BooleanEvent Circle(EventLoop *loop) const
Constructs an event instance around the circle button's digital signal.
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 NiDsPS4Controller.
Definition NiDsPS4Controller.hpp:558
static constexpr int kL2
Left trigger 2.
Definition NiDsPS4Controller.hpp:568
static constexpr int kR2
Right trigger 2.
Definition NiDsPS4Controller.hpp:570
static constexpr int kLeftY
Left Y axis.
Definition NiDsPS4Controller.hpp:562
static constexpr int kRightY
Right Y axis.
Definition NiDsPS4Controller.hpp:566
static constexpr int kRightX
Right X axis.
Definition NiDsPS4Controller.hpp:564
static constexpr int kLeftX
Left X axis.
Definition NiDsPS4Controller.hpp:560
Represents a digital button on an NiDsPS4Controller.
Definition NiDsPS4Controller.hpp:526
static constexpr int kOptions
Options button.
Definition NiDsPS4Controller.hpp:546
static constexpr int kPS
PlayStation button.
Definition NiDsPS4Controller.hpp:552
static constexpr int kR2
Right trigger 2 button.
Definition NiDsPS4Controller.hpp:542
static constexpr int kR3
R3 (right stick) button.
Definition NiDsPS4Controller.hpp:550
static constexpr int kL3
L3 (left stick) button.
Definition NiDsPS4Controller.hpp:548
static constexpr int kShare
Share button.
Definition NiDsPS4Controller.hpp:544
static constexpr int kL1
Left trigger 1 button.
Definition NiDsPS4Controller.hpp:536
static constexpr int kL2
Left trigger 2 button.
Definition NiDsPS4Controller.hpp:540
static constexpr int kSquare
Square button.
Definition NiDsPS4Controller.hpp:528
static constexpr int kCross
Cross button.
Definition NiDsPS4Controller.hpp:530
static constexpr int kTriangle
Triangle button.
Definition NiDsPS4Controller.hpp:534
static constexpr int kTouchpad
Touchpad button.
Definition NiDsPS4Controller.hpp:554
static constexpr int kCircle
Circle button.
Definition NiDsPS4Controller.hpp:532
static constexpr int kR1
Right trigger 1 button.
Definition NiDsPS4Controller.hpp:538