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