New timer for device information query in DeviceManager
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include "DeviceManager.h"
|
#include "DeviceManager.h"
|
||||||
#include "../event/EventCenter.h"
|
#include "../event/EventCenter.h"
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QTimerEvent>
|
||||||
|
|
||||||
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
|
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ std::string getJsonFromPatInf(QObject* obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::initDevice() {
|
void DeviceManager::initDevice() {
|
||||||
|
deviceInfTimerID = startTimer(1000);
|
||||||
// empty scan
|
// empty scan
|
||||||
connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){
|
connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){
|
||||||
std::string json= getJsonFromPatInf(detail);
|
std::string json= getJsonFromPatInf(detail);
|
||||||
@@ -74,40 +76,46 @@ void DeviceManager::initDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::timerEvent(QTimerEvent *event) {
|
void DeviceManager::timerEvent(QTimerEvent *event) {
|
||||||
StatusInfo inf = GetStatus();
|
if (event->timerId() !=deviceInfTimerID)
|
||||||
if (inf.status==SCANING)
|
|
||||||
{
|
{
|
||||||
lastStatus = SCANING;
|
StatusInfo inf = GetStatus();
|
||||||
//normal scan
|
if (inf.status==SCANING)
|
||||||
if(!previewing)
|
|
||||||
{
|
{
|
||||||
QVariant var(inf.progress);
|
lastStatus = SCANING;
|
||||||
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
|
//normal scan
|
||||||
}
|
if(!previewing)
|
||||||
//preview scan
|
{
|
||||||
else{
|
QVariant var(inf.progress);
|
||||||
const char * data = GetPreviewData();
|
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
|
||||||
QByteArray bytes =QByteArray::fromRawData(data,40000);
|
}
|
||||||
TRIGGER_EVENT(GUIEvents::ResponsePreviewData, nullptr, (QObject*)(&bytes));
|
//preview scan
|
||||||
delete [] data;
|
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{
|
} else{
|
||||||
if (lastStatus == SCANING && !errorOccured)
|
QString temp = QString(GetDeviceInf(MEAN_TEMPERATURE));
|
||||||
{
|
TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject*)&temp);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void processScan(const char * json);
|
void processScan(const char * json);
|
||||||
int timerID = -1;
|
int timerID = -1;
|
||||||
|
int deviceInfTimerID = -1;
|
||||||
int lastStatus=-1;
|
int lastStatus=-1;
|
||||||
bool previewing = false;
|
bool previewing = false;
|
||||||
bool errorOccured = false;
|
bool errorOccured = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user