| Summary: | [Android] Handle joystick POV hat separately | ||
|---|---|---|---|
| Product: | SDL | Reporter: | ny00 |
| Component: | joystick | Assignee: | Gabriel Jacobo <gabomdq> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | dbrady, gabomdq |
| Version: | HG 2.1 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
Patch for handling of POV hat
Updated patch Fixed patch Fixed validation |
||
P.S. This has been tested with two game controllers that do have POV hats (which are simply d-pads). It can be good to test the patch with a controller that does not report any, though. I don't have such a controller ready. This looks ok, can we generalize to "n" hats instead of hardcoding to either 0 or 1? (In reply to Gabriel Jacobo from comment #2) > This looks ok, can we generalize to "n" hats instead of hardcoding to either > 0 or 1? I'm not sure Android supports controllers with more than 1 hat directly, at least according to this: http://developer.android.com/reference/android/view/MotionEvent.html The best way to tell would be to try and pair/connect a controller with two of more hats (as reported on a PC) with an Android-powered device, and see what API Demos tells, for instance. I suspect that in case they're supported at all, the extra hats are to be reported as totally unrelated axes, the same way that the 5th analog axis of an old controller I've gotten here is reported as AXIS_THROTTLE for some reason. Created attachment 1535 [details] Updated patch I've updated this patch to work with the latest head. I've also made it slightly more generic, even though Android does only support one hat stick. It also depends on the not-yet-committed patch from bug 2358 to sort joystick axes. A few comments: Line 969: joystick.hats.size() should probably be joystick.hats.size() / 2, right? Android_OnHat: validate x,y >=0 && <= 2 There's some minor spacing issues Argh, I swear I ran tabs to spaces on every single file. But good catch. I'll fix the patch when I can. Created attachment 1541 [details]
Fixed patch
Here's another crack at this patch. I couldn't find any tabs, but I corrected some whitespace stuff that looked a little different from the existing code.
> int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) ); Should this value be normalized (like we do with regular axes) to -1...1 using range.getMin() and range.getRange() or is it guaranteed to always be -1, 0, 1? > if (x >= 0 && x <=2 && y >= 0 && y <= 2) { > SDL_PrivateJoystickHat(item->joystick, hat_id, position_map[y+1][x+1] ); One of the above is wrong, if x,y can be 0,1,2, position_map should use them directly. If they are -1,0,1, then the validation in the if statement is wrong. Created attachment 1543 [details] Fixed validation Fixed the validation code. And yes, the hat stick values are supposed to be normalised already. http://developer.android.com/reference/android/view/MotionEvent.html#AXIS_HAT_X Fixed, thanks! https://hg.libsdl.org/SDL/rev/8372466c003c |
Created attachment 1422 [details] Patch for handling of POV hat At the moment the POV hat of a controller is identified by two SDL analog axes, as these are simply the axes AXIS_HAT_X and AXIS_HAT_Y on the Android side. With this patch, the axes are handled separately. Although the SDL_GameController API can take care of that, there may still be some game or other app where the SDL_Joystick API is used directly, and it can be good to know how to read HAT input in order to pick default assignments, at the least.