Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 2 | /* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 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 "frc/XboxController.h" |
| 9 | |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 10 | #include <hal/FRCUsageReporting.h> |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | XboxController::XboxController(int port) : GenericHID(port) { |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 15 | HAL_Report(HALUsageReporting::kResourceType_XboxController, port + 1); |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | double XboxController::GetX(JoystickHand hand) const { |
| 19 | if (hand == kLeftHand) { |
| 20 | return GetRawAxis(0); |
| 21 | } else { |
| 22 | return GetRawAxis(4); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | double XboxController::GetY(JoystickHand hand) const { |
| 27 | if (hand == kLeftHand) { |
| 28 | return GetRawAxis(1); |
| 29 | } else { |
| 30 | return GetRawAxis(5); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | double XboxController::GetTriggerAxis(JoystickHand hand) const { |
| 35 | if (hand == kLeftHand) { |
| 36 | return GetRawAxis(2); |
| 37 | } else { |
| 38 | return GetRawAxis(3); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | bool 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 | |
| 50 | bool 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 | |
| 58 | bool 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 | |
| 66 | bool 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 | |
| 74 | bool 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 | |
| 82 | bool 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 | |
| 90 | bool XboxController::GetAButton() const { |
| 91 | return GetRawButton(static_cast<int>(Button::kA)); |
| 92 | } |
| 93 | |
| 94 | bool XboxController::GetAButtonPressed() { |
| 95 | return GetRawButtonPressed(static_cast<int>(Button::kA)); |
| 96 | } |
| 97 | |
| 98 | bool XboxController::GetAButtonReleased() { |
| 99 | return GetRawButtonReleased(static_cast<int>(Button::kA)); |
| 100 | } |
| 101 | |
| 102 | bool XboxController::GetBButton() const { |
| 103 | return GetRawButton(static_cast<int>(Button::kB)); |
| 104 | } |
| 105 | |
| 106 | bool XboxController::GetBButtonPressed() { |
| 107 | return GetRawButtonPressed(static_cast<int>(Button::kB)); |
| 108 | } |
| 109 | |
| 110 | bool XboxController::GetBButtonReleased() { |
| 111 | return GetRawButtonReleased(static_cast<int>(Button::kB)); |
| 112 | } |
| 113 | |
| 114 | bool XboxController::GetXButton() const { |
| 115 | return GetRawButton(static_cast<int>(Button::kX)); |
| 116 | } |
| 117 | |
| 118 | bool XboxController::GetXButtonPressed() { |
| 119 | return GetRawButtonPressed(static_cast<int>(Button::kX)); |
| 120 | } |
| 121 | |
| 122 | bool XboxController::GetXButtonReleased() { |
| 123 | return GetRawButtonReleased(static_cast<int>(Button::kX)); |
| 124 | } |
| 125 | |
| 126 | bool XboxController::GetYButton() const { |
| 127 | return GetRawButton(static_cast<int>(Button::kY)); |
| 128 | } |
| 129 | |
| 130 | bool XboxController::GetYButtonPressed() { |
| 131 | return GetRawButtonPressed(static_cast<int>(Button::kY)); |
| 132 | } |
| 133 | |
| 134 | bool XboxController::GetYButtonReleased() { |
| 135 | return GetRawButtonReleased(static_cast<int>(Button::kY)); |
| 136 | } |
| 137 | |
| 138 | bool XboxController::GetBackButton() const { |
| 139 | return GetRawButton(static_cast<int>(Button::kBack)); |
| 140 | } |
| 141 | |
| 142 | bool XboxController::GetBackButtonPressed() { |
| 143 | return GetRawButtonPressed(static_cast<int>(Button::kBack)); |
| 144 | } |
| 145 | |
| 146 | bool XboxController::GetBackButtonReleased() { |
| 147 | return GetRawButtonReleased(static_cast<int>(Button::kBack)); |
| 148 | } |
| 149 | |
| 150 | bool XboxController::GetStartButton() const { |
| 151 | return GetRawButton(static_cast<int>(Button::kStart)); |
| 152 | } |
| 153 | |
| 154 | bool XboxController::GetStartButtonPressed() { |
| 155 | return GetRawButtonPressed(static_cast<int>(Button::kStart)); |
| 156 | } |
| 157 | |
| 158 | bool XboxController::GetStartButtonReleased() { |
| 159 | return GetRawButtonReleased(static_cast<int>(Button::kStart)); |
| 160 | } |