JoystickAndroid.h 1.38 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
    static bool init(JoystickManager *manager);
23 24

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

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

30 31
    static void setNativeMethods(JoystickManager *manager);

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

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

    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
48
    static int ACTION_DOWN, ACTION_UP;
49 50 51 52 53 54
    static QMutex m_mutex;

    int deviceId;
};

#endif // JOYSTICKANDROID_H