New ShimLib simulation logic (windows only).

This commit is contained in:
Krad
2022-05-11 15:38:20 +08:00
parent 24f6e4e97c
commit 1abd387617
2 changed files with 71 additions and 49 deletions

View File

@@ -1,23 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include "ShimLib.h"
#include <Windows.h>
#include <process.h>
#include <time.h>
typedef void(*error_cb)(const char* msg);
int statusCountFlag = 0;
error_cb innerCallback = NULL;
void ThreadFunc(void*);
HANDLE th;
HANDLE e1;
int InitLib(error_cb cb) {
innerCallback = cb;
innerCallback("11111");
e1 = CreateEvent(NULL, FALSE, FALSE, "e1");
th = _beginthread(ThreadFunc,0, NULL);
return 0;
}
volatile int running = 1;
volatile float progress = 0.0f;
volatile int status = READY;
volatile int stop_flag = 0;
char output_path[256] = {0};
void ThreadFunc(void* args){
while (running){
WaitForSingleObject(e1, INFINITE);
status = SCANNING;
stop_flag = 0;
progress = 0.0f;
for (int i = 0; i < 30; ++i) {
if (stop_flag > 0){
stop_flag = 0;
break;
}
if (i == 20){
WaitForSingleObject(e1, INFINITE);
}
progress = (float)i * 0.1f;
Sleep(300);
}
status = READY;
}
}
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;
@@ -25,56 +72,20 @@ int ScanControl(ScanAction actionType) {
break;
case STOP:
statusCountFlag = 0;
stop_flag = 1;
status = READY;
printf("Stop everything!\r\n");
break;
}
return 0;
}
StatusInfo GetStatus() {
StatusInfo inf;
switch (statusCountFlag)
{
case 0:
inf.status = READY;
break;
case 1:
inf.status = SCANNING;
inf.progress = 0.0f;
break;
case 2:
inf.status = SCANNING;
inf.progress = 0.3f;
statusCountFlag++;
break;
case 3:
inf.status = SCANNING;
inf.progress = 0.6f;
statusCountFlag++;
break;
case 4:
inf.status = SCANNING;
inf.progress = 0.9f;
statusCountFlag++;
break;
case 5:
inf.status = SCANNING;
inf.progress = 1.0f;
statusCountFlag = 0;
break;
case 6:
// case 7:
// inf.status = BUSY;
// statusCountFlag++;
// break;
// case 8:
inf.status = BUSY;
statusCountFlag = 0;
break;
default:
inf.status = BUSY;
statusCountFlag = 0;
}
inf.status = status;
inf.progress = progress;
return inf;
}
@@ -114,7 +125,13 @@ const char* GetDeviceInfo(DeviceInfo infoType) {
case VERSION:
return "6.6.06";
case DEV_OUTPATH:
return "path to store bin";
return output_path;
}
return "";
}
#ifdef _WIN32
void StopDevice(){
CloseHandle(e1);
}
#endif

View File

@@ -46,6 +46,11 @@ extern const char *GetPreviewData();
extern const char *GetDeviceInfo(DeviceInfo infoType);
#ifdef _WIN32
extern void StopDevice();
#endif
#ifdef __cplusplus
};
#endif