blob: b294257c72dc167df36fb037306d15f6b3beddb3 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
James Kuszmaul4b81d302019-12-14 20:53:14 -08002/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
Brian Silverman41cdd3e2019-01-19 19:48:58 -08003/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "frc/XboxController.h"
9
James Kuszmaul4b81d302019-12-14 20:53:14 -080010#include <hal/FRCUsageReporting.h>
Brian Silverman41cdd3e2019-01-19 19:48:58 -080011
12using namespace frc;
13
14XboxController::XboxController(int port) : GenericHID(port) {
James Kuszmaul4b81d302019-12-14 20:53:14 -080015 HAL_Report(HALUsageReporting::kResourceType_XboxController, port + 1);
Brian Silverman41cdd3e2019-01-19 19:48:58 -080016}
17
18double XboxController::GetX(JoystickHand hand) const {
19 if (hand == kLeftHand) {
20 return GetRawAxis(0);
21 } else {
22 return GetRawAxis(4);
23 }
24}
25
26double XboxController::GetY(JoystickHand hand) const {
27 if (hand == kLeftHand) {
28 return GetRawAxis(1);
29 } else {
30 return GetRawAxis(5);
31 }
32}
33
34double XboxController::GetTriggerAxis(JoystickHand hand) const {
35 if (hand == kLeftHand) {
36 return GetRawAxis(2);
37 } else {
38 return GetRawAxis(3);
39 }
40}
41
42bool XboxController::GetBumper(JoystickHand hand) const {
43 if (hand == kLeftHand) {
44 return GetRawButton(static_cast<int>(Button::kBumperLeft));
45 } else {
46 return GetRawButton(static_cast<int>(Button::kBumperRight));
47 }
48}
49
50bool XboxController::GetBumperPressed(JoystickHand hand) {
51 if (hand == kLeftHand) {
52 return GetRawButtonPressed(static_cast<int>(Button::kBumperLeft));
53 } else {
54 return GetRawButtonPressed(static_cast<int>(Button::kBumperRight));
55 }
56}
57
58bool XboxController::GetBumperReleased(JoystickHand hand) {
59 if (hand == kLeftHand) {
60 return GetRawButtonReleased(static_cast<int>(Button::kBumperLeft));
61 } else {
62 return GetRawButtonReleased(static_cast<int>(Button::kBumperRight));
63 }
64}
65
66bool XboxController::GetStickButton(JoystickHand hand) const {
67 if (hand == kLeftHand) {
68 return GetRawButton(static_cast<int>(Button::kStickLeft));
69 } else {
70 return GetRawButton(static_cast<int>(Button::kStickRight));
71 }
72}
73
74bool XboxController::GetStickButtonPressed(JoystickHand hand) {
75 if (hand == kLeftHand) {
76 return GetRawButtonPressed(static_cast<int>(Button::kStickLeft));
77 } else {
78 return GetRawButtonPressed(static_cast<int>(Button::kStickRight));
79 }
80}
81
82bool XboxController::GetStickButtonReleased(JoystickHand hand) {
83 if (hand == kLeftHand) {
84 return GetRawButtonReleased(static_cast<int>(Button::kStickLeft));
85 } else {
86 return GetRawButtonReleased(static_cast<int>(Button::kStickRight));
87 }
88}
89
90bool XboxController::GetAButton() const {
91 return GetRawButton(static_cast<int>(Button::kA));
92}
93
94bool XboxController::GetAButtonPressed() {
95 return GetRawButtonPressed(static_cast<int>(Button::kA));
96}
97
98bool XboxController::GetAButtonReleased() {
99 return GetRawButtonReleased(static_cast<int>(Button::kA));
100}
101
102bool XboxController::GetBButton() const {
103 return GetRawButton(static_cast<int>(Button::kB));
104}
105
106bool XboxController::GetBButtonPressed() {
107 return GetRawButtonPressed(static_cast<int>(Button::kB));
108}
109
110bool XboxController::GetBButtonReleased() {
111 return GetRawButtonReleased(static_cast<int>(Button::kB));
112}
113
114bool XboxController::GetXButton() const {
115 return GetRawButton(static_cast<int>(Button::kX));
116}
117
118bool XboxController::GetXButtonPressed() {
119 return GetRawButtonPressed(static_cast<int>(Button::kX));
120}
121
122bool XboxController::GetXButtonReleased() {
123 return GetRawButtonReleased(static_cast<int>(Button::kX));
124}
125
126bool XboxController::GetYButton() const {
127 return GetRawButton(static_cast<int>(Button::kY));
128}
129
130bool XboxController::GetYButtonPressed() {
131 return GetRawButtonPressed(static_cast<int>(Button::kY));
132}
133
134bool XboxController::GetYButtonReleased() {
135 return GetRawButtonReleased(static_cast<int>(Button::kY));
136}
137
138bool XboxController::GetBackButton() const {
139 return GetRawButton(static_cast<int>(Button::kBack));
140}
141
142bool XboxController::GetBackButtonPressed() {
143 return GetRawButtonPressed(static_cast<int>(Button::kBack));
144}
145
146bool XboxController::GetBackButtonReleased() {
147 return GetRawButtonReleased(static_cast<int>(Button::kBack));
148}
149
150bool XboxController::GetStartButton() const {
151 return GetRawButton(static_cast<int>(Button::kStart));
152}
153
154bool XboxController::GetStartButtonPressed() {
155 return GetRawButtonPressed(static_cast<int>(Button::kStart));
156}
157
158bool XboxController::GetStartButtonReleased() {
159 return GetRawButtonReleased(static_cast<int>(Button::kStart));
160}