Commit graph

61 commits

Author SHA1 Message Date
Sam Lantinga
1e46b7fc9a Added stubs for simple Steam Controller support 2017-09-22 08:30:52 -07:00
Sam Lantinga
09b61ab1fd Fixed bug 2361 - [Android] Joysticks do not have unique IDs
David Brady

When I attempted to make a mapping file for Android gamepads, I quickly discovered that most of the ones that I have here show up as the same device (Broadcom Bluetooth HID), meaning that it was impossible to make mappings on Android, since every device looked the same.

This patch will check for the existence of the getDescriptor function added in Jelly Bean, and use it if it's there.  The Android Dashboard says that the majority of Android phones should support this function, and doing it this way will not force us to bump up our API version.
2017-08-28 10:03:39 -07:00
Sam Lantinga
1b24bfad38 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga
d1b2ffe485 Fixed missing prototypes on Android, patch from Sylvain 2016-12-02 02:25:12 -08:00
Philipp Wiesemann
2a8a7f92b7 Fixed empty parameter list in signatures of internal functions. 2016-11-16 22:08:51 +01:00
Sam Lantinga
e4105e7b2d Fixed bug 3444 - Android-TV: no more handling of back button on remote
ny00

Unfortunately, simply checking the return codes of "onNativePadDown/Up" as previously done has its own issue:

If an SDL joystick is connected *and* opened, then a proper KeyEvent, say with keycode KEYCODE_BUTTON_1, should lead to an SDL joystick button event as expected.

If, however, the joystick was *not* opened, then "onNativePadDown/Up" will return a negative value, so before the commit from bug 3426, you could unexpectedly get a keyboard event. (In practice, you'll just get a log message, since KEYCODE_BUTTON_1 has no mapping to a proper SDL_ScanCode value, but it's still an problem).

What should still be done, though, is checking the key code itself. We do have the KeyEvent.isGamepadButton method, but according my test, it returns "true" exactly (and only) for the KEYCODE_BUTTON* values, and not for KEYCODE_DPAD* or any other key code.

Here is a possible solution:
- Do check the return codes of "onNativePadDown/Up" as previously done.
- In addition, in "Android_OnPadDown/Up" from src/joystick/android/SDL_sysjoystick.c, 0 should *always* be returned in case the key code can be translated to an SDL_joystick button; Even if no matching joystick can be found.
2016-10-17 22:09:22 -07:00
Sam Lantinga
1b032a0419 Implemented SDL_GetHintBoolean() to make it easier to check boolean hints 2016-10-07 23:40:44 -07:00
Sam Lantinga
f98a06ec45 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Updated the removal code to iterate over all joystick add messages instead of just the first one.
2016-08-26 12:18:08 -07:00
Philipp Wiesemann
ea2a180c90 Android: Fixed crash if closing removed joystick (thanks, Sylvain!).
Fixes fix for Bugzilla #3408.
2016-08-25 22:31:33 +02:00
Philipp Wiesemann
e688740f8e Android: Fixed opening previously closed joystick (thanks, Sylvain!).
Fixes Bugzilla #3408.
2016-08-17 21:04:32 +02:00
Ryan C. Gordon
6bcb829721 Android: Restored Philipp's joystick change, lost in the previous merge.
This patch, specifically: https://hg.libsdl.org/SDL/rev/2455bf5d1866

--HG--
extra : histedit_source : b0bb3fe19f27af6a6098b4354fe2c3913bee9559
2016-02-19 00:28:53 -05:00
Ryan C. Gordon
0e5bf80595 Merge Android C89 fixes from Eric Wing. 2016-02-19 00:24:00 -05:00
Philipp Wiesemann
78c1a2d31f Android: Changed an internal joystick function to return count instead of id.
The returned value is currently not used by the caller. The instance id would
also not be needed on Java side and providing it just complicated the function.

Partially fixes Bugzilla #3234.
2016-02-16 20:32:22 +01:00
Eric Wing
6e7137e857 Android: C89 cleanup to avoid warnings/errors since the default gcc mode on Android is still pre-C99. 2016-02-09 17:36:42 -08:00
Sam Lantinga
7ee8dda270 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Sam Lantinga
1844f52297 Fixed bug 2948 - [Android] Arrow keys from external keyboard are not received
Sylvain

http://developer.android.com/reference/android/view/InputDevice.html
 int SOURCE_CLASS_JOYSTICK   Constant Value: 16       (0x00000010)

 int SOURCE_JOYSTICK         Constant Value: 16777232 (0x01000010)
 int SOURCE_KEYBOARD         Constant Value: 257      (0x00000101)
 int SOURCE_GAMEPAD          Constant Value: 1025     (0x00000401)
 int SOURCE_DPAD             Constant Value:  513     (0x00000201)


I have an a PC keyboard that I connect to an android device.
The issue is that "arrow" keys gets lost.

More explanation:

This device gets detected twice by the java "pollInputDevices()" both as SOURCE_KEYBOARD and as a composite (0x1000311 == SOURCE_JOYSTICK | SOURCE_KEYBOARD | SOURCE_DPAD).
Because of being a SOURCE_CLASS_JOYSTICK, only the second entry is registered, and I opened it.


When I press one arrow key, the java method "onKey(...)" is called.
The Source "event.getSource()" is "SOURCE_KEYBOARD", so it enters this conditions :

   if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
      (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {


And then, it enters :

   SDLActivity.onNativePadDown() (native code in "SDL_sysjoystick.c")


Since the "arrows" are viewed as "D-PAD", it gets translated :

   int button = keycode_to_SDL(keycode);


But the android-java "event.getDeviceId()" is wrong: this is the one from the Keyboard, and not the one from the Joystick that I have opened.
So I don't get them through the Joystick interface.


And since, the keycode has been translated, it returns 0 and assume it was consumed.
So I lost the key in the function "Android_OnPadDown()"


Notice, It won't happen with other normal "letters" keys because they does not get translated by "keycode_to_SDL", so "Android_OnPadDown()" returns -1.
And then java code send the keys to "SDLActivity.onNativeKeyDown()".




Possible patch on "Android_OnPadDown" and also "Android_OnPadUp" (and maybe other functons):

85 int
186 Android_OnPadDown(int device_id, int keycode)
187 {
188     SDL_joylist_item *item;
189     int button = keycode_to_SDL(keycode);
190     if (button >= 0) {
191         item = JoystickByDeviceId(device_id);
192         if (item && item->joystick) {
193             SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
194         }
+           else return -1;
195         return 0;
196     }
197
198     return -1;
199 }

It would allow the java caller function to send the key to "SDLActivity.onNativeKeyDown();"



Another solution, would be to replace:

 if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
      (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {

by

 if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0)

Because only "SOURCE_CLASS_JOYSTICK" devices are registered/opened.
2015-06-17 00:00:53 -07:00
Sam Lantinga
82634edb67 Fixed style 2015-06-14 19:26:20 -07:00
Sam Lantinga
66d920a28a Fixed bug 3012 - Android accelerometer joystick axis values overflow when values from Android are larger than gravity
Magnus Bjerke Vik

This causes issues when for instance using the joystick API to make an Android phone rotate an object by rotating the phone. When the absolute value of an axis reported by android is larger than earth gravity, SDL will overflow the Sint16 value used for joystick axes, causing sporadic movements when close to the gravity. Just holding the phone so that e.g. Y points directly upwards will make it unstable, and even more if you just tap the phone gently from below (increasing the acceleration).

More detailed: SDLActivity gets the accelerometer values in onSensorChanged and divides each axis by earth gravity. SDL_SYS_JoystickUpdate takes each of the axis values, multiplies them by 32767.0 (largest Sint16), and the casts them to Sint16. From this you can see that any value from Android that exceeds earth gravity will overflow the joystick axis.

A fix is to clamp the values so that they won't overflow the Sint16.
2015-06-14 19:25:12 -07:00
Sam Lantinga
56b58afdbe Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Philipp Wiesemann
8dcfd98d27 Android: Deactivated debug log messages on joystick device events. 2015-04-30 21:45:29 +02:00
Philipp Wiesemann
fc24a2d81e Fixed typo in internal joystick documentation comments. 2015-04-15 21:29:55 +02:00
Ryan C. Gordon
3ff618a9c7 Cleanups in the joystick code.
Removed some redundant state and other confusions.

Fixes Bugzilla #2738.

--HG--
extra : rebase_source : 35dd561553379e00eb8d169ce12ecc99393b2f84
2015-03-24 13:52:01 -04:00
Philipp Wiesemann
bde0ce0969 Updated internal documentation comments. 2015-03-11 21:14:21 +01:00
Ryan C. Gordon
fbdde501ba Removed SDL_SYS_JoystickNeedsPolling().
It was simpler to just have the polling (actually: hotplug detection)
 functions return immediately if it's not an appropriate time to poll.

Note that previously, if any joystick/controller was opened, we would poll
 every time anyhow, skipping this function.
2014-06-14 23:31:23 -04:00
Sam Lantinga
b2c4391ab7 Changed SDL_HINT_ACCEL_AS_JOY to SDL_HINT_ACCELEROMETER_AS_JOYSTICK to be more clear. 2014-03-01 12:21:15 -08:00
Sam Lantinga
d7940a513e Fixed bug 2374 - Update copyright for 2014...
Is it that time already??
2014-02-02 00:53:27 -08:00
dbrady
e2653cfbe5 fixed hat code validation. 2014-01-28 15:28:20 -08:00
Gabriel Jacobo
b878543be3 [Android] Fixes Bug 2370, don't send accelerometer changes when
Android_JNI_GetAccelerometerValues return SDL_FALSE (thanks to Jairo Luiz)
2014-01-27 17:59:19 -03:00
Gabriel Jacobo
196de652c5 Bug 2358 - [Android] Joystick Button Mappings are strange (fix by David Brady) 2014-01-23 08:44:25 -03:00
Gabriel Jacobo
3ae02c72db Fixes 2356, [Android] SDL_JoystickGetAttached does not function
Also fix a potential NULL pointer access in android/SDL_SYS_JoystickGetGUID

--HG--
extra : source : 215d88851d3a51422efeb30d50476e8b34337a95
2014-01-21 18:20:12 -03:00
Ryan C. Gordon
82edee6971 Make internal SDL sources include SDL_internal.h instead of SDL_config.h
The new header will include SDL_config.h, but allows for other global stuff.

--HG--
extra : rebase_source : ddf4a4c0dc2c554b98c82700798f343cd91b16e3
2013-11-24 23:56:17 -05:00
Philipp Wiesemann
7297902ce0 Fixed unused local variable warning in joystick source for Android. 2013-12-24 20:00:58 +01:00
Philipp Wiesemann
9da82d88f2 Fixed implicit declaration of SDL_Log() warning in joystick source for Android. 2013-12-24 19:59:35 +01:00
Gabriel Jacobo
99198c8c9f [Android] Poll joysticks every three seconds 2013-12-12 14:55:33 -03:00
Gabriel Jacobo
ae184f5e89 [Android] Hotplugging support for joysticks 2013-12-10 16:24:11 -03:00
Philipp Wiesemann
8106c1a455 Removed include of no more needed header. 2013-11-23 18:29:36 +01:00
Gabriel Jacobo
23434404ae [Android] Fixes #2264, handle joystick open/closed state properly 2013-11-23 09:47:25 -03:00
Gabriel Jacobo
c68f34799d [Android] Try to improve handling of DPAD|GAMEPAD + KEYBOARD devices
It seems some devices report themselves as DPAD or GAMEPAD and KEYBOARD as well,
and we need to route different keycodes to different parts of SDL.
2013-11-19 10:00:05 -03:00
Philipp Wiesemann
6917b0dbe5 Fixed implicit function declaration warning in joystick source for Android. 2013-11-18 23:38:59 +01:00
Gabriel Jacobo
a2cdc5c163 [Android] Fixes bug 2217, better joystick axes handling on Android. 2013-11-11 10:15:35 -03:00
Gabriel Jacobo
90cd003e2a Fixes bugs #2213 and #2214, improves the Android joystick code button handling 2013-11-10 20:13:27 -03:00
Philipp Wiesemann
99684031ac Changed function to return -1 through SDL_Error() instead of plain -1. 2013-11-10 14:47:05 +01:00
Philipp Wiesemann
3cf636ad92 Changed function to be static.
The function keycode_to_SDL() is only used in this file.
2013-11-10 14:44:50 +01:00
Philipp Wiesemann
1659944a67 Removed unused local variable to fix warning. 2013-11-10 14:42:41 +01:00
Gabriel Jacobo
7075ece4a5 Adds Joystick support for Android
This bumps the build SDK level to 12 (up from 10). Runtime requirements remain
the same (at API level < 12 joystick support is disabled).

Also enables building SDL for armv7 and x86.
2013-11-05 20:07:39 -03:00
Sam Lantinga
0cb6385637 File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00
Gabriel Jacobo
b39dd8c4e3 Backed out changeset: a500a9dbfb41 2013-04-01 13:21:23 -03:00
Sam Lantinga
3f660cc9ad Removed old file from the Android build 2013-03-19 23:24:24 -07:00
Sam Lantinga
95dcfa4c28 Happy New Year! 2013-02-15 08:47:44 -08:00
Sam Lantinga
5f53c47559 Fixed joystick GUID renaming for other platforms 2012-12-11 12:16:28 -08:00