The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[API Change Suggestion] Add sensor API
josebagar


Joined: 10 Dec 2010
Posts: 87
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?