forked from vranki/ExtPlane-Panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextplaneclient.cpp
More file actions
58 lines (50 loc) · 1.58 KB
/
extplaneclient.cpp
File metadata and controls
58 lines (50 loc) · 1.58 KB
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
#include "extplaneclient.h"
#include <QDebug>
ExtPlaneClient::ExtPlaneClient(QObject *parent, QString name, ClientDataRefProvicer *drp) :
QObject(parent), _name(name), _connection(drp)
{
}
ExtPlaneClient::~ExtPlaneClient() {
foreach(ClientDataRef *ref, _dataRefs) {
_connection->unsubscribeDataRef(ref);
}
_dataRefs.clear();
}
void ExtPlaneClient::subscribeDataRef(QString name, double accuracy) {
ClientDataRef *ref = _connection->subscribeDataRef(name, accuracy);
connect(ref, SIGNAL(changed(ClientDataRef*)), this, SLOT(cdrChanged(ClientDataRef*)));
_dataRefs.append(ref);
}
void ExtPlaneClient::cdrChanged(ClientDataRef *ref) {
double value;
bool ok;
value = ref->valueString().toDouble(&ok);
if (ok){
emit refChanged(ref->name(), value);
} else {
qDebug() << Q_FUNC_INFO << "unable to convert to double " << ref->valueString();
emit refChanged(ref->name(), ref->valueString());
}
}
void ExtPlaneClient::unsubscribeDataRef(QString name) {
foreach(ClientDataRef *ref, _dataRefs) {
if(ref->name() == name) {
// disconnect(ref, 0, this, 0);
_connection->unsubscribeDataRef(ref);
_dataRefs.removeOne(ref);
return;
}
}
}
void ExtPlaneClient::keyPress(int id) {
_connection->keyPress(id);
}
void ExtPlaneClient::buttonPress(int id) {
_heldButtons.insert(id);
_connection->buttonPress(id);
}
void ExtPlaneClient::buttonRelease(int id) {
if(!_heldButtons.contains(id)) return;
_heldButtons.remove(id);
_connection->buttonRelease(id);
}