[API Change Suggestion] Add sensor API

Hi,

I’m sending this agiain since my forum posts don’t seem to come to the
mailing list. Sorry for double posting if you already read it.===============

When working on adding joystick input support for Android I realized that
right now the only sensor input that SDL can read is from the system’s
default accelerometer, and I believe that’s the situation for iOS too.
That doesn’t seem right to me: what if the system has more than one
accelerometer?, what if it has none?, what about other kinds of sensors
like gyroscopes?. Also, I don’t feel it really fits in the joystick API.

What I’m proposing is to have a separate sensors API -based on the current
API for joysticks- which would roughly look like this:

  • Function to check for the number of currently attached sensors. It would
    accept a parameter for sensor type:
    int SDL_NumSensors(Uint32 type);
    type could be something like SDL_ANY, SDL_ACCELEROMETER, SDL_GYROSCOPE,
    SDL_MAGNETOMETER…
  • Function to get sensor name:
    const char* SDL_SensorName(int device_index)
  • Function to open a sensor:
    SDL_Sensor* SDL_SensorOpen(int device_index)
  • Function to close a sensor:
    void SDL_SensorClose(SDL_Sensor* sensor)
  • Function to get number of axes the sensor can read data in:
    int SDL_SensorNumAxes(SDL_Sensor *sensor)
  • Function to get the data of a sensor in a particular axis:
    float SDL_SensorGetAxis(SDL_Sensor* sensor, int axis)

What are your thoughts on this? Should I write a small sample patch to see
how it fits?

===================

I’ve started writing a sample implementation for this in Android. I’ll let
you know when it’s done.

Regards,
Joseba

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 :slight_smile:

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

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?Date: Mon, 4 Feb 2013 20:24:55 +0100

From: Joseba Garc?a Etxebarria
To: SDL Development List
Subject: Re: [SDL] [API Change Suggestion] Add sensor API
Message-ID:
<
CAKJa1KmQ4L3q-YO9UKNiw4v76Oc3KrFPdEr1EoMJR8P+wXevhA at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

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 :slight_smile:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

End of SDL Digest, Vol 74, Issue 3


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,
JosebaOn Mon, Feb 4, 2013 at 9:35 PM, Rodrigo wrote:

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?

Date: Mon, 4 Feb 2013 20:24:55 +0100
From: Joseba Garc?a Etxebarria <@Joseba_Garcia_Etxeba>
To: SDL Development List
Subject: Re: [SDL] [API Change Suggestion] Add sensor API
Message-ID:

<CAKJa1KmQ4L3q-YO9UKNiw4v76Oc3KrFPdEr1EoMJR8P+wXevhA at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

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 :slight_smile:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

End of SDL Digest, Vol 74, Issue 3



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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 <@Joseba_Garcia_Etxeba> wrote:

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:

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?

Date: Mon, 4 Feb 2013 20:24:55 +0100
From: Joseba Garc?a Etxebarria <@Joseba_Garcia_Etxeba>
To: SDL Development List
Subject: Re: [SDL] [API Change Suggestion] Add sensor API
Message-ID:

<CAKJa1KmQ4L3q-YO9UKNiw4v76Oc3KrFPdEr1EoMJR8P+wXevhA at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

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 :slight_smile:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

End of SDL Digest, Vol 74, Issue 3



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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,
JosebaOn Mon, Feb 11, 2013 at 5:00 PM, Joseba Garc?a Etxebarria <@Joseba_Garcia_Etxeba> wrote:

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 <@Joseba_Garcia_Etxeba> wrote:

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:

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?

Date: Mon, 4 Feb 2013 20:24:55 +0100
From: Joseba Garc?a Etxebarria <@Joseba_Garcia_Etxeba>
To: SDL Development List
Subject: Re: [SDL] [API Change Suggestion] Add sensor API
Message-ID:

<CAKJa1KmQ4L3q-YO9UKNiw4v76Oc3KrFPdEr1EoMJR8P+wXevhA at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

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 :slight_smile:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

End of SDL Digest, Vol 74, Issue 3



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org