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 005package edu.wpi.first.wpilibj.simulation; 006 007import edu.wpi.first.wpilibj.XboxController; 008 009/** Class to control a simulated Xbox 360 or Xbox One controller. */ 010public class XboxControllerSim extends GenericHIDSim { 011 /** 012 * Constructs from a XboxController object. 013 * 014 * @param joystick controller to simulate 015 */ 016 public XboxControllerSim(XboxController joystick) { 017 super(joystick); 018 setAxisCount(6); 019 setButtonCount(10); 020 setPOVCount(1); 021 } 022 023 /** 024 * Constructs from a joystick port number. 025 * 026 * @param port port number 027 */ 028 public XboxControllerSim(int port) { 029 super(port); 030 setAxisCount(6); 031 setButtonCount(10); 032 setPOVCount(1); 033 } 034 035 /** 036 * Change the left X value of the joystick. 037 * 038 * @param value the new value 039 */ 040 public void setLeftX(double value) { 041 setRawAxis(XboxController.Axis.kLeftX.value, value); 042 } 043 044 /** 045 * Change the right X value of the joystick. 046 * 047 * @param value the new value 048 */ 049 public void setRightX(double value) { 050 setRawAxis(XboxController.Axis.kRightX.value, value); 051 } 052 053 /** 054 * Change the left Y value of the joystick. 055 * 056 * @param value the new value 057 */ 058 public void setLeftY(double value) { 059 setRawAxis(XboxController.Axis.kLeftY.value, value); 060 } 061 062 /** 063 * Change the right Y value of the joystick. 064 * 065 * @param value the new value 066 */ 067 public void setRightY(double value) { 068 setRawAxis(XboxController.Axis.kRightY.value, value); 069 } 070 071 /** 072 * Change the value of the left trigger axis on the joystick. 073 * 074 * @param value the new value 075 */ 076 public void setLeftTriggerAxis(double value) { 077 setRawAxis(XboxController.Axis.kLeftTrigger.value, value); 078 } 079 080 /** 081 * Change the value of the right trigger axis on the joystick. 082 * 083 * @param value the new value 084 */ 085 public void setRightTriggerAxis(double value) { 086 setRawAxis(XboxController.Axis.kRightTrigger.value, value); 087 } 088 089 /** 090 * Change the value of the left bumper on the joystick. 091 * 092 * @param state the new value 093 */ 094 public void setLeftBumper(boolean state) { 095 setRawButton(XboxController.Button.kLeftBumper.value, state); 096 } 097 098 /** 099 * Change the value of the right bumper on the joystick. 100 * 101 * @param state the new value 102 */ 103 public void setRightBumper(boolean state) { 104 setRawButton(XboxController.Button.kRightBumper.value, state); 105 } 106 107 /** 108 * Change the value of the left stick button on the joystick. 109 * 110 * @param state the new value 111 */ 112 public void setLeftStickButton(boolean state) { 113 setRawButton(XboxController.Button.kLeftStick.value, state); 114 } 115 116 /** 117 * Change the value of the right stick button on the joystick. 118 * 119 * @param state the new value 120 */ 121 public void setRightStickButton(boolean state) { 122 setRawButton(XboxController.Button.kRightStick.value, state); 123 } 124 125 /** 126 * Change the value of the A button. 127 * 128 * @param state the new value 129 */ 130 public void setAButton(boolean state) { 131 setRawButton(XboxController.Button.kA.value, state); 132 } 133 134 /** 135 * Change the value of the B button. 136 * 137 * @param state the new value 138 */ 139 public void setBButton(boolean state) { 140 setRawButton(XboxController.Button.kB.value, state); 141 } 142 143 /** 144 * Change the value of the X button. 145 * 146 * @param state the new value 147 */ 148 public void setXButton(boolean state) { 149 setRawButton(XboxController.Button.kX.value, state); 150 } 151 152 /** 153 * Change the value of the Y button. 154 * 155 * @param state the new value 156 */ 157 public void setYButton(boolean state) { 158 setRawButton(XboxController.Button.kY.value, state); 159 } 160 161 /** 162 * Change the value of the Back button. 163 * 164 * @param state the new value 165 */ 166 public void setBackButton(boolean state) { 167 setRawButton(XboxController.Button.kBack.value, state); 168 } 169 170 /** 171 * Change the value of the Start button. 172 * 173 * @param state the new value 174 */ 175 public void setStartButton(boolean state) { 176 setRawButton(XboxController.Button.kStart.value, state); 177 } 178}