-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDeviceManagerWrapper.cpp
85 lines (69 loc) · 5.51 KB
/
DeviceManagerWrapper.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
#include "DeviceManagerWrapper.h"
DeviceManagerWrapper::DeviceManagerWrapper(QObject* parent) :
QObject(parent)
{
workerObject_ = std::make_unique<DeviceManager>();
#ifdef SEPARATE_READING
workerThread_ = std::make_unique<QThread>(this);
auto connectionType = Qt::AutoConnection;
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendOpenFile, workerObject_.get(), &DeviceManager::openFile, connectionType));
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendCloseFile, workerObject_.get(), &DeviceManager::closeFile, connectionType));
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::devChanged, this, &DeviceManagerWrapper::devChanged, connectionType));
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::streamChanged, this, &DeviceManagerWrapper::streamChanged, connectionType));
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::vruChanged, this, &DeviceManagerWrapper::vruChanged, connectionType));
#ifdef MOTOR
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::motorDeviceChanged, this, &DeviceManagerWrapper::motorDeviceChanged, connectionType));
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::anglesHasChanged, this, &DeviceManagerWrapper::angleChanged, connectionType));
deviceManagerConnections_.append(QObject::connect(workerObject_.get(), &DeviceManager::posIsConstant, this, &DeviceManagerWrapper::posIsConstant, connectionType));
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendRunSteps, workerObject_.get(), &DeviceManager::runSteps, connectionType));
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendReturnToZero, workerObject_.get(), &DeviceManager::returnToZero, connectionType));
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendOpenCsvFile, workerObject_.get(), &DeviceManager::openCsvFile, connectionType));
deviceManagerConnections_.append(QObject::connect(this, &DeviceManagerWrapper::sendClearTasks, workerObject_.get(), &DeviceManager::clearTasks, connectionType));
#endif
workerObject_->moveToThread(workerThread_.get());
workerThread_->start();
#else
auto connectionType = Qt::DirectConnection;
QObject::connect(this, &DeviceManagerWrapper::sendOpenFile, workerObject_.get(), &DeviceManager::openFile, connectionType);
QObject::connect(this, &DeviceManagerWrapper::sendCloseFile, workerObject_.get(), &DeviceManager::closeFile, connectionType);
QObject::connect(workerObject_.get(), &DeviceManager::devChanged, this, &DeviceManagerWrapper::devChanged, connectionType);
QObject::connect(workerObject_.get(), &DeviceManager::streamChanged, this, &DeviceManagerWrapper::streamChanged, connectionType);
QObject::connect(workerObject_.get(), &DeviceManager::vruChanged, this, &DeviceManagerWrapper::vruChanged, connectionType);
#ifdef MOTOR
QObject::connect(workerObject_.get(), &DeviceManager::motorDeviceChanged, this, &DeviceManagerWrapper::motorDeviceChanged, connectionType);
QObject::connect(workerObject_.get(), &DeviceManager::anglesHasChanged, this, &DeviceManagerWrapper::angleChanged, connectionType);
QObject::connect(workerObject_.get(), &DeviceManager::posIsConstant, this, &DeviceManagerWrapper::posIsConstant, connectionType);
QObject::connect(this, &DeviceManagerWrapper::sendRunSteps, workerObject_.get(), &DeviceManager::runSteps, connectionType);
QObject::connect(this, &DeviceManagerWrapper::sendReturnToZero, workerObject_.get(), &DeviceManager::returnToZero, connectionType);
QObject::connect(this, &DeviceManagerWrapper::sendOpenCsvFile, workerObject_.get(), &DeviceManager::openCsvFile, connectionType);
QObject::connect(this, &DeviceManagerWrapper::sendClearTasks, workerObject_.get(), &DeviceManager::clearTasks, connectionType);
#endif
#endif
}
DeviceManagerWrapper::~DeviceManagerWrapper()
{
#ifdef SEPARATE_READING
for (auto& itm : deviceManagerConnections_)
QObject::disconnect(itm);
deviceManagerConnections_.clear();
workerThread_->quit();
workerThread_->wait();
workerThread_.reset();
workerObject_.reset();
#endif
}
DeviceManager* DeviceManagerWrapper::getWorker()
{
return workerObject_.get();
}
#ifdef MOTOR
void DeviceManagerWrapper::posIsConstant(float currFAngle, float taskFAngle, float currSAngle, float taskSAngle)
{
qDebug() << "DeviceManagerWrapper::posIsConstant: currFAngle: " << currFAngle << ", taskFAngle: " << taskFAngle << ", currSAngle: " << currSAngle << ", taskSAngle: " << taskSAngle;
currFAngle_ = currFAngle;
currSAngle_ = currSAngle;
taskFAngle_ = taskFAngle;
taskSAngle_ = taskSAngle;
emit enginesStopped();
}
#endif