[API Change Suggestion] Add sensor API |
[API Change Suggestion] Add sensor API |
Joseba García Etxebarria
Guest
|
Hi all,
This is supposed to be a follow-up to the thread in [1], in case the list doesn't automatically detect it. Just to let you know that I've been working in writing the sensor subsystem for SDL HG. The implementation for Android is mostly ready (I just need to make sure the various data fetched from the sensors is sent to the right structure members) but it's mostly working! The code is not quite ready for prime-time but it's almost there. You can have a look at it right now at [2]. Once it's ready I'll submit an enhancement request to bugzilla with the patch. It'll include: * Working Android implementation, based on the joystick API and working for Android 2.3 (android-9) and over. The code is written in C using the NDK, so no JNI involved. * "Dummy" implementation others can use to implement the API in other systems, too. * Removal of the accelerometer code from the joystick subsystem in Android. I'm sure this'll need some discussion on how things should be given to the user and on the API itself, but I'd say it's looking pretty neat already For anybody interested, in [3] there's a general overview of how sensors work in Android. Regards, Joseba [1] http://forums.libsdl.org/viewtopic.php?t=8744 [2] http://code.google.com/p/bennugd-monolithic/source/browse/#svn%2Fbranches%2FSDL [3] http://developer.android.com/guide/topics/sensors/sensors_overview.html _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
[API Change Suggestion] Add sensor API |
RodrigoCard
|
I think this is great, that accelerometer code in Joystick interface was a bit weird.
Are you planning to work in a iOS implementation too?
|
|||||||||||||
|
[API Change Suggestion] Add sensor API |
Joseba García Etxebarria
Guest
|
Hi,
No, sorry, I won't probably be porting this to iOS. I don't know Objective-C or iOS well enough to be able to write this and I still have to do quite a bit of work in my game engine in order to get it to work fine in Android. Still, someone with enough knowledge should be able to write the code starting from the "dummy" implementation, if the code does get to SDL. If anybody is curious on how the API looks like, they can have a look at the publich header here: https://code.google.com/p/bennugd-monolithic/source/browse/branches/SDL/include/SDL_sensor.h Regards, Joseba On Mon, Feb 4, 2013 at 9:35 PM, Rodrigo wrote:
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
[API Change Suggestion] Add sensor API |
Joseba García Etxebarria
Guest
|
Hi all,
I've submitted bug report 1717 ( http://bugzilla.libsdl.org/show_bug.cgi?id=1717 ) with the sensor patch. The patch includes the sample Android implementation as well as a dummy implementation others can use to add sensor handling code in other systems. The code is usable and I've tested it on Android. The constants used in the API basically match those in Android and the kinds of sensors supported are those supported in Android. You can have a look at how data should be given to you at the Android developer docs on sensors: http://developer.android.com/reference/android/hardware/SensorEvent.html As for the API itself, it's based on the joystick API and it's very similar to use. The basic prototypes look a bit like this: int SDL_NumSensors(); const char *SDL_SensorNameForIndex(int device_index); SDL_Sensot * SDL_SensorOpen(int device_index); int SDL_SensorNumAxes(SDL_Sensor * sensor); Uint8 SDL_SensorType(SDL_Sensor * sensor); Sint16 SDL_SensorGetAxis(SDL_Sensor * sensor, int axis); void SDL_SensorClose(SDL_Sensor * sensor); And their usage is pretty much the same as with the joystick code. One design decission I made was to NOT send SDL_Event's for sensor changes. Sensors can provide data at a very high frequency and I don't know if it makes sense to fill the SDL event queue with data for that regard. Please let me know if you have any suggestions or comments on how the API should behave(look. Kind regards, Joseba PS: I have an exam in my university this Wednesday, so I won't be able to work on this (or the Android joystick patch) until thursday but please don't hesitate to send me any ideas on this and I'll come back to you after the exam. On Mon, Feb 4, 2013 at 11:33 PM, Joseba García Etxebarria wrote:
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|
[API Change Suggestion] Add sensor API |
Joseba García Etxebarria
Guest
|
Hi all,
In case someone is interested in this but not CC'ed in the bug report, I've submitted a couple of new versions of the patch with changes after suggestions from Philipp Wiesemann and Sam Lantinga. Basically the latest patch also serves the accelerometer data thorugh a fake joystick (as it does right now in the official code) and introduces a new SDL_HINT to disable that behaviour so that you only get accelerometer data through the sensor API. The default, however, is to be compatible with the current official behaviour. http://bugzilla.libsdl.org/show_bug.cgi?id=1717 Regards, Joseba On Mon, Feb 11, 2013 at 5:00 PM, Joseba García Etxebarria wrote:
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||||
|