1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
/**
* Handle input from PS4 controllers connected to the Driver Station.
*
* This class handles PS4 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 Sony 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.
*/
class PS4Controller : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<PS4Controller> {
public:
/**
* Construct an instance of a controller.
*
* The controller index is the USB port on the Driver Station.
*
* @param port The port on the Driver Station that the controller is plugged
* into (0-5).
*/
explicit PS4Controller(int port);
~PS4Controller() override = default;
PS4Controller(PS4Controller&&) = default;
PS4Controller& operator=(PS4Controller&&) = default;
/**
* Get the X axis value of left side of the controller. Right is positive.
*
* @return the axis value.
*/
double GetLeftX() const;
/**
* Get the Y axis value of left side of the controller. Back is positive.
*
* @return the axis value.
*/
double GetLeftY() const;
/**
* Get the X axis value of right side of the controller. Right is positive.
*
* @return the axis value.
*/
double GetRightX() const;
/**
* Get the Y axis value of right side of the controller. Back is positive.
*
* @return the axis value.
*/
double GetRightY() const;
/**
* Get the left trigger 2 axis value of the controller. Note that this axis
* is bound to the range of [0, 1] as opposed to the usual [-1, 1].
*
* @return the axis value.
*/
double GetL2Axis() const;
/**
* Get the right trigger 2 axis value of the controller. Note that this axis
* is bound to the range of [0, 1] as opposed to the usual [-1, 1].
*
* @return the axis value.
*/
double GetR2Axis() const;
/**
* Read the value of the square button on the controller.
*
* @return The state of the button.
*/
bool GetSquareButton() const;
/**
* Whether the square button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetSquareButtonPressed();
/**
* Whether the square button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetSquareButtonReleased();
/**
* Constructs an event instance around the square button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the square button's
* digital signal attached to the given loop.
*/
BooleanEvent Square(EventLoop* loop) const;
/**
* Read the value of the cross button on the controller.
*
* @return The state of the button.
*/
bool GetCrossButton() const;
/**
* Whether the cross button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetCrossButtonPressed();
/**
* Whether the cross button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetCrossButtonReleased();
/**
* Constructs an event instance around the cross button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the cross button's
* digital signal attached to the given loop.
*/
BooleanEvent Cross(EventLoop* loop) const;
/**
* Read the value of the circle button on the controller.
*
* @return The state of the button.
*/
bool GetCircleButton() const;
/**
* Whether the circle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetCircleButtonPressed();
/**
* Whether the circle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetCircleButtonReleased();
/**
* Constructs an event instance around the circle button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the circle button's
* digital signal attached to the given loop.
*/
BooleanEvent Circle(EventLoop* loop) const;
/**
* Read the value of the triangle button on the controller.
*
* @return The state of the button.
*/
bool GetTriangleButton() const;
/**
* Whether the triangle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetTriangleButtonPressed();
/**
* Whether the triangle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetTriangleButtonReleased();
/**
* Constructs an event instance around the triangle button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the triangle button's
* digital signal attached to the given loop.
*/
BooleanEvent Triangle(EventLoop* loop) const;
/**
* Read the value of the left trigger 1 button on the controller.
*
* @return The state of the button.
*/
bool GetL1Button() const;
/**
* Whether the left trigger 1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetL1ButtonPressed();
/**
* Whether the left trigger 1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetL1ButtonReleased();
/**
* Constructs an event instance around the left trigger 1 button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger 1 button's
* digital signal attached to the given loop.
*/
BooleanEvent L1(EventLoop* loop) const;
/**
* Read the value of the right trigger 1 button on the controller.
*
* @return The state of the button.
*/
bool GetR1Button() const;
/**
* Whether the right trigger 1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetR1ButtonPressed();
/**
* Whether the right trigger 1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetR1ButtonReleased();
/**
* Constructs an event instance around the right trigger 1 button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger 1 button's
* digital signal attached to the given loop.
*/
BooleanEvent R1(EventLoop* loop) const;
/**
* Read the value of the left trigger 2 button on the controller.
*
* @return The state of the button.
*/
bool GetL2Button() const;
/**
* Whether the left trigger 2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetL2ButtonPressed();
/**
* Whether the left trigger 2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetL2ButtonReleased();
/**
* Constructs an event instance around the left trigger 2 button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger 2 button's
* digital signal attached to the given loop.
*/
BooleanEvent L2(EventLoop* loop) const;
/**
* Read the value of the right trigger 2 button on the controller.
*
* @return The state of the button.
*/
bool GetR2Button() const;
/**
* Whether the right trigger 2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetR2ButtonPressed();
/**
* Whether the right trigger 2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetR2ButtonReleased();
/**
* Constructs an event instance around the right trigger 2 button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger 2 button's
* digital signal attached to the given loop.
*/
BooleanEvent R2(EventLoop* loop) const;
/**
* Read the value of the share button on the controller.
*
* @return The state of the button.
*/
bool GetShareButton() const;
/**
* Whether the share button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetShareButtonPressed();
/**
* Whether the share button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetShareButtonReleased();
/**
* Constructs an event instance around the share button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the share button's
* digital signal attached to the given loop.
*/
BooleanEvent Share(EventLoop* loop) const;
/**
* Read the value of the options button on the controller.
*
* @return The state of the button.
*/
bool GetOptionsButton() const;
/**
* Whether the options button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetOptionsButtonPressed();
/**
* Whether the options button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetOptionsButtonReleased();
/**
* Constructs an event instance around the options button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the options button's
* digital signal attached to the given loop.
*/
BooleanEvent Options(EventLoop* loop) const;
/**
* Read the value of the L3 (left stick) button on the controller.
*
* @return The state of the button.
*/
bool GetL3Button() const;
/**
* Whether the L3 (left stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetL3ButtonPressed();
/**
* Whether the L3 (left stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetL3ButtonReleased();
/**
* Constructs an event instance around the L3 (left stick) button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L3 (left stick) button's
* digital signal attached to the given loop.
*/
BooleanEvent L3(EventLoop* loop) const;
/**
* Read the value of the R3 (right stick) button on the controller.
*
* @return The state of the button.
*/
bool GetR3Button() const;
/**
* Whether the R3 (right stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetR3ButtonPressed();
/**
* Whether the R3 (right stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetR3ButtonReleased();
/**
* Constructs an event instance around the R3 (right stick) button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R3 (right stick) button's
* digital signal attached to the given loop.
*/
BooleanEvent R3(EventLoop* loop) const;
/**
* Read the value of the PlayStation button on the controller.
*
* @return The state of the button.
*/
bool GetPSButton() const;
/**
* Whether the PlayStation button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetPSButtonPressed();
/**
* Whether the PlayStation button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetPSButtonReleased();
/**
* Constructs an event instance around the PlayStation button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the PlayStation button's
* digital signal attached to the given loop.
*/
BooleanEvent PS(EventLoop* loop) const;
/**
* Read the value of the touchpad button on the controller.
*
* @return The state of the button.
*/
bool GetTouchpadButton() const;
/**
* Whether the touchpad button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
bool GetTouchpadButtonPressed();
/**
* Whether the touchpad button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
bool GetTouchpadButtonReleased();
/**
* Constructs an event instance around the touchpad button's
* digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the touchpad button's
* digital signal attached to the given loop.
*/
BooleanEvent Touchpad(EventLoop* loop) const;
/**
* Read the value of the touchpad button on the controller.
*
* @return The state of the button.
* @deprecated Use GetTouchpadButton instead. This function is deprecated for
* removal to make function names consistent to allow the HID classes to be
* automatically generated.
*/
[[deprecated("Use GetTouchpadButton instead")]]
bool GetTouchpad() const;
/**
* Whether the touchpad was pressed since the last check.
*
* @return Whether the touchpad was pressed since the last check.
* @deprecated Use GetTouchpadButtonPressed instead. This function is
* deprecated for removal to make function names consistent to allow the HID
* classes to be automatically generated.
*/
[[deprecated("Use GetTouchpadButtonPressed instead")]]
bool GetTouchpadPressed();
/**
* Whether the touchpad was released since the last check.
*
* @return Whether the touchpad was released since the last check.
* @deprecated Use GetLeftBumperButton instead. This function is deprecated
* for removal to make function names consistent to allow the HID classes to
* be automatically generated.
*/
[[deprecated("Use GetTouchpadButtonReleased instead")]]
bool GetTouchpadReleased();
/** Represents a digital button on an PS4Controller. */
struct Button {
/// Square button.
static constexpr int kSquare = 1;
/// Cross button.
static constexpr int kCross = 2;
/// Circle button.
static constexpr int kCircle = 3;
/// Triangle button.
static constexpr int kTriangle = 4;
/// Left trigger 1 button.
static constexpr int kL1 = 5;
/// Right trigger 1 button.
static constexpr int kR1 = 6;
/// Left trigger 2 button.
static constexpr int kL2 = 7;
/// Right trigger 2 button.
static constexpr int kR2 = 8;
/// Share button.
static constexpr int kShare = 9;
/// Options button.
static constexpr int kOptions = 10;
/// L3 (left stick) button.
static constexpr int kL3 = 11;
/// R3 (right stick) button.
static constexpr int kR3 = 12;
/// PlayStation button.
static constexpr int kPS = 13;
/// Touchpad button.
static constexpr int kTouchpad = 14;
};
/** Represents an axis on an PS4Controller. */
struct Axis {
/// Left X axis.
static constexpr int kLeftX = 0;
/// Left Y axis.
static constexpr int kLeftY = 1;
/// Right X axis.
static constexpr int kRightX = 2;
/// Right Y axis.
static constexpr int kRightY = 5;
/// Left trigger 2.
static constexpr int kL2 = 3;
/// Right trigger 2.
static constexpr int kR2 = 4;
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc