diff --git a/src/ShimLib/ShimLib.c b/src/ShimLib/ShimLib.c index e532fbf..ce8f366 100644 --- a/src/ShimLib/ShimLib.c +++ b/src/ShimLib/ShimLib.c @@ -13,17 +13,18 @@ error_cb innerCallback = NULL; void ThreadFunc(void*); HANDLE th; -HANDLE e1; +HANDLE e1,e2; int InitLib(error_cb cb) { innerCallback = cb; innerCallback("11111"); e1 = CreateEvent(NULL, FALSE, FALSE, "e1"); + e2 = CreateEvent(NULL, FALSE, FALSE, "e2"); th = _beginthread(ThreadFunc,0, NULL); return 0; } volatile int running = 1; -volatile float progress = 0.0f; +volatile int progress = 0; volatile int status = READY; volatile int stop_flag = 0; char output_path[256] = {0}; @@ -33,16 +34,25 @@ void ThreadFunc(void* args){ WaitForSingleObject(e1, INFINITE); status = SCANNING; stop_flag = 0; - progress = 0.0f; - for (int i = 0; i < 30; ++i) { + progress = 0; + for (int i = 0; i < 50; ++i) { if (stop_flag > 0){ stop_flag = 0; break; } - progress = (float)i * 0.1f; - if (i == 10){ - WaitForSingleObject(e1, INFINITE); + if (i == 20){ + progress = 139; + WaitForSingleObject(e2, INFINITE); + } + else if ( i > 20 && i<35){ + progress = i * 2 + 100; + } + else if(i >= 35){ + progress = i * 2 + 200; + } + else{ + progress = i *2; } Sleep(300); } @@ -53,32 +63,35 @@ void ThreadFunc(void* args){ int ScanControl(ScanAction actionType) { switch (actionType) { - case SCAN: - printf("Do Scan!\r\n"); - statusCountFlag = 2; - SYSTEMTIME st = {0}; - GetLocalTime(&st); - sprintf(output_path,"%d%02d%02dT%02d%02d%02d", - st.wYear, - st.wMonth, - st.wDay, - st.wHour, - st.wMinute, - st.wSecond); - SetEvent(e1); - break; - case PREVIEW_SCAN: - statusCountFlag = 1; - printf("Do preview!\r\n"); - break; - case STOP: - statusCountFlag = 0; - stop_flag = 1; - progress = 0.0f; - status = READY; - printf("Stop everything!\r\n"); - break; - } + case SCAN: + printf("Do Scan!\r\n"); + statusCountFlag = 2; + SYSTEMTIME st = {0}; + GetLocalTime(&st); + sprintf(output_path, "%d%02d%02dT%02d%02d%02d", + st.wYear, + st.wMonth, + st.wDay, + st.wHour, + st.wMinute, + st.wSecond); + SetEvent(e1); + break; + case PREVIEW_SCAN: + statusCountFlag = 1; + printf("Do preview!\r\n"); + break; + case STOP: + statusCountFlag = 0; + stop_flag = 1; + progress = 0; + status = READY; + printf("Stop everything!\r\n"); + break; + case SCAN_CONTINUE: + SetEvent(e2); + break; + } return 0; } @@ -135,5 +148,6 @@ const char* GetDeviceInfo(DeviceInfo infoType) { #ifdef _WIN32 void StopDevice(){ CloseHandle(e1); + CloseHandle(e2); } #endif diff --git a/src/ShimLib/ShimLib.h b/src/ShimLib/ShimLib.h index 6435f11..4ba9fb3 100644 --- a/src/ShimLib/ShimLib.h +++ b/src/ShimLib/ShimLib.h @@ -16,7 +16,7 @@ typedef enum { typedef struct StatusInfo { DeviceStatus status;// a enum represent device current status - float progress;// percent value of operation + int progress;// percent value of operation } StatusInfo; @@ -25,6 +25,7 @@ typedef enum { SCAN,// Start scan action PREVIEW_SCAN,// Start preview scan action STOP,// Stop current scan + SCAN_CONTINUE,//Continue pending scan } ScanAction; //kinds of device information diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index 25cda10..0efdbe0 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -69,6 +69,10 @@ void DeviceManager::initDevice() { processScan(json.c_str()); } }); + // Continue Scan + connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) { + postContinueCommand(true); + }); // stop connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() { qDebug() << "GetStatus"; @@ -207,14 +211,36 @@ void DeviceManager::timerEvent(QTimerEvent* event) { qDebug() << "Scanning request status, status:" << getStatusString(inf.status); //设备正常扫描中 if (inf.status == SCANNING) { - qDebug() <<"current output path:"< 3 || scanPhase > phase ){ + QString errorMsg = QString("Error Scan Phase code, current Phase code:%1, new Phase code:%2!").arg(scanPhase,phase); + THROW_ERROR(errorMsg) + goto exitTimer; + } + scanPhase = phase; + if (scanPhase == 2){ + if (!AppGlobalValues::EmptyScanFlag().toBool()) { + var.setValue(QString("Scan phase 2 waiting for patient!\r\n Click \"Next\" to continue!")); + TRIGGER_EVENT(GUIEvents::InvokeOperationPending, nullptr, (QObject *) &var); + goto exitTimer; + } + //empty scan no pending, auto continue + else { + postContinueCommand(); + } + } + } + return; + } else { //未发生错误并且,之前状态是扫描,代表正常扫描完成 if (lastStatus == SCANNING) { @@ -293,20 +319,36 @@ void DeviceManager::processScan(const char* json, bool empty) { return; } qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success"; - //ScanControl fail - qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>"; - if (!ScanControl(SCAN)) { - qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success"; - //set current state - lastStatus = SCANNING; - previewing = false; - qDebug() << "Start progress timer"; - timerID = startTimer(500); - return; - } - QString errmsg("ScanControl start fail!"); - THROW_ERROR(errmsg); - qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; + + postScanCommand(); +} + +void DeviceManager::postScanCommand() { + qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>"; + if (!ScanControl(SCAN)) { + qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success"; + //set current state + lastStatus = SCANNING; + previewing = false; + scanPhase = 1; + qDebug() << "Start progress timer"; + timerID = startTimer(500); + return; + } + //ScanControl fail + QString errmsg("ScanControl start fail!"); + THROW_ERROR(errmsg); + qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; +} + +void DeviceManager::postContinueCommand(bool useTimer) { + if (!ScanControl(SCAN_CONTINUE)) { + if (useTimer)timerID = startTimer(500); + return; + } + //ScanControl fail + QString errmsg("ScanControl start fail!"); + THROW_ERROR(errmsg); } void DeviceManager::close() { @@ -324,3 +366,5 @@ QString DeviceManager::getSoftwareVersion() { QString DeviceManager::getScanOutputPath() { return GetDeviceInfo(DEV_OUTPATH); } + + diff --git a/src/device/DeviceManager.h b/src/device/DeviceManager.h index 60aa53a..13414b1 100644 --- a/src/device/DeviceManager.h +++ b/src/device/DeviceManager.h @@ -34,6 +34,9 @@ protected: private: void processScan(const char* json, bool empty = false); + void postScanCommand(); + void postContinueCommand(bool useTimer = false); + int scanPhase = 1; int timerID = -1; int deviceInfTimerID = -1; int lastStatus = -1; diff --git a/src/windows/mainwindow.cpp b/src/windows/mainwindow.cpp index 42c4f43..312b8b9 100644 --- a/src/windows/mainwindow.cpp +++ b/src/windows/mainwindow.cpp @@ -1,4 +1,4 @@ -#include "mainwindow.h" +#include "mainwindow.h" #include "ui_mainwindow.h" #include #include @@ -126,7 +126,8 @@ MainWindow::MainWindow(QWidget* parent) : if (msg) { QVariant* var = (QVariant*)msg; - msgDialog->showMessage(QString("Scanning %1%").arg((int)(var->toFloat() * 100.0f))); + if (msgDialog->Pending())msgDialog->stopPending(); + msgDialog->showMessage(var->toString()); } else { msgDialog->hideMessage();