blob: aa494ddc7bf48e4491cfd98132724f46a85e5665 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2016-2017. All Rights Reserved. */
3/* 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 "XboxController.h"
9
10#include "DriverStation.h"
11#include "HAL/HAL.h"
12
13using namespace frc;
14
15/**
16 * Construct an instance of an Xbox controller.
17 *
18 * The joystick index is the USB port on the Driver Station.
19 *
20 * @param port The port on the Driver Station that the joystick is plugged into
21 * (0-5).
22 */
23XboxController::XboxController(int port)
24 : GamepadBase(port), m_ds(DriverStation::GetInstance()) {
25 // HAL_Report(HALUsageReporting::kResourceType_XboxController, port);
26 HAL_Report(HALUsageReporting::kResourceType_Joystick, port);
27}
28
29/**
30 * Get the X axis value of the controller.
31 *
32 * @param hand Side of controller whose value should be returned.
33 */
34double XboxController::GetX(JoystickHand hand) const {
35 if (hand == kLeftHand) {
36 return GetRawAxis(0);
37 } else {
38 return GetRawAxis(4);
39 }
40}
41
42/**
43 * Get the Y axis value of the controller.
44 *
45 * @param hand Side of controller whose value should be returned.
46 */
47double XboxController::GetY(JoystickHand hand) const {
48 if (hand == kLeftHand) {
49 return GetRawAxis(1);
50 } else {
51 return GetRawAxis(5);
52 }
53}
54
55/**
56 * Read the value of the bumper button on the controller.
57 *
58 * @param hand Side of controller whose value should be returned.
59 */
60bool XboxController::GetBumper(JoystickHand hand) const {
61 if (hand == kLeftHand) {
62 return GetRawButton(5);
63 } else {
64 return GetRawButton(6);
65 }
66}
67
68/**
69 * Read the value of the stick button on the controller.
70 *
71 * @param hand Side of controller whose value should be returned.
72 * @return The state of the button.
73 */
74bool XboxController::GetStickButton(JoystickHand hand) const {
75 if (hand == kLeftHand) {
76 return GetRawButton(9);
77 } else {
78 return GetRawButton(10);
79 }
80}
81
82/**
83 * Get the trigger axis value of the controller.
84 *
85 * @param hand Side of controller whose value should be returned.
86 */
87double XboxController::GetTriggerAxis(JoystickHand hand) const {
88 if (hand == kLeftHand) {
89 return GetRawAxis(2);
90 } else {
91 return GetRawAxis(3);
92 }
93}
94
95/**
96 * Read the value of the A button on the controller.
97 *
98 * @param hand Side of controller whose value should be returned.
99 * @return The state of the button.
100 */
101bool XboxController::GetAButton() const { return GetRawButton(1); }
102
103/**
104 * Read the value of the B button on the controller.
105 *
106 * @param hand Side of controller whose value should be returned.
107 * @return The state of the button.
108 */
109bool XboxController::GetBButton() const { return GetRawButton(2); }
110
111/**
112 * Read the value of the X button on the controller.
113 *
114 * @param hand Side of controller whose value should be returned.
115 * @return The state of the button.
116 */
117bool XboxController::GetXButton() const { return GetRawButton(3); }
118
119/**
120 * Read the value of the Y button on the controller.
121 *
122 * @param hand Side of controller whose value should be returned.
123 * @return The state of the button.
124 */
125bool XboxController::GetYButton() const { return GetRawButton(4); }
126
127/**
128 * Read the value of the back button on the controller.
129 *
130 * @param hand Side of controller whose value should be returned.
131 * @return The state of the button.
132 */
133bool XboxController::GetBackButton() const { return GetRawButton(7); }
134
135/**
136 * Read the value of the start button on the controller.
137 *
138 * @param hand Side of controller whose value should be returned.
139 * @return The state of the button.
140 */
141bool XboxController::GetStartButton() const { return GetRawButton(8); }