src/joystick/emscripten/SDL_sysjoystick.c
changeset 12575 62f907f026bb
parent 12503 806492103856
equal deleted inserted replaced
12574:109c919d61f6 12575:62f907f026bb
   187 {
   187 {
   188     int retval, i, numjs;
   188     int retval, i, numjs;
   189     EmscriptenGamepadEvent gamepadState;
   189     EmscriptenGamepadEvent gamepadState;
   190 
   190 
   191     numjoysticks = 0;
   191     numjoysticks = 0;
       
   192 
       
   193     retval = emscripten_sample_gamepad_data();
       
   194 
       
   195     /* Check if gamepad is supported by browser */
       
   196     if (retval == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
       
   197         return SDL_SetError("Gamepads not supported");
       
   198     }
       
   199 
   192     numjs = emscripten_get_num_gamepads();
   200     numjs = emscripten_get_num_gamepads();
   193 
       
   194     /* Check if gamepad is supported by browser */
       
   195     if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
       
   196         return SDL_SetError("Gamepads not supported");
       
   197     }
       
   198 
   201 
   199     /* handle already connected gamepads */
   202     /* handle already connected gamepads */
   200     if (numjs > 0) {
   203     if (numjs > 0) {
   201         for(i = 0; i < numjs; i++) {
   204         for(i = 0; i < numjs; i++) {
   202             retval = emscripten_get_gamepad_status(i, &gamepadState);
   205             retval = emscripten_get_gamepad_status(i, &gamepadState);
   332 EMSCRIPTEN_JoystickUpdate(SDL_Joystick * joystick)
   335 EMSCRIPTEN_JoystickUpdate(SDL_Joystick * joystick)
   333 {
   336 {
   334     EmscriptenGamepadEvent gamepadState;
   337     EmscriptenGamepadEvent gamepadState;
   335     SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   338     SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   336     int i, result, buttonState;
   339     int i, result, buttonState;
       
   340 
       
   341     emscripten_sample_gamepad_data();
   337 
   342 
   338     if (item) {
   343     if (item) {
   339         result = emscripten_get_gamepad_status(item->index, &gamepadState);
   344         result = emscripten_get_gamepad_status(item->index, &gamepadState);
   340         if( result == EMSCRIPTEN_RESULT_SUCCESS) {
   345         if( result == EMSCRIPTEN_RESULT_SUCCESS) {
   341             if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
   346             if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {