From 2159de66c46f664ba8dbe0a40899da33e780399a Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Thu, 12 Dec 2013 14:55:33 -0300 Subject: [PATCH] [Android] Poll joysticks every three seconds --- src/joystick/android/SDL_sysjoystick.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 7e3c59506..673c62a9d 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -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 @@ int SDL_SYS_NumJoysticks() 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()