New timer for device information query in DeviceManager

This commit is contained in:
Krad
2021-10-14 17:52:43 +08:00
parent 153d4f8a37
commit 6969f55779
2 changed files with 39 additions and 30 deletions

View File

@@ -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);
}
}

View File

@@ -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;