-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsmartpayout.cpp
76 lines (61 loc) · 1.74 KB
/
smartpayout.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
#include "smartpayout.h"
#include <QDebug>
#include "sspcoms.h"
#include "sspevents.h"
SmartPayout::SmartPayout(QObject *parent) :
QObject(parent), coms(nullptr) {
}
SmartPayout::~SmartPayout() {
if(coms) {
}
}
const QString &SmartPayout::device() const {
return m_device;
}
void SmartPayout::setDevice(const QString &dev) {
if(m_device != dev) {
m_device = dev;
if(coms != nullptr)
coms->setTerminate(true);
if(dev != "") {
qDebug() << "Opening device" << dev;
coms = new SSPComs(QSerialPortInfo(dev));
QObject::connect(coms, &SSPComs::terminating, [=]{
delete coms;
});
coms->startConnection();
coms->enable([]() {
qDebug() << "enable finished";
});
coms->datasetVersion([](const QString &datasetVersion){
qDebug() << "datasetVersion =" << datasetVersion;
});
coms->firmwareVersion([](const QString &firmwareVersion){
qDebug() << "firmwareVersion =" << firmwareVersion;
});
} else {
coms = nullptr;
}
emit deviceChanged(m_device);
}
}
void SmartPayout::test() {
coms->enable([]() {
qDebug() << "enable finished";
});
// coms->emptyAll([]() {
// qDebug() << "empty all finished";
// });
coms->displayOn([]() {
qDebug() << "displayOn finished";
});
}
void SmartPayout::poll() {
coms->poll([](const QList<QSharedPointer<SSPEvent>> &events){
qDebug() << "poll callback: got" << events.length() << "event(s)";
for(int i = 0; i < events.length(); i++) {
SSPEvent *event = events[i].data();
qDebug() << "poll callback: received: " << event->eventDescription();
}
});
}