Phase control workflow logic

This commit is contained in:
Krad
2022-05-12 14:53:17 +08:00
parent 6ba9786efb
commit ae89aeffe4
5 changed files with 121 additions and 58 deletions

View File

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

View File

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