#ifndef _JOYSTICK_H_ #define _JOYSTICK_H_ #include #include #include #include #include #include #define SDL_JOYSTICK_DEFAULT_EVENT_TIMEOUT 25 #define SDL_JOYSTICK_DEFAULT_AUTOREPEAT_DELAY 250 class Joystick : public QObject { Q_OBJECT public: QStringList joystickNames; SDL_Joystick *joystick; int numAxes; int numButtons; int numHats; int numTrackballs; int eventTimeout; int autoRepeatDelay; bool autoRepeat; QTimer joystickTimer; 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(); bool open(int); void close(); bool isOpen() { return joystick != NULL; } int getAxisValue(int); private: QMap axes; QMap buttons; QMap hats; QMap axisRepeatTimers; QMap buttonRepeatTimers; QMap hatRepeatTimers; signals: void axisValueChanged(int axis, int value); void buttonValueChanged(int button, bool value); void hatValueChanged(int hat, int value); void trackballValueChanged(int trackball, int deltaX, int deltaY); public slots: void processEvents(); }; #endif