diff --git a/src/ShimLib/ShimLib.c b/src/ShimLib/ShimLib.c index d178d27..775d168 100644 --- a/src/ShimLib/ShimLib.c +++ b/src/ShimLib/ShimLib.c @@ -27,20 +27,26 @@ volatile int running = 1; volatile int progress = 0; volatile int status = READY; volatile int stop_flag = 0; +volatile int empty = 0; char output_path[256] = {0}; void ThreadFunc(void* args){ while (running){ - WaitForSingleObject(e1, INFINITE); - status = SCANNING; stop_flag = 0; - progress = 0; - for (int i = 0; i <= 50; ++i) { - if (stop_flag > 0){ - stop_flag = 0; - break; - } + progress = 0; + WaitForSingleObject(e1, INFINITE); + status = SCANNING; + Sleep(300); + if (empty) + { + GetPreviewData(); + } + for (int i = 0; i <= 50; ++i) { + if (stop_flag > 0 || status != SCANNING){ + stop_flag = 0; + break; + } if (i == 20){ progress = 139; WaitForSingleObject(e2, INFINITE); @@ -53,6 +59,10 @@ void ThreadFunc(void* args){ } else{ progress = i *2; + } + if (stop_flag > 0 || status != SCANNING){ + stop_flag = 0; + break; } Sleep(300); } @@ -107,7 +117,8 @@ StatusInfo GetStatus() { } //result, 0 success, other false -int SetScanInfo(const char* jsonString, int empty) { +int SetScanInfo(const char* jsonString, int e) { + empty = e; return 0; } diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index 9781798..eef09da 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -53,7 +53,7 @@ void DeviceManager::emitErrorCallback(const char *msg) { void DeviceManager::initDevice() { InitLib(ErrorCallback); - deviceInfTimerID = startTimer(1000); + deviceInfTimerID = startTimer(10000); // empty scan connect(EventCenter::Default(), &EventCenter::RequestEmptyScan, [=](QObject* sender, QObject* detail) { @@ -207,6 +207,7 @@ void DeviceManager::timerEvent(QTimerEvent* event) { //scanning progress timer //error exit, callback error if (errorOccurred) { + timerID = event->timerId(); exitScanTimer(); return; } @@ -225,14 +226,14 @@ void DeviceManager::timerEvent(QTimerEvent* event) { return; } else { //未发生错误并且,之前状态是扫描,代表正常扫描完成 - if (lastStatus == SCANNING) { + if (lastStatus == SCANNING ) { prepareFinishScan(); } //一般不会出现其他情况 - else { - QString msg("Unknown error in scanning progress timer"); - THROW_ERROR(msg); - } +// else { +// QString msg("Unknown error in scanning progress timer"); +// THROW_ERROR(msg); +// } } } exitScanTimer(); @@ -280,7 +281,7 @@ void DeviceManager::scanProcess(int sProgress) { void DeviceManager::exitScanTimer() { qDebug() << "Scanning progress Timer exit"; - killTimer(timerID); + if (timerID>0)killTimer(timerID); timerID = -1; lastStatus = -1; previewing = false; @@ -358,7 +359,7 @@ void DeviceManager::postScanCommand() { previewing = false; scanPhase = 1; qDebug() << "Start progress timer"; - timerID = startTimer(500); + timerID = startTimer(2500); return; } //ScanControl fail diff --git a/src/device/DeviceManager.h b/src/device/DeviceManager.h index 6e7b64a..a9c5173 100644 --- a/src/device/DeviceManager.h +++ b/src/device/DeviceManager.h @@ -92,12 +92,12 @@ private: void scanProcess(int progress); int scanPhase = 1; - int timerID = -1; + volatile int timerID = -1; int deviceInfTimerID = -1; int lastStatus = -1; bool previewing = false; volatile bool endLoop = false; - bool errorOccurred = false; + volatile bool errorOccurred = false; QThread* previewDataCaller = nullptr; };