blob: e59e18cd3b3523d37b02dbf9c41f5862e549be14 [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) {
14 HAL_Report(HALUsageReporting::kResourceType_PS4Controller, port + 1);
15}
16
17double PS4Controller::GetLeftX() const {
18 return GetRawAxis(Axis::kLeftX);
19}
20
21double PS4Controller::GetRightX() const {
22 return GetRawAxis(Axis::kRightX);
23}
24
25double PS4Controller::GetLeftY() const {
26 return GetRawAxis(Axis::kLeftY);
27}
28
29double PS4Controller::GetRightY() const {
30 return GetRawAxis(Axis::kRightY);
31}
32
33double PS4Controller::GetL2Axis() const {
34 return GetRawAxis(Axis::kL2);
35}
36
37double PS4Controller::GetR2Axis() const {
38 return GetRawAxis(Axis::kR2);
39}
40
41bool PS4Controller::GetSquareButton() const {
42 return GetRawButton(Button::kSquare);
43}
44
45bool PS4Controller::GetSquareButtonPressed() {
46 return GetRawButtonPressed(Button::kSquare);
47}
48
49bool PS4Controller::GetSquareButtonReleased() {
50 return GetRawButtonReleased(Button::kSquare);
51}
52
James Kuszmaulcf324122023-01-14 14:07:17 -080053BooleanEvent PS4Controller::Square(EventLoop* loop) const {
54 return BooleanEvent(loop, [this]() { return this->GetSquareButton(); });
55}
56
Austin Schuh812d0d12021-11-04 20:16:48 -070057bool PS4Controller::GetCrossButton() const {
58 return GetRawButton(Button::kCross);
59}
60
61bool PS4Controller::GetCrossButtonPressed() {
62 return GetRawButtonPressed(Button::kCross);
63}
64
65bool PS4Controller::GetCrossButtonReleased() {
66 return GetRawButtonReleased(Button::kCross);
67}
68
James Kuszmaulcf324122023-01-14 14:07:17 -080069BooleanEvent PS4Controller::Cross(EventLoop* loop) const {
70 return BooleanEvent(loop, [this]() { return this->GetCrossButton(); });
71}
72
Austin Schuh812d0d12021-11-04 20:16:48 -070073bool PS4Controller::GetCircleButton() const {
74 return GetRawButton(Button::kCircle);
75}
76
77bool PS4Controller::GetCircleButtonPressed() {
78 return GetRawButtonPressed(Button::kCircle);
79}
80
81bool PS4Controller::GetCircleButtonReleased() {
82 return GetRawButtonReleased(Button::kCircle);
83}
84
James Kuszmaulcf324122023-01-14 14:07:17 -080085BooleanEvent PS4Controller::Circle(EventLoop* loop) const {
86 return BooleanEvent(loop, [this]() { return this->GetCircleButton(); });
87}
88
Austin Schuh812d0d12021-11-04 20:16:48 -070089bool PS4Controller::GetTriangleButton() const {
90 return GetRawButton(Button::kTriangle);
91}
92
93bool PS4Controller::GetTriangleButtonPressed() {
94 return GetRawButtonPressed(Button::kTriangle);
95}
96
97bool PS4Controller::GetTriangleButtonReleased() {
98 return GetRawButtonReleased(Button::kTriangle);
99}
100
James Kuszmaulcf324122023-01-14 14:07:17 -0800101BooleanEvent PS4Controller::Triangle(EventLoop* loop) const {
102 return BooleanEvent(loop, [this]() { return this->GetTriangleButton(); });
103}
104
Austin Schuh812d0d12021-11-04 20:16:48 -0700105bool PS4Controller::GetL1Button() const {
106 return GetRawButton(Button::kL1);
107}
108
109bool PS4Controller::GetL1ButtonPressed() {
110 return GetRawButtonPressed(Button::kL1);
111}
112
113bool PS4Controller::GetL1ButtonReleased() {
114 return GetRawButtonReleased(Button::kL1);
115}
116
James Kuszmaulcf324122023-01-14 14:07:17 -0800117BooleanEvent PS4Controller::L1(EventLoop* loop) const {
118 return BooleanEvent(loop, [this]() { return this->GetL1Button(); });
119}
120
Austin Schuh812d0d12021-11-04 20:16:48 -0700121bool PS4Controller::GetR1Button() const {
122 return GetRawButton(Button::kR1);
123}
124
125bool PS4Controller::GetR1ButtonPressed() {
126 return GetRawButtonPressed(Button::kR1);
127}
128
129bool PS4Controller::GetR1ButtonReleased() {
130 return GetRawButtonReleased(Button::kR1);
131}
132
James Kuszmaulcf324122023-01-14 14:07:17 -0800133BooleanEvent PS4Controller::R1(EventLoop* loop) const {
134 return BooleanEvent(loop, [this]() { return this->GetR1Button(); });
135}
136
Austin Schuh812d0d12021-11-04 20:16:48 -0700137bool PS4Controller::GetL2Button() const {
138 return GetRawButton(Button::kL2);
139}
140
141bool PS4Controller::GetL2ButtonPressed() {
142 return GetRawButtonPressed(Button::kL2);
143}
144
145bool PS4Controller::GetL2ButtonReleased() {
146 return GetRawButtonReleased(Button::kL2);
147}
148
James Kuszmaulcf324122023-01-14 14:07:17 -0800149BooleanEvent PS4Controller::L2(EventLoop* loop) const {
150 return BooleanEvent(loop, [this]() { return this->GetL2Button(); });
151}
152
Austin Schuh812d0d12021-11-04 20:16:48 -0700153bool PS4Controller::GetR2Button() const {
154 return GetRawButton(Button::kR2);
155}
156
157bool PS4Controller::GetR2ButtonPressed() {
158 return GetRawButtonPressed(Button::kR2);
159}
160
161bool PS4Controller::GetR2ButtonReleased() {
162 return GetRawButtonReleased(Button::kR2);
163}
164
James Kuszmaulcf324122023-01-14 14:07:17 -0800165BooleanEvent PS4Controller::R2(EventLoop* loop) const {
166 return BooleanEvent(loop, [this]() { return this->GetR2Button(); });
167}
168
Austin Schuh812d0d12021-11-04 20:16:48 -0700169bool PS4Controller::GetShareButton() const {
170 return GetRawButton(Button::kShare);
171}
172
173bool PS4Controller::GetShareButtonPressed() {
174 return GetRawButtonPressed(Button::kShare);
175}
176
177bool PS4Controller::GetShareButtonReleased() {
178 return GetRawButtonReleased(Button::kShare);
179}
180
James Kuszmaulcf324122023-01-14 14:07:17 -0800181BooleanEvent PS4Controller::Share(EventLoop* loop) const {
182 return BooleanEvent(loop, [this]() { return this->GetShareButton(); });
183}
184
Austin Schuh812d0d12021-11-04 20:16:48 -0700185bool PS4Controller::GetOptionsButton() const {
186 return GetRawButton(Button::kOptions);
187}
188
189bool PS4Controller::GetOptionsButtonPressed() {
190 return GetRawButtonPressed(Button::kOptions);
191}
192
193bool PS4Controller::GetOptionsButtonReleased() {
194 return GetRawButtonReleased(Button::kOptions);
195}
196
James Kuszmaulcf324122023-01-14 14:07:17 -0800197BooleanEvent PS4Controller::Options(EventLoop* loop) const {
198 return BooleanEvent(loop, [this]() { return this->GetOptionsButton(); });
199}
200
Austin Schuh812d0d12021-11-04 20:16:48 -0700201bool PS4Controller::GetL3Button() const {
202 return GetRawButton(Button::kL3);
203}
204
205bool PS4Controller::GetL3ButtonPressed() {
206 return GetRawButtonPressed(Button::kL3);
207}
208
209bool PS4Controller::GetL3ButtonReleased() {
210 return GetRawButtonReleased(Button::kL3);
211}
212
James Kuszmaulcf324122023-01-14 14:07:17 -0800213BooleanEvent PS4Controller::L3(EventLoop* loop) const {
214 return BooleanEvent(loop, [this]() { return this->GetL3Button(); });
215}
216
Austin Schuh812d0d12021-11-04 20:16:48 -0700217bool PS4Controller::GetR3Button() const {
218 return GetRawButton(Button::kR3);
219}
220
221bool PS4Controller::GetR3ButtonPressed() {
222 return GetRawButtonPressed(Button::kR3);
223}
224
225bool PS4Controller::GetR3ButtonReleased() {
226 return GetRawButtonReleased(Button::kR3);
227}
228
James Kuszmaulcf324122023-01-14 14:07:17 -0800229BooleanEvent PS4Controller::R3(EventLoop* loop) const {
230 return BooleanEvent(loop, [this]() { return this->GetR3Button(); });
231}
232
Austin Schuh812d0d12021-11-04 20:16:48 -0700233bool PS4Controller::GetPSButton() const {
234 return GetRawButton(Button::kPS);
235}
236
237bool PS4Controller::GetPSButtonPressed() {
238 return GetRawButtonPressed(Button::kPS);
239}
240
241bool PS4Controller::GetPSButtonReleased() {
242 return GetRawButtonReleased(Button::kPS);
243}
244
James Kuszmaulcf324122023-01-14 14:07:17 -0800245BooleanEvent PS4Controller::PS(EventLoop* loop) const {
246 return BooleanEvent(loop, [this]() { return this->GetPSButton(); });
247}
248
Austin Schuh812d0d12021-11-04 20:16:48 -0700249bool PS4Controller::GetTouchpad() const {
250 return GetRawButton(Button::kTouchpad);
251}
252
253bool PS4Controller::GetTouchpadPressed() {
254 return GetRawButtonPressed(Button::kTouchpad);
255}
256
257bool PS4Controller::GetTouchpadReleased() {
258 return GetRawButtonReleased(Button::kTouchpad);
259}
James Kuszmaulcf324122023-01-14 14:07:17 -0800260
261BooleanEvent PS4Controller::Touchpad(EventLoop* loop) const {
262 return BooleanEvent(loop, [this]() { return this->GetTouchpad(); });
263}