We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5052

Summary: Interval between SDL_SENSORUPDATE events for gyroscopes is too high
Product: SDL Reporter: Andrei Kortunov <andrei.kortunov>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.9   
Hardware: ARM   
OS: Android (All)   

Description Andrei Kortunov 2020-03-22 18:02:28 UTC
Hello. I try to implement an application for Android, which uses a new sensors API from 2.0.9 to control a camera rotation via built-in gyroscope, using the code from the test/testsensor.c as an example.

Gyroscope input itself works well, but an interval between SDL_SENSORUPDATE events is about 200ms (the SENSOR_DELAY_NORMAL, I believe), when I need the interval about 20-40ms (the SENSOR_DELAY_GAME or SENSOR_DELAY_FASTEST).

For example, Unity3D has the Input.gyro.updateInterval attribute to control a gyroscope update interval. Is there a way to do something like that in SDL2?
Comment 1 Andrei Kortunov 2020-03-22 19:59:03 UTC
In theory, the value can be controlled via ASensorEventQueue_setEventRate() function on Android, somewhere in the SDL_androidsensor.c:

ASensorEventQueue_setEventRate(hwdata->eventqueue, hwdata->asensor, desiredDelay);

It would be nice to have an optional argument for SDL_SensorOpen function to specify the update interval.

To get the minimum supported interval (SENSOR_DELAY_FASTEST), it is possible to use the ASensor_getMinDelay().
Comment 2 Sam Lantinga 2020-03-23 19:10:56 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/06adf174772e