void Joystick::processEvents() { if ( !isOpen() ) return; SDL_JoystickUpdate(); int i; for (i = 0; i < numAxes; i++) { Sint16 moved = SDL_JoystickGetAxis(joystick, i); if ( abs(moved) >= deadzones[i] ) { if ( (moved != axes[i]) ) { int deltaMoved = abs(axes[i] - moved); if ( deltaMoved >= sensitivities[i] ) emit axisValueChanged(i, moved); axes[i] = moved; axisRepeatTimers[i].restart(); } else if (autoRepeat && moved != 0) { if ( axisRepeatTimers[i].elapsed() >= autoRepeatDelay ) { emit axisValueChanged(i, moved); axes[i] = moved; } } else axisRepeatTimers[i].restart(); } else emit axisValueChanged(i, 0); } for (i = 0; i < numButtons; i++) { Uint8 changed = SDL_JoystickGetButton(joystick, i); if ( (changed != buttons[i]) ) { emit buttonValueChanged(i, (bool) changed); buttons[i] = changed; buttonRepeatTimers[i].restart(); } else if (autoRepeat && changed != 0) { if ( buttonRepeatTimers[i].elapsed() >= autoRepeatDelay ) { emit buttonValueChanged(i, (bool) changed); buttons[i] = changed; } } else buttonRepeatTimers[i].restart(); } for (i = 0; i < numHats; i++) { Uint8 changed = SDL_JoystickGetHat(joystick, i); if ( (changed != hats[i]) ) { emit hatValueChanged(i, changed); hats[i] = changed; hatRepeatTimers[i].restart(); } else if (autoRepeat && changed != 0) { if ( hatRepeatTimers[i].elapsed() >= autoRepeatDelay ) { emit hatValueChanged(i, changed); hats[i] = changed; } } else hatRepeatTimers[i].restart(); } for (i = 0; i < numTrackballs; i++) { int dx, dy; SDL_JoystickGetBall(joystick, i, &dx, &dy); if ( dx != 0 || dy != 0 ) emit trackballValueChanged(i, dx, dy); } }
void QJoystick::axisValueChanged__(int axis, int value) { if(axis_old_values[axis]==value) return; axis_old_values[axis] = value; emit axisValueChanged(axis, value); }