forked from psemiletov/tea-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myjoystick.h
80 lines (49 loc) · 1.26 KB
/
myjoystick.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//this code by Peter Semiletov is the public domain
#include <QtGlobal>
#include <QObject>
#ifndef MYJOYSTICK_H
#define MYJOYSTICK_H
#if defined(JOYSTICK_SUPPORTED)
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/joystick.h>
#include <QEvent>
const QEvent::Type evtJoystickAxis = QEvent::Type (QEvent::User + 1);
const QEvent::Type evtJoystickButton = QEvent::Type (QEvent::User + 2);
class CJoystickButtonEvent: public QEvent
{
public:
uint button;
bool pressed;
CJoystickButtonEvent (QEvent::Type type): QEvent (type), button (0), pressed (false) {}
};
class CJoystickAxisEvent: public QEvent
{
public:
uint axis;
qint16 value;
CJoystickAxisEvent (QEvent::Type type): QEvent (type), axis (0), value (0) {}
};
class CJoystick: public QObject
{
Q_OBJECT
public:
QObject *receiver; //link to the object that handle joystick events
int fd; //joystick file descriptor
uint id; //joystick id
int etype;
bool axis_pressed;
QString description; //joystick text description
bool initialized;
uint number_of_axis;
uint number_of_buttons;
CJoystick (uint idn, QObject *upper_link);
~CJoystick();
void process_event (js_event e);
public slots:
void read_joystick();
};
#endif
#endif