New timer for device information query in DeviceManager
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "DeviceManager.h"
|
||||
#include "../event/EventCenter.h"
|
||||
#include <QVariant>
|
||||
#include <QTimerEvent>
|
||||
|
||||
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
|
||||
|
||||
@@ -17,6 +18,7 @@ std::string getJsonFromPatInf(QObject* obj)
|
||||
}
|
||||
|
||||
void DeviceManager::initDevice() {
|
||||
deviceInfTimerID = startTimer(1000);
|
||||
// empty scan
|
||||
connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){
|
||||
std::string json= getJsonFromPatInf(detail);
|
||||
@@ -74,40 +76,46 @@ void DeviceManager::initDevice() {
|
||||
}
|
||||
|
||||
void DeviceManager::timerEvent(QTimerEvent *event) {
|
||||
StatusInfo inf = GetStatus();
|
||||
if (inf.status==SCANING)
|
||||
if (event->timerId() !=deviceInfTimerID)
|
||||
{
|
||||
lastStatus = SCANING;
|
||||
//normal scan
|
||||
if(!previewing)
|
||||
StatusInfo inf = GetStatus();
|
||||
if (inf.status==SCANING)
|
||||
{
|
||||
QVariant var(inf.progress);
|
||||
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
|
||||
}
|
||||
//preview scan
|
||||
else{
|
||||
const char * data = GetPreviewData();
|
||||
QByteArray bytes =QByteArray::fromRawData(data,40000);
|
||||
TRIGGER_EVENT(GUIEvents::ResponsePreviewData, nullptr, (QObject*)(&bytes));
|
||||
delete [] data;
|
||||
}
|
||||
lastStatus = SCANING;
|
||||
//normal scan
|
||||
if(!previewing)
|
||||
{
|
||||
QVariant var(inf.progress);
|
||||
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
|
||||
}
|
||||
//preview scan
|
||||
else{
|
||||
const char * data = GetPreviewData();
|
||||
QByteArray bytes =QByteArray::fromRawData(data,40000);
|
||||
TRIGGER_EVENT(GUIEvents::ResponsePreviewData, nullptr, (QObject*)(&bytes));
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
} else{
|
||||
if (lastStatus == SCANING && !errorOccured)
|
||||
{
|
||||
QVariant var(true);
|
||||
TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, (QObject*)&var);
|
||||
lastStatus = -1;
|
||||
previewing = false;
|
||||
}
|
||||
//内部错误,导致Scan停止
|
||||
else if (lastStatus == SCANING && errorOccured)
|
||||
{
|
||||
//正常情况下,设备应该已经调用的错误callback,然后会回归Ready状态,清理lastStatus即可
|
||||
lastStatus = -1;
|
||||
previewing = false;
|
||||
}
|
||||
killTimer(timerID);
|
||||
}
|
||||
} else{
|
||||
if (lastStatus == SCANING && !errorOccured)
|
||||
{
|
||||
QVariant var(true);
|
||||
TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, (QObject*)&var);
|
||||
lastStatus = -1;
|
||||
previewing = false;
|
||||
}
|
||||
//内部错误,导致Scan停止
|
||||
else if (lastStatus == SCANING && errorOccured)
|
||||
{
|
||||
//正常情况下,设备应该已经调用的错误callback,然后会回归Ready状态,清理lastStatus即可
|
||||
lastStatus = -1;
|
||||
previewing = false;
|
||||
}
|
||||
killTimer(timerID);
|
||||
QString temp = QString(GetDeviceInf(MEAN_TEMPERATURE));
|
||||
TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject*)&temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ protected:
|
||||
private:
|
||||
void processScan(const char * json);
|
||||
int timerID = -1;
|
||||
int deviceInfTimerID = -1;
|
||||
int lastStatus=-1;
|
||||
bool previewing = false;
|
||||
bool errorOccured = false;
|
||||
|
||||
Reference in New Issue
Block a user