diff --git a/companion/src/simulation/joystick.cpp b/companion/src/simulation/joystick.cpp index 87f7476f0..012694e92 100644 --- a/companion/src/simulation/joystick.cpp +++ b/companion/src/simulation/joystick.cpp @@ -108,37 +108,43 @@ void Joystick::processEvents() } for (i = 0; i < numButtons; i++) { Uint8 changed = SDL_JoystickGetButton(joystick, i); - if ( (changed != buttons[i]) ) { + if (changed != buttons[i]) { emit buttonValueChanged(i, (bool) changed); buttons[i] = changed; buttonRepeatTimers[i].restart(); - } else if (autoRepeat && changed != 0) { + } + else if (autoRepeat && changed != 0) { if ( buttonRepeatTimers[i].elapsed() >= autoRepeatDelay ) { emit buttonValueChanged(i, (bool) changed); buttons[i] = changed; } - } else + } + else { buttonRepeatTimers[i].restart(); + } } for (i = 0; i < numHats; i++) { Uint8 changed = SDL_JoystickGetHat(joystick, i); - if ( (changed != hats[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 ) { + } + else if (autoRepeat && changed != 0) { + if (hatRepeatTimers[i].elapsed() >= autoRepeatDelay) { emit hatValueChanged(i, changed); hats[i] = changed; } - } else + } + else { hatRepeatTimers[i].restart(); + } } for (i = 0; i < numTrackballs; i++) { int dx, dy; SDL_JoystickGetBall(joystick, i, &dx, &dy); - if ( dx != 0 || dy != 0 ) + if (dx != 0 || dy != 0) emit trackballValueChanged(i, dx, dy); } } diff --git a/companion/src/simulation/joystick.h b/companion/src/simulation/joystick.h index 5e2b4e863..ad167eaf7 100644 --- a/companion/src/simulation/joystick.h +++ b/companion/src/simulation/joystick.h @@ -49,14 +49,17 @@ class Joystick : public QObject QMap deadzones; QMap sensitivities; - Joystick(QObject *parent = 0, - int joystickEventTimeout = SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT, - bool doAutoRepeat = true, - int autoRepeatDelay = SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY); - ~Joystick(); + explicit Joystick(QObject * parent = nullptr, + int joystickEventTimeout = SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT, + bool doAutoRepeat = true, + int autoRepeatDelay = SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY); + ~Joystick() override; bool open(int); void close(); - bool isOpen() { return joystick != NULL; } + bool isOpen() + { + return joystick != nullptr; + } int getAxisValue(int); private: