blob: 5ac3420756c1677524e836ef8d001f91f4f021b3 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// 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#include "frc/PS4Controller.h"
6
7#include <hal/FRCUsageReporting.h>
8
James Kuszmaulcf324122023-01-14 14:07:17 -08009#include "frc/event/BooleanEvent.h"
10
Austin Schuh812d0d12021-11-04 20:16:48 -070011using namespace frc;
12
13PS4Controller::PS4Controller(int port) : GenericHID(port) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080014 // re-enable when PS4Controller is added to Usage Reporting
15 // HAL_Report(HALUsageReporting::kResourceType_PS4Controller, port + 1);
Austin Schuh812d0d12021-11-04 20:16:48 -070016}
17
18double PS4Controller::GetLeftX() const {
19 return GetRawAxis(Axis::kLeftX);
20}
21
22double PS4Controller::GetRightX() const {
23 return GetRawAxis(Axis::kRightX);
24}
25
26double PS4Controller::GetLeftY() const {
27 return GetRawAxis(Axis::kLeftY);
28}
29
30double PS4Controller::GetRightY() const {
31 return GetRawAxis(Axis::kRightY);
32}
33
34double PS4Controller::GetL2Axis() const {
35 return GetRawAxis(Axis::kL2);
36}
37
38double PS4Controller::GetR2Axis() const {
39 return GetRawAxis(Axis::kR2);
40}
41
42bool PS4Controller::GetSquareButton() const {
43 return GetRawButton(Button::kSquare);
44}
45
46bool PS4Controller::GetSquareButtonPressed() {
47 return GetRawButtonPressed(Button::kSquare);
48}
49
50bool PS4Controller::GetSquareButtonReleased() {
51 return GetRawButtonReleased(Button::kSquare);
52}
53
James Kuszmaulcf324122023-01-14 14:07:17 -080054BooleanEvent PS4Controller::Square(EventLoop* loop) const {
55 return BooleanEvent(loop, [this]() { return this->GetSquareButton(); });
56}
57
Austin Schuh812d0d12021-11-04 20:16:48 -070058bool PS4Controller::GetCrossButton() const {
59 return GetRawButton(Button::kCross);
60}
61
62bool PS4Controller::GetCrossButtonPressed() {
63 return GetRawButtonPressed(Button::kCross);
64}
65
66bool PS4Controller::GetCrossButtonReleased() {
67 return GetRawButtonReleased(Button::kCross);
68}
69
James Kuszmaulcf324122023-01-14 14:07:17 -080070BooleanEvent PS4Controller::Cross(EventLoop* loop) const {
71 return BooleanEvent(loop, [this]() { return this->GetCrossButton(); });
72}
73
Austin Schuh812d0d12021-11-04 20:16:48 -070074bool PS4Controller::GetCircleButton() const {
75 return GetRawButton(Button::kCircle);
76}
77
78bool PS4Controller::GetCircleButtonPressed() {
79 return GetRawButtonPressed(Button::kCircle);
80}
81
82bool PS4Controller::GetCircleButtonReleased() {
83 return GetRawButtonReleased(Button::kCircle);
84}
85
James Kuszmaulcf324122023-01-14 14:07:17 -080086BooleanEvent PS4Controller::Circle(EventLoop* loop) const {
87 return BooleanEvent(loop, [this]() { return this->GetCircleButton(); });
88}
89
Austin Schuh812d0d12021-11-04 20:16:48 -070090bool PS4Controller::GetTriangleButton() const {
91 return GetRawButton(Button::kTriangle);
92}
93
94bool PS4Controller::GetTriangleButtonPressed() {
95 return GetRawButtonPressed(Button::kTriangle);
96}
97
98bool PS4Controller::GetTriangleButtonReleased() {
99 return GetRawButtonReleased(Button::kTriangle);
100}
101
James Kuszmaulcf324122023-01-14 14:07:17 -0800102BooleanEvent PS4Controller::Triangle(EventLoop* loop) const {
103 return BooleanEvent(loop, [this]() { return this->GetTriangleButton(); });
104}
105
Austin Schuh812d0d12021-11-04 20:16:48 -0700106bool PS4Controller::GetL1Button() const {
107 return GetRawButton(Button::kL1);
108}
109
110bool PS4Controller::GetL1ButtonPressed() {
111 return GetRawButtonPressed(Button::kL1);
112}
113
114bool PS4Controller::GetL1ButtonReleased() {
115 return GetRawButtonReleased(Button::kL1);
116}
117
James Kuszmaulcf324122023-01-14 14:07:17 -0800118BooleanEvent PS4Controller::L1(EventLoop* loop) const {
119 return BooleanEvent(loop, [this]() { return this->GetL1Button(); });
120}
121
Austin Schuh812d0d12021-11-04 20:16:48 -0700122bool PS4Controller::GetR1Button() const {
123 return GetRawButton(Button::kR1);
124}
125
126bool PS4Controller::GetR1ButtonPressed() {
127 return GetRawButtonPressed(Button::kR1);
128}
129
130bool PS4Controller::GetR1ButtonReleased() {
131 return GetRawButtonReleased(Button::kR1);
132}
133
James Kuszmaulcf324122023-01-14 14:07:17 -0800134BooleanEvent PS4Controller::R1(EventLoop* loop) const {
135 return BooleanEvent(loop, [this]() { return this->GetR1Button(); });
136}
137
Austin Schuh812d0d12021-11-04 20:16:48 -0700138bool PS4Controller::GetL2Button() const {
139 return GetRawButton(Button::kL2);
140}
141
142bool PS4Controller::GetL2ButtonPressed() {
143 return GetRawButtonPressed(Button::kL2);
144}
145
146bool PS4Controller::GetL2ButtonReleased() {
147 return GetRawButtonReleased(Button::kL2);
148}
149
James Kuszmaulcf324122023-01-14 14:07:17 -0800150BooleanEvent PS4Controller::L2(EventLoop* loop) const {
151 return BooleanEvent(loop, [this]() { return this->GetL2Button(); });
152}
153
Austin Schuh812d0d12021-11-04 20:16:48 -0700154bool PS4Controller::GetR2Button() const {
155 return GetRawButton(Button::kR2);
156}
157
158bool PS4Controller::GetR2ButtonPressed() {
159 return GetRawButtonPressed(Button::kR2);
160}
161
162bool PS4Controller::GetR2ButtonReleased() {
163 return GetRawButtonReleased(Button::kR2);
164}
165
James Kuszmaulcf324122023-01-14 14:07:17 -0800166BooleanEvent PS4Controller::R2(EventLoop* loop) const {
167 return BooleanEvent(loop, [this]() { return this->GetR2Button(); });
168}
169
Austin Schuh812d0d12021-11-04 20:16:48 -0700170bool PS4Controller::GetShareButton() const {
171 return GetRawButton(Button::kShare);
172}
173
174bool PS4Controller::GetShareButtonPressed() {
175 return GetRawButtonPressed(Button::kShare);
176}
177
178bool PS4Controller::GetShareButtonReleased() {
179 return GetRawButtonReleased(Button::kShare);
180}
181
James Kuszmaulcf324122023-01-14 14:07:17 -0800182BooleanEvent PS4Controller::Share(EventLoop* loop) const {
183 return BooleanEvent(loop, [this]() { return this->GetShareButton(); });
184}
185
Austin Schuh812d0d12021-11-04 20:16:48 -0700186bool PS4Controller::GetOptionsButton() const {
187 return GetRawButton(Button::kOptions);
188}
189
190bool PS4Controller::GetOptionsButtonPressed() {
191 return GetRawButtonPressed(Button::kOptions);
192}
193
194bool PS4Controller::GetOptionsButtonReleased() {
195 return GetRawButtonReleased(Button::kOptions);
196}
197
James Kuszmaulcf324122023-01-14 14:07:17 -0800198BooleanEvent PS4Controller::Options(EventLoop* loop) const {
199 return BooleanEvent(loop, [this]() { return this->GetOptionsButton(); });
200}
201
Austin Schuh812d0d12021-11-04 20:16:48 -0700202bool PS4Controller::GetL3Button() const {
203 return GetRawButton(Button::kL3);
204}
205
206bool PS4Controller::GetL3ButtonPressed() {
207 return GetRawButtonPressed(Button::kL3);
208}
209
210bool PS4Controller::GetL3ButtonReleased() {
211 return GetRawButtonReleased(Button::kL3);
212}
213
James Kuszmaulcf324122023-01-14 14:07:17 -0800214BooleanEvent PS4Controller::L3(EventLoop* loop) const {
215 return BooleanEvent(loop, [this]() { return this->GetL3Button(); });
216}
217
Austin Schuh812d0d12021-11-04 20:16:48 -0700218bool PS4Controller::GetR3Button() const {
219 return GetRawButton(Button::kR3);
220}
221
222bool PS4Controller::GetR3ButtonPressed() {
223 return GetRawButtonPressed(Button::kR3);
224}
225
226bool PS4Controller::GetR3ButtonReleased() {
227 return GetRawButtonReleased(Button::kR3);
228}
229
James Kuszmaulcf324122023-01-14 14:07:17 -0800230BooleanEvent PS4Controller::R3(EventLoop* loop) const {
231 return BooleanEvent(loop, [this]() { return this->GetR3Button(); });
232}
233
Austin Schuh812d0d12021-11-04 20:16:48 -0700234bool PS4Controller::GetPSButton() const {
235 return GetRawButton(Button::kPS);
236}
237
238bool PS4Controller::GetPSButtonPressed() {
239 return GetRawButtonPressed(Button::kPS);
240}
241
242bool PS4Controller::GetPSButtonReleased() {
243 return GetRawButtonReleased(Button::kPS);
244}
245
James Kuszmaulcf324122023-01-14 14:07:17 -0800246BooleanEvent PS4Controller::PS(EventLoop* loop) const {
247 return BooleanEvent(loop, [this]() { return this->GetPSButton(); });
248}
249
Austin Schuh812d0d12021-11-04 20:16:48 -0700250bool PS4Controller::GetTouchpad() const {
251 return GetRawButton(Button::kTouchpad);
252}
253
254bool PS4Controller::GetTouchpadPressed() {
255 return GetRawButtonPressed(Button::kTouchpad);
256}
257
258bool PS4Controller::GetTouchpadReleased() {
259 return GetRawButtonReleased(Button::kTouchpad);
260}
James Kuszmaulcf324122023-01-14 14:07:17 -0800261
262BooleanEvent PS4Controller::Touchpad(EventLoop* loop) const {
263 return BooleanEvent(loop, [this]() { return this->GetTouchpad(); });
264}