Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | // 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. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "frc/XboxController.h" |
| 6 | |
| 7 | #include <hal/FRCUsageReporting.h> |
| 8 | |
| 9 | using namespace frc; |
| 10 | |
| 11 | XboxController::XboxController(int port) : GenericHID(port) { |
| 12 | HAL_Report(HALUsageReporting::kResourceType_XboxController, port + 1); |
| 13 | } |
| 14 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 15 | double XboxController::GetLeftX() const { |
| 16 | return GetRawAxis(Axis::kLeftX); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 17 | } |
| 18 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 19 | double XboxController::GetRightX() const { |
| 20 | return GetRawAxis(Axis::kRightX); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 21 | } |
| 22 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 23 | double XboxController::GetLeftY() const { |
| 24 | return GetRawAxis(Axis::kLeftY); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 25 | } |
| 26 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 27 | double XboxController::GetRightY() const { |
| 28 | return GetRawAxis(Axis::kRightY); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 31 | double XboxController::GetLeftTriggerAxis() const { |
| 32 | return GetRawAxis(Axis::kLeftTrigger); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 35 | double XboxController::GetRightTriggerAxis() const { |
| 36 | return GetRawAxis(Axis::kRightTrigger); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 39 | bool XboxController::GetLeftBumper() const { |
| 40 | return GetRawButton(Button::kLeftBumper); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 43 | bool XboxController::GetRightBumper() const { |
| 44 | return GetRawButton(Button::kRightBumper); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 47 | bool XboxController::GetLeftBumperPressed() { |
| 48 | return GetRawButtonPressed(Button::kLeftBumper); |
| 49 | } |
| 50 | |
| 51 | bool XboxController::GetRightBumperPressed() { |
| 52 | return GetRawButtonPressed(Button::kRightBumper); |
| 53 | } |
| 54 | |
| 55 | bool XboxController::GetLeftBumperReleased() { |
| 56 | return GetRawButtonReleased(Button::kLeftBumper); |
| 57 | } |
| 58 | |
| 59 | bool XboxController::GetRightBumperReleased() { |
| 60 | return GetRawButtonReleased(Button::kRightBumper); |
| 61 | } |
| 62 | |
| 63 | bool XboxController::GetLeftStickButton() const { |
| 64 | return GetRawButton(Button::kLeftStick); |
| 65 | } |
| 66 | |
| 67 | bool XboxController::GetRightStickButton() const { |
| 68 | return GetRawButton(Button::kRightStick); |
| 69 | } |
| 70 | |
| 71 | bool XboxController::GetLeftStickButtonPressed() { |
| 72 | return GetRawButtonPressed(Button::kLeftStick); |
| 73 | } |
| 74 | |
| 75 | bool XboxController::GetRightStickButtonPressed() { |
| 76 | return GetRawButtonPressed(Button::kRightStick); |
| 77 | } |
| 78 | |
| 79 | bool XboxController::GetLeftStickButtonReleased() { |
| 80 | return GetRawButtonReleased(Button::kLeftStick); |
| 81 | } |
| 82 | |
| 83 | bool XboxController::GetRightStickButtonReleased() { |
| 84 | return GetRawButtonReleased(Button::kRightStick); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool XboxController::GetAButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 88 | return GetRawButton(Button::kA); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | bool XboxController::GetAButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 92 | return GetRawButtonPressed(Button::kA); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | bool XboxController::GetAButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 96 | return GetRawButtonReleased(Button::kA); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool XboxController::GetBButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 100 | return GetRawButton(Button::kB); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | bool XboxController::GetBButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 104 | return GetRawButtonPressed(Button::kB); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool XboxController::GetBButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 108 | return GetRawButtonReleased(Button::kB); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | bool XboxController::GetXButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 112 | return GetRawButton(Button::kX); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | bool XboxController::GetXButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 116 | return GetRawButtonPressed(Button::kX); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | bool XboxController::GetXButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 120 | return GetRawButtonReleased(Button::kX); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | bool XboxController::GetYButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 124 | return GetRawButton(Button::kY); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | bool XboxController::GetYButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 128 | return GetRawButtonPressed(Button::kY); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | bool XboxController::GetYButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 132 | return GetRawButtonReleased(Button::kY); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | bool XboxController::GetBackButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 136 | return GetRawButton(Button::kBack); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | bool XboxController::GetBackButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 140 | return GetRawButtonPressed(Button::kBack); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | bool XboxController::GetBackButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 144 | return GetRawButtonReleased(Button::kBack); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | bool XboxController::GetStartButton() const { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 148 | return GetRawButton(Button::kStart); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | bool XboxController::GetStartButtonPressed() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 152 | return GetRawButtonPressed(Button::kStart); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | bool XboxController::GetStartButtonReleased() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 156 | return GetRawButtonReleased(Button::kStart); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 157 | } |