JoystickAndroid.h 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#ifndef JOYSTICKANDROID_H
#define JOYSTICKANDROID_H

#include "Joystick.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"

#include <jni.h>
#include <QtCore/private/qjni_p.h>
#include <QtCore/private/qjnihelpers_p.h>
#include <QtAndroidExtras/QtAndroidExtras>
#include <QtAndroidExtras/QAndroidJniObject>


class JoystickAndroid : public Joystick, public QtAndroidPrivate::GenericMotionEventListener, public QtAndroidPrivate::KeyEventListener
{
public:
Gregory Dymarek's avatar
Gregory Dymarek committed
18
    JoystickAndroid(const QString& name, int axisCount, int buttonCount, int id, MultiVehicleManager* multiVehicleManager);
19

20 21
    ~JoystickAndroid();

22 23 24
    static bool init();

    static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
25 26 27 28 29

private:
    bool handleKeyEvent(jobject event);
    bool handleGenericMotionEvent(jobject event);

Gregory Dymarek's avatar
Gregory Dymarek committed
30 31 32
    virtual bool _open();
    virtual void _close();
    virtual bool _update();
33

Gregory Dymarek's avatar
Gregory Dymarek committed
34 35 36
    virtual bool _getButton(int i);
    virtual int _getAxis(int i);
    virtual uint8_t _getHat(int hat,int i);
37 38 39 40 41 42 43 44 45

    int *btnCode;
    int *axisCode;
    bool *btnValue;
    int *axisValue;

    static int * _androidBtnList; //list of all possible android buttons
    static int _androidBtnListCount;

Gregory Dymarek's avatar
Gregory Dymarek committed
46
    static int ACTION_DOWN, ACTION_UP;
47 48 49 50 51 52
    static QMutex m_mutex;

    int deviceId;
};

#endif // JOYSTICKANDROID_H