/* Function to update the state of a joystick - called as a device poll. * This function shouldn't update the joystick structure directly, * but instead should call SDL_PrivateJoystick*() to deliver events * and update joystick device state. */ static __inline__ void JS_HandleEvents(SDL_Joystick *joystick) { struct js_event events[32]; int i, len; Uint8 other_axis; #ifndef NO_LOGICAL_JOYSTICKS if (SDL_joylist[joystick->index].fname == NULL) { SDL_joylist_head(i, joystick->index); JS_HandleEvents(SDL_joylist[i].joy); return; } #endif while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { len /= sizeof(events[0]); for ( i=0; i<len; ++i ) { switch (events[i].type & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: if ( events[i].number < joystick->naxes ) { #ifndef NO_LOGICAL_JOYSTICKS if (!LogicalJoystickAxis(joystick, events[i].number, events[i].value)) #endif SDL_PrivateJoystickAxis(joystick, events[i].number, events[i].value); break; } events[i].number -= joystick->naxes; other_axis = (events[i].number / 2); if ( other_axis < joystick->nhats ) { HandleHat(joystick, other_axis, events[i].number%2, events[i].value); break; } events[i].number -= joystick->nhats*2; other_axis = (events[i].number / 2); if ( other_axis < joystick->nballs ) { HandleBall(joystick, other_axis, events[i].number%2, events[i].value); break; } break; case JS_EVENT_BUTTON: #ifndef NO_LOGICAL_JOYSTICKS if (!LogicalJoystickButton(joystick, events[i].number, events[i].value)) #endif SDL_PrivateJoystickButton(joystick, events[i].number, events[i].value); break; default: /* ?? */ break; } } } }
void STJoystick::Sys_Update() { int i; #if SDL_INPUT_LINUXEV if ( joystick_data->hwdata->is_hid ) EV_HandleEvents(this->joystick_data); else #endif JS_HandleEvents(this->joystick_data); /* Deliver ball motion updates */ for ( i=0; i<joystick_data->nballs; ++i ) { int xrel, yrel; xrel = joystick_data->hwdata->balls[i].axis[0]; yrel = joystick_data->hwdata->balls[i].axis[1]; if ( xrel || yrel ) { joystick_data->hwdata->balls[i].axis[0] = 0; joystick_data->hwdata->balls[i].axis[1] = 0; joystick_data->balls[i].dx = xrel; joystick_data->balls[i].dy = yrel; } } }
void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) { int i; #if SDL_INPUT_LINUXEV if (joystick->hwdata->is_hid) EV_HandleEvents(joystick); else #endif JS_HandleEvents(joystick); /* Deliver ball motion updates */ for (i = 0; i < joystick->nballs; ++i) { int xrel, yrel; xrel = joystick->hwdata->balls[i].axis[0]; yrel = joystick->hwdata->balls[i].axis[1]; if (xrel || yrel) { joystick->hwdata->balls[i].axis[0] = 0; joystick->hwdata->balls[i].axis[1] = 0; SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel); } } }