001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY 006 007package edu.wpi.first.wpilibj2.command.button; 008 009import edu.wpi.first.wpilibj.XboxController; 010import edu.wpi.first.wpilibj.event.EventLoop; 011import edu.wpi.first.wpilibj2.command.CommandScheduler; 012 013/** 014 * A version of {@link XboxController} with {@link Trigger} factories for command-based. 015 * 016 * @see XboxController 017 */ 018@SuppressWarnings("MethodName") 019public class CommandXboxController extends CommandGenericHID { 020 private final XboxController m_hid; 021 022 /** 023 * Construct an instance of a controller. 024 * 025 * @param port The port index on the Driver Station that the controller is plugged into. 026 */ 027 public CommandXboxController(int port) { 028 super(port); 029 m_hid = new XboxController(port); 030 } 031 032 /** 033 * Get the underlying GenericHID object. 034 * 035 * @return the wrapped GenericHID object 036 */ 037 @Override 038 public XboxController getHID() { 039 return m_hid; 040 } 041 042 /** 043 * Constructs a Trigger instance around the A button's digital signal. 044 * 045 * @return a Trigger instance representing the A button's digital signal attached 046 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 047 * @see #a(EventLoop) 048 */ 049 public Trigger a() { 050 return a(CommandScheduler.getInstance().getDefaultButtonLoop()); 051 } 052 053 /** 054 * Constructs a Trigger instance around the A button's digital signal. 055 * 056 * @param loop the event loop instance to attach the event to. 057 * @return a Trigger instance representing the A button's digital signal attached 058 * to the given loop. 059 */ 060 public Trigger a(EventLoop loop) { 061 return button(XboxController.Button.kA.value, loop); 062 } 063 064 /** 065 * Constructs a Trigger instance around the B button's digital signal. 066 * 067 * @return a Trigger instance representing the B button's digital signal attached 068 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 069 * @see #b(EventLoop) 070 */ 071 public Trigger b() { 072 return b(CommandScheduler.getInstance().getDefaultButtonLoop()); 073 } 074 075 /** 076 * Constructs a Trigger instance around the B button's digital signal. 077 * 078 * @param loop the event loop instance to attach the event to. 079 * @return a Trigger instance representing the B button's digital signal attached 080 * to the given loop. 081 */ 082 public Trigger b(EventLoop loop) { 083 return button(XboxController.Button.kB.value, loop); 084 } 085 086 /** 087 * Constructs a Trigger instance around the X button's digital signal. 088 * 089 * @return a Trigger instance representing the X button's digital signal attached 090 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 091 * @see #x(EventLoop) 092 */ 093 public Trigger x() { 094 return x(CommandScheduler.getInstance().getDefaultButtonLoop()); 095 } 096 097 /** 098 * Constructs a Trigger instance around the X button's digital signal. 099 * 100 * @param loop the event loop instance to attach the event to. 101 * @return a Trigger instance representing the X button's digital signal attached 102 * to the given loop. 103 */ 104 public Trigger x(EventLoop loop) { 105 return button(XboxController.Button.kX.value, loop); 106 } 107 108 /** 109 * Constructs a Trigger instance around the Y button's digital signal. 110 * 111 * @return a Trigger instance representing the Y button's digital signal attached 112 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 113 * @see #y(EventLoop) 114 */ 115 public Trigger y() { 116 return y(CommandScheduler.getInstance().getDefaultButtonLoop()); 117 } 118 119 /** 120 * Constructs a Trigger instance around the Y button's digital signal. 121 * 122 * @param loop the event loop instance to attach the event to. 123 * @return a Trigger instance representing the Y button's digital signal attached 124 * to the given loop. 125 */ 126 public Trigger y(EventLoop loop) { 127 return button(XboxController.Button.kY.value, loop); 128 } 129 130 /** 131 * Constructs a Trigger instance around the left bumper button's digital signal. 132 * 133 * @return a Trigger instance representing the left bumper button's digital signal attached 134 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 135 * @see #leftBumper(EventLoop) 136 */ 137 public Trigger leftBumper() { 138 return leftBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); 139 } 140 141 /** 142 * Constructs a Trigger instance around the left bumper button's digital signal. 143 * 144 * @param loop the event loop instance to attach the event to. 145 * @return a Trigger instance representing the left bumper button's digital signal attached 146 * to the given loop. 147 */ 148 public Trigger leftBumper(EventLoop loop) { 149 return button(XboxController.Button.kLeftBumper.value, loop); 150 } 151 152 /** 153 * Constructs a Trigger instance around the right bumper button's digital signal. 154 * 155 * @return a Trigger instance representing the right bumper button's digital signal attached 156 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 157 * @see #rightBumper(EventLoop) 158 */ 159 public Trigger rightBumper() { 160 return rightBumper(CommandScheduler.getInstance().getDefaultButtonLoop()); 161 } 162 163 /** 164 * Constructs a Trigger instance around the right bumper button's digital signal. 165 * 166 * @param loop the event loop instance to attach the event to. 167 * @return a Trigger instance representing the right bumper button's digital signal attached 168 * to the given loop. 169 */ 170 public Trigger rightBumper(EventLoop loop) { 171 return button(XboxController.Button.kRightBumper.value, loop); 172 } 173 174 /** 175 * Constructs a Trigger instance around the back button's digital signal. 176 * 177 * @return a Trigger instance representing the back button's digital signal attached 178 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 179 * @see #back(EventLoop) 180 */ 181 public Trigger back() { 182 return back(CommandScheduler.getInstance().getDefaultButtonLoop()); 183 } 184 185 /** 186 * Constructs a Trigger instance around the back button's digital signal. 187 * 188 * @param loop the event loop instance to attach the event to. 189 * @return a Trigger instance representing the back button's digital signal attached 190 * to the given loop. 191 */ 192 public Trigger back(EventLoop loop) { 193 return button(XboxController.Button.kBack.value, loop); 194 } 195 196 /** 197 * Constructs a Trigger instance around the start button's digital signal. 198 * 199 * @return a Trigger instance representing the start button's digital signal attached 200 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 201 * @see #start(EventLoop) 202 */ 203 public Trigger start() { 204 return start(CommandScheduler.getInstance().getDefaultButtonLoop()); 205 } 206 207 /** 208 * Constructs a Trigger instance around the start button's digital signal. 209 * 210 * @param loop the event loop instance to attach the event to. 211 * @return a Trigger instance representing the start button's digital signal attached 212 * to the given loop. 213 */ 214 public Trigger start(EventLoop loop) { 215 return button(XboxController.Button.kStart.value, loop); 216 } 217 218 /** 219 * Constructs a Trigger instance around the left stick button's digital signal. 220 * 221 * @return a Trigger instance representing the left stick button's digital signal attached 222 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 223 * @see #leftStick(EventLoop) 224 */ 225 public Trigger leftStick() { 226 return leftStick(CommandScheduler.getInstance().getDefaultButtonLoop()); 227 } 228 229 /** 230 * Constructs a Trigger instance around the left stick button's digital signal. 231 * 232 * @param loop the event loop instance to attach the event to. 233 * @return a Trigger instance representing the left stick button's digital signal attached 234 * to the given loop. 235 */ 236 public Trigger leftStick(EventLoop loop) { 237 return button(XboxController.Button.kLeftStick.value, loop); 238 } 239 240 /** 241 * Constructs a Trigger instance around the right stick button's digital signal. 242 * 243 * @return a Trigger instance representing the right stick button's digital signal attached 244 * to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 245 * @see #rightStick(EventLoop) 246 */ 247 public Trigger rightStick() { 248 return rightStick(CommandScheduler.getInstance().getDefaultButtonLoop()); 249 } 250 251 /** 252 * Constructs a Trigger instance around the right stick button's digital signal. 253 * 254 * @param loop the event loop instance to attach the event to. 255 * @return a Trigger instance representing the right stick button's digital signal attached 256 * to the given loop. 257 */ 258 public Trigger rightStick(EventLoop loop) { 259 return button(XboxController.Button.kRightStick.value, loop); 260 } 261 262 /** 263 * Constructs a Trigger instance around the axis value of the left trigger. The returned 264 * trigger will be true when the axis value is greater than {@code threshold}. 265 * 266 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 267 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 268 * @param loop the event loop instance to attach the Trigger to. 269 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 270 * threshold, attached to the given event loop 271 */ 272 public Trigger leftTrigger(double threshold, EventLoop loop) { 273 return axisGreaterThan(XboxController.Axis.kLeftTrigger.value, threshold, loop); 274 } 275 276 /** 277 * Constructs a Trigger instance around the axis value of the left trigger. The returned 278 * trigger will be true when the axis value is greater than {@code threshold}. 279 * 280 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 281 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 282 * @return a Trigger instance that is true when the left trigger's axis exceeds the provided 283 * threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler 284 * button loop}. 285 */ 286 public Trigger leftTrigger(double threshold) { 287 return leftTrigger(threshold, CommandScheduler.getInstance().getDefaultButtonLoop()); 288 } 289 290 /** 291 * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger 292 * will be true when the axis value is greater than 0.5. 293 * 294 * @return a Trigger instance that is true when the left trigger's axis exceeds 0.5, attached to 295 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 296 */ 297 public Trigger leftTrigger() { 298 return leftTrigger(0.5); 299 } 300 301 /** 302 * Constructs a Trigger instance around the axis value of the right trigger. The returned 303 * trigger will be true when the axis value is greater than {@code threshold}. 304 * 305 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 306 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 307 * @param loop the event loop instance to attach the Trigger to. 308 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 309 * threshold, attached to the given event loop 310 */ 311 public Trigger rightTrigger(double threshold, EventLoop loop) { 312 return axisGreaterThan(XboxController.Axis.kRightTrigger.value, threshold, loop); 313 } 314 315 /** 316 * Constructs a Trigger instance around the axis value of the right trigger. The returned 317 * trigger will be true when the axis value is greater than {@code threshold}. 318 * 319 * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value 320 * should be in the range [0, 1] where 0 is the unpressed state of the axis. 321 * @return a Trigger instance that is true when the right trigger's axis exceeds the provided 322 * threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler 323 * button loop}. 324 */ 325 public Trigger rightTrigger(double threshold) { 326 return rightTrigger(threshold, CommandScheduler.getInstance().getDefaultButtonLoop()); 327 } 328 329 /** 330 * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger 331 * will be true when the axis value is greater than 0.5. 332 * 333 * @return a Trigger instance that is true when the right trigger's axis exceeds 0.5, attached to 334 * the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. 335 */ 336 public Trigger rightTrigger() { 337 return rightTrigger(0.5); 338 } 339 340 /** 341 * Get the X axis value of left side of the controller. 342 * 343 * @return The axis value. 344 */ 345 public double getLeftX() { 346 return m_hid.getLeftX(); 347 } 348 349 /** 350 * Get the X axis value of right side of the controller. 351 * 352 * @return The axis value. 353 */ 354 public double getRightX() { 355 return m_hid.getRightX(); 356 } 357 358 /** 359 * Get the Y axis value of left side of the controller. 360 * 361 * @return The axis value. 362 */ 363 public double getLeftY() { 364 return m_hid.getLeftY(); 365 } 366 367 /** 368 * Get the Y axis value of right side of the controller. 369 * 370 * @return The axis value. 371 */ 372 public double getRightY() { 373 return m_hid.getRightY(); 374 } 375 376 /** 377 * Get the left trigger axis value of the controller. Note that this axis is bound to the 378 * range of [0, 1] as opposed to the usual [-1, 1]. 379 * 380 * @return The axis value. 381 */ 382 public double getLeftTriggerAxis() { 383 return m_hid.getLeftTriggerAxis(); 384 } 385 386 /** 387 * Get the right trigger axis value of the controller. Note that this axis is bound to the 388 * range of [0, 1] as opposed to the usual [-1, 1]. 389 * 390 * @return The axis value. 391 */ 392 public double getRightTriggerAxis() { 393 return m_hid.getRightTriggerAxis(); 394 } 395}