-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamepadthread.cpp
113 lines (92 loc) · 2.86 KB
/
gamepadthread.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "gamepadthread.h"
#include <QThread>
#include <QObject>
#include <QMessageBox>
#include <QDebug>
GamepadThread::GamepadThread()
{
auto gamepads = QGamepadManager::instance()->connectedGamepads();
m_gamepad = new QGamepad(*gamepads.begin(), this);
connect(m_gamepad, &QGamepad::axisLeftXChanged, this, [this](double value){
qDebug() << "Left X" << value;
});
connect(m_gamepad, &QGamepad::axisLeftYChanged, this, [this](double value){
qDebug() << "Left Y" << value;
});
connect(m_gamepad, &QGamepad::axisRightXChanged, this, [this](double value){
qDebug() << "Right X" << value;
});
connect(m_gamepad, &QGamepad::axisRightYChanged, this, [this](double value){
qDebug() << "Right Y" << value;
});
connect(m_gamepad, &QGamepad::buttonAChanged, this,[this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonA);
}
});
connect(m_gamepad, &QGamepad::buttonBChanged, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonB);
}
});
connect(m_gamepad, &QGamepad::buttonXChanged, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonX);
}
});
connect(m_gamepad, &QGamepad::buttonYChanged, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonY);
}
});
connect(m_gamepad, &QGamepad::buttonL1Changed, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonL1);
}
});
connect(m_gamepad, &QGamepad::buttonR1Changed, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonR1);
}
});
connect(m_gamepad, &QGamepad::buttonL2Changed, this, [this](double value){
emit sendCmd(config.cmd_buttonL2+ ": "+QString::number(value));
});
connect(m_gamepad, &QGamepad::buttonR2Changed, this, [this](double value){
emit sendCmd(config.cmd_buttonR2+ ": "+QString::number(value));
});
connect(m_gamepad, &QGamepad::buttonSelectChanged, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonBack);
}
});
connect(m_gamepad, &QGamepad::buttonStartChanged, this, [this](bool pressed){
if(pressed){
emit sendCmd(config.cmd_buttonStart);
}
});
connect(m_gamepad, &QGamepad::buttonGuideChanged, this, [](bool pressed){
qDebug() << "Button Guide" << pressed;
});
}
void GamepadThread::run(void)
{
}
bool GamepadThread::abortConnection()
{
return true;
}
void GamepadThread::stop()
{
threadRun = false;
}
void GamepadThread::updateConfig(gamepad_config_t* pConfig)
{
this->config = *pConfig;
}
void GamepadThread::onButtonA(bool pressed)
{
if(pressed){
emit sendCmd(config.cmd_buttonA);
}
}