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.PS4Controller; 008 009/** Class to control a simulated PS4 controller. */ 010public class PS4ControllerSim extends GenericHIDSim { 011 /** 012 * Constructs from a PS4Controller object. 013 * 014 * @param joystick controller to simulate 015 */ 016 public PS4ControllerSim(PS4Controller joystick) { 017 super(joystick); 018 setAxisCount(6); 019 setButtonCount(14); 020 setPOVCount(1); 021 } 022 023 /** 024 * Constructs from a joystick port number. 025 * 026 * @param port port number 027 */ 028 public PS4ControllerSim(int port) { 029 super(port); 030 setAxisCount(6); 031 setButtonCount(14); 032 setPOVCount(1); 033 } 034 035 /** 036 * Change the X axis value of the controller's left stick. 037 * 038 * @param value the new value 039 */ 040 public void setLeftX(double value) { 041 setRawAxis(PS4Controller.Axis.kLeftX.value, value); 042 } 043 044 /** 045 * Change the X axis value of the controller's right stick. 046 * 047 * @param value the new value 048 */ 049 public void setRightX(double value) { 050 setRawAxis(PS4Controller.Axis.kRightX.value, value); 051 } 052 053 /** 054 * Change the Y axis value of the controller's left stick. 055 * 056 * @param value the new value 057 */ 058 public void setLeftY(double value) { 059 setRawAxis(PS4Controller.Axis.kLeftY.value, value); 060 } 061 062 /** 063 * Change the Y axis value of the controller's right stick. 064 * 065 * @param value the new value 066 */ 067 public void setRightY(double value) { 068 setRawAxis(PS4Controller.Axis.kRightY.value, value); 069 } 070 071 /** 072 * Change the L2 axis value of the controller. 073 * 074 * @param value the new value 075 */ 076 public void setL2Axis(double value) { 077 setRawAxis(PS4Controller.Axis.kL2.value, value); 078 } 079 080 /** 081 * Change the R2 axis value of the controller. 082 * 083 * @param value the new value 084 */ 085 public void setR2Axis(double value) { 086 setRawAxis(PS4Controller.Axis.kR2.value, value); 087 } 088 089 /** 090 * Change the value of the Square button on the controller. 091 * 092 * @param value the new value 093 */ 094 public void setSquareButton(boolean value) { 095 setRawButton(PS4Controller.Button.kSquare.value, value); 096 } 097 098 /** 099 * Change the value of the Cross button on the controller. 100 * 101 * @param value the new value 102 */ 103 public void setCrossButton(boolean value) { 104 setRawButton(PS4Controller.Button.kCross.value, value); 105 } 106 107 /** 108 * Change the value of the Circle button on the controller. 109 * 110 * @param value the new value 111 */ 112 public void setCircleButton(boolean value) { 113 setRawButton(PS4Controller.Button.kCircle.value, value); 114 } 115 116 /** 117 * Change the value of the Triangle button on the controller. 118 * 119 * @param value the new value 120 */ 121 public void setTriangleButton(boolean value) { 122 setRawButton(PS4Controller.Button.kTriangle.value, value); 123 } 124 125 /** 126 * Change the value of the L1 button on the controller. 127 * 128 * @param value the new value 129 */ 130 public void setL1Button(boolean value) { 131 setRawButton(PS4Controller.Button.kL1.value, value); 132 } 133 134 /** 135 * Change the value of the R1 button on the controller. 136 * 137 * @param value the new value 138 */ 139 public void setR1Button(boolean value) { 140 setRawButton(PS4Controller.Button.kR1.value, value); 141 } 142 143 /** 144 * Change the value of the L2 button on the controller. 145 * 146 * @param value the new value 147 */ 148 public void setL2Button(boolean value) { 149 setRawButton(PS4Controller.Button.kL2.value, value); 150 } 151 152 /** 153 * Change the value of the R2 button on the controller. 154 * 155 * @param value the new value 156 */ 157 public void setR2Button(boolean value) { 158 setRawButton(PS4Controller.Button.kR2.value, value); 159 } 160 161 /** 162 * Change the value of the Share button on the controller. 163 * 164 * @param value the new value 165 */ 166 public void setShareButton(boolean value) { 167 setRawButton(PS4Controller.Button.kShare.value, value); 168 } 169 170 /** 171 * Change the value of the Options button on the controller. 172 * 173 * @param value the new value 174 */ 175 public void setOptionsButton(boolean value) { 176 setRawButton(PS4Controller.Button.kOptions.value, value); 177 } 178 179 /** 180 * Change the value of the L3 (left stick) button on the controller. 181 * 182 * @param value the new value 183 */ 184 public void setL3Button(boolean value) { 185 setRawButton(PS4Controller.Button.kL3.value, value); 186 } 187 188 /** 189 * Change the value of the R3 (right stick) button on the controller. 190 * 191 * @param value the new value 192 */ 193 public void setR3Button(boolean value) { 194 setRawButton(PS4Controller.Button.kR3.value, value); 195 } 196 197 /** 198 * Change the value of the PS button on the controller. 199 * 200 * @param value the new value 201 */ 202 public void setPSButton(boolean value) { 203 setRawButton(PS4Controller.Button.kPS.value, value); 204 } 205 206 /** 207 * Change the value of the touchpad button on the controller. 208 * 209 * @param value the new value 210 */ 211 public void setTouchpad(boolean value) { 212 setRawButton(PS4Controller.Button.kTouchpad.value, value); 213 } 214}