[Android] Poll joysticks every three seconds
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 12 Dec 2013 14:55:33 -0300
changeset 8060d1948d163145
parent 8059 e70f5749f692
child 8061 a5f8137ccf01
[Android] Poll joysticks every three seconds
src/joystick/android/SDL_sysjoystick.c
     1.1 --- a/src/joystick/android/SDL_sysjoystick.c	Wed Dec 11 21:17:24 2013 -0800
     1.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Thu Dec 12 14:55:33 2013 -0300
     1.3 @@ -34,6 +34,7 @@
     1.4  #include "SDL_joystick.h"
     1.5  #include "SDL_hints.h"
     1.6  #include "SDL_assert.h"
     1.7 +#include "SDL_timer.h"
     1.8  #include "SDL_sysjoystick_c.h"
     1.9  #include "../SDL_joystick_c.h"
    1.10  #include "../../core/android/SDL_android.h"
    1.11 @@ -339,10 +340,14 @@
    1.12  void SDL_SYS_JoystickDetect()
    1.13  {
    1.14      /* Support for device connect/disconnect is API >= 16 only,
    1.15 -     * so we have to poll ever few seconds.
    1.16 +     * so we poll every three seconds
    1.17       * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
    1.18       */
    1.19 -    Android_JNI_PollInputDevices();   
    1.20 +    static Uint32 timeout = 0;
    1.21 +    if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
    1.22 +        timeout = SDL_GetTicks() + 3000;
    1.23 +        Android_JNI_PollInputDevices();
    1.24 +    }
    1.25  }
    1.26  
    1.27  SDL_bool SDL_SYS_JoystickNeedsPolling()