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 "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,6 +76,8 @@ void DeviceManager::initDevice() {
} }
void DeviceManager::timerEvent(QTimerEvent *event) { void DeviceManager::timerEvent(QTimerEvent *event) {
if (event->timerId() !=deviceInfTimerID)
{
StatusInfo inf = GetStatus(); StatusInfo inf = GetStatus();
if (inf.status==SCANING) if (inf.status==SCANING)
{ {
@@ -109,6 +113,10 @@ void DeviceManager::timerEvent(QTimerEvent *event) {
} }
killTimer(timerID); killTimer(timerID);
} }
} else{
QString temp = QString(GetDeviceInf(MEAN_TEMPERATURE));
TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject*)&temp);
}
} }
void DeviceManager::processScan(const char *json) { void DeviceManager::processScan(const char *json) {

View File

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