Commit graph

51 commits

Author SHA1 Message Date
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
Sam Lantinga
03e08a6a79 Organized joystick hotplug code a bit.
Cleaned up names, return types, etc.
2012-11-27 00:58:12 -08:00
Sam Lantinga
3f29ebe82f Return an error if the joystick index isn't 0 on Android 2012-11-26 22:09:34 -08:00
Sam Lantinga
c6918ae961 Fixed building joystick code on Android 2012-11-26 22:02:01 -08:00
Sam Lantinga
f380ecb137 Removed executable bit from source files 2012-09-27 14:35:28 -07:00
Sam Lantinga
40c6294290 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
morgan.devel@gmail.com 2012-01-13 00:32:23 PST

The android version of SDL_SYS_JoystickUpdate doesn't check if there is
actually new data and always generate the SDL_JOYAXISMOTION event.
Consequently, doing a while(SDL_PollEvent()) will result in an endless loop.

The attached patch fix this issue.

It also scale the incoming values properly in the Sint16 range. The scale from
[-gravity;+gravity] is done directly in the java part because one may want to
map the sensor values with a non-linear method for example.
2012-01-13 20:57:35 -05:00
Sam Lantinga
028e5dcdbd Happy New Year! 2011-12-31 09:28:07 -05:00
Sam Lantinga
b0660ba5ff SDL 1.3 is now under the zlib license. 2011-04-08 13:03:26 -07:00
Sam Lantinga
e5803d148c Happy 2011! :) 2011-02-11 22:37:15 -08:00
Sam Lantinga
b4497865bd Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
I think this also fixes the bug relating to non-latin characters in filenames, since UNICODE wasn't defined in SDL_rwops.c

--HG--
rename : src/SDL_android.cpp => src/core/android/SDL_android.cpp
rename : src/SDL_android.h => src/core/android/SDL_android.h
2011-01-24 21:20:30 -08:00
Sam Lantinga
70c916a415 Cleaned up internal accelerometer interface 2011-01-13 18:03:56 -08:00