|
28 | 28 | * and all of the main buttons. |
29 | 29 | * |
30 | 30 | * * Joysticks should be your typical 10k dual potentiometers. |
| 31 | + * To prevent random values caused by floating inputs, |
| 32 | + joysticks are disabled by default. |
31 | 33 | * * Triggers can be either analog (pots) or digital (buttons). |
32 | 34 | * Set the 'TriggerButtons' variable to change between the two. |
33 | 35 | * * Buttons use the internal pull-ups and should be connected |
@@ -187,24 +189,22 @@ void loop() { |
187 | 189 |
|
188 | 190 | // White lie here... most generic joysticks are typically |
189 | 191 | // inverted by default. If the "Invert" variable is false |
190 | | - // then we need to do this transformation. |
191 | | - if (InvertLeftYAxis == false) { |
192 | | - leftJoyY = ADC_Max - leftJoyY; |
193 | | - } |
| 192 | + // then we'll take the opposite value with 'not' (!). |
| 193 | + boolean invert = !InvertLeftYAxis; |
194 | 194 |
|
195 | | - XInput.setJoystick(JOY_LEFT, leftJoyX, leftJoyY); |
| 195 | + XInput.setJoystickX(JOY_LEFT, leftJoyX); |
| 196 | + XInput.setJoystickY(JOY_LEFT, leftJoyY, invert); |
196 | 197 | } |
197 | 198 |
|
198 | 199 | // Set right joystick |
199 | 200 | if (UseRightJoystick == true) { |
200 | 201 | int rightJoyX = analogRead(Pin_RightJoyX); |
201 | 202 | int rightJoyY = analogRead(Pin_RightJoyY); |
202 | 203 |
|
203 | | - if (InvertRightYAxis == false) { |
204 | | - rightJoyY = ADC_Max - rightJoyY; |
205 | | - } |
| 204 | + boolean invert = !InvertRightYAxis; |
206 | 205 |
|
207 | | - XInput.setJoystick(JOY_RIGHT, rightJoyX, rightJoyY); |
| 206 | + XInput.setJoystickX(JOY_RIGHT, rightJoyX); |
| 207 | + XInput.setJoystickY(JOY_RIGHT, rightJoyY, invert); |
208 | 208 | } |
209 | 209 |
|
210 | 210 | // Send control data to the computer |
|
0 commit comments