ID:2203976
 
Resolved
Certain controllers, notably the PS4 DualShock controller, did not function correctly due to having a mix of positive-and-negative and positive-only axes.
BYOND Version:511.1369
Operating System:Windows 10 Home
Web Browser:Firefox 50.0
Applies to:Dream Seeker
Status: Resolved (511.1371)

This issue has been resolved.
Descriptive Problem Summary:
When sending [[x]] and [[y]] data from the right stick of a gamepad the values are not consistent between different gamepads. From what I have direct access to the Rock Candy Xbox 360 controller works exactly as expected, whereas the Playstation 4 Dual Shock 4 controller is never sending less than 0.75 for the y-axis. I don't know the specific values that were being sent, but someone else tried using a different brand of Xbox 360 and the y value never even got to 0.25 (estimating because I wasn't outputting the numbers, but things should have been happening with values higher than 0.25).

Numbered Steps to Reproduce Problem:
1. Input code in any environment.
2. Add macro "GamepadRightAnalog" with the command "use-weapon-stick [[x]] [[y]]"
3. Run with any controller.
4. Some controllers will not return the correct values for the y-axis.

Code Snippet (if applicable) to Reproduce Problem:
mob/player
var/tmp
weaponwait = 0
controller_dir = 0
last_x = 0
last_y = 0
verb
use_weapon_stick(x as num, y as num)
set hidden = 1
if(weaponwait || (x < last_x+0.25 && x > last_x-0.25) && (y < last_y+0.25 && y > last_y-0.25))
if(x < 0.25 && y < 0.25)
if(x > -0.25 && y > -0.25) controller_dir = null
return
weaponwait = 1
var/_dir = 0
if(x > 0.75)
if(y > 0.25) _dir = NORTHEAST
else if(y < -0.25) _dir = SOUTHEAST
else _dir = EAST
else if(x < -0.75)
if(y > 0.25) _dir = NORTHWEST
else if(y < -0.25) _dir = SOUTHWEST
else _dir = WEST
else if(y > 0.75) _dir = NORTH
else if(y < -0.75) _dir = SOUTH
else _dir = 0
last_x = x
last_y = y
controller_dir = _dir
sleep world.tick_lag
weaponwait = 0


Expected Results:
All controllers should return the same or similar y-axis values.

Actual Results:
Some controllers return y values that are too high or too low.

Does the problem occur:
Every time? Or how often? Every time
In other games? Yes
In other user accounts? Yes
On other computers? Yes

When does the problem NOT occur?
When using a Rock Candy Xbox 360 controller.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Tested on versions 511.1367-511.1369 and it's present in all versions.

Workarounds:
None.
I'll run some tests with a PS4 controller and get back to you on this. It looks like there's a possibility it's simply not sending info in an appropriate range. It seems DirectInput may have a way to account for the controller pulling stupid crap like that, so I'll look into it and see about adding a workaround.
Thanks for the quick response! I appreciate you looking into it. :)
Okay, here's what I've found so far: Axes 0-1 are the left stick, 2 and 5 are the right stick, and 3 and 4 are L2 and R2, respectively. The value range used for all axes is confusing the code, both for L2/R2 detection (their values are seen as negative unless pressed more than halfway) and for the Gamepad Setup dialog (which sees them both as active when not being pressed).

I'm gonna have to puzzle out a new scheme for handling these kinds of situations and setting the triggers appropriately. Ideally, I want to be able to get a good idea if an input is a trigger or an axis before even going to the setup dialog. For the DualShock 4, the value of DIPROP_PHYSICALRANGE is 0 to 255 for regular axes and 0 to 315 for the triggers, but I doubt that's going to be a universal indicator.
Thanks for all the updates! Hopefully you can come up with a solution; I'm really excited to put the analog features to use, but currently I can only test it out with other people that have the exact same controller as me. :p
I'm sure I'll come up with something. I mostly have to let it percolate.

Right now you could set up a mapping for this manually as far as the axes are concerned, though I'm less sure of the buttons. The big problem then is that the triggers read as negative values unless they're pressed more than halfway.

Ultimately this stems from the fact that all axes are set to a range of -10000 to 10000. For triggers this is inappropriate; it should be 0 to 10000, or at least mapped internally that way. But how to tell a trigger from a stick? Aye, there's the rub. A trigger will of course be at its minimum value, or very near it, when not pressed; an axis will be at or near its middle value; but the only way to tell if an axis is in use is to check its value, and who's to say it's not a trigger being held down halfway or a stick held all the way to the left/up?
Lummox JR resolved issue with message:
Certain controllers, notably the PS4 DualShock controller, did not function correctly due to having a mix of positive-and-negative and positive-only axes.
:D :D :D :D
In the newest beta this still isn't fixed. It now gets input with my Rock Candy Xbox 360 controller between the values of -0.37 and 0.37 instead of -1 and 1. The same is true for the DS4 controller, except that it's not grabbing anything at all from the y axis. Upon further testing it seems to think that L2 is the y axis.
Have you used the gamepad setup dialog at all? The DS4 controller has to be configured; you can't just use the default setup with it.
I got it all working locally. Thanks a lot!
I intend to add that setup to the joysticks.txt file eventually. I just more or less forgot to put it in this release.
Not a problem, I'm just happy it's working. :)

It would be pretty convenient if we could manually include a copy of joysticks.txt with our projects, but I understand that beta releases are frequent enough for that to not be a major concern.
I guess I'll bump this, because my standard Xbox 360 controller is getting similar values on the Left Analog stick, capping out at 0.37 (Sometimes at about 0.404849 at the perfect angle).

Not sure what setup I need to do, but I'm assuming either the bug is back or the joysticks.txt file mentioned hasn't been included since this post.
In response to Albro1
Albro1 wrote:
I guess I'll bump this, because my standard Xbox 360 controller is getting similar values on the Left Analog stick, capping out at 0.37 (Sometimes at about 0.404849 at the perfect angle).

Not sure what setup I need to do, but I'm assuming either the bug is back or the joysticks.txt file mentioned hasn't been included since this post.

The issue in this thread is unrelated to the range problem already covered in another thread. This thread is really about the fact that certain trigger-only axes weren't read correctly, which has been dealt with already.