New ShimLib simulation logic (windows only).

This commit is contained in:
Krad
2022-05-11 15:38:20 +08:00
parent c83c72c5f7
commit 8f6ddc6119
2 changed files with 71 additions and 49 deletions

View File

@@ -1,23 +1,70 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ShimLib.h" #include "ShimLib.h"
#include <Windows.h>
#include <process.h>
#include <time.h>
typedef void(*error_cb)(const char* msg); typedef void(*error_cb)(const char* msg);
int statusCountFlag = 0; int statusCountFlag = 0;
error_cb innerCallback = NULL; error_cb innerCallback = NULL;
void ThreadFunc(void*);
HANDLE th;
HANDLE e1;
int InitLib(error_cb cb) { int InitLib(error_cb cb) {
innerCallback = cb; innerCallback = cb;
innerCallback("11111"); innerCallback("11111");
e1 = CreateEvent(NULL, FALSE, FALSE, "e1");
th = _beginthread(ThreadFunc,0, NULL);
return 0; 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) { int ScanControl(ScanAction actionType) {
switch (actionType) { switch (actionType) {
case SCAN: case SCAN:
printf("Do Scan!\r\n"); printf("Do Scan!\r\n");
statusCountFlag = 2; 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; break;
case PREVIEW_SCAN: case PREVIEW_SCAN:
statusCountFlag = 1; statusCountFlag = 1;
@@ -25,56 +72,20 @@ int ScanControl(ScanAction actionType) {
break; break;
case STOP: case STOP:
statusCountFlag = 0; statusCountFlag = 0;
stop_flag = 1;
status = READY;
printf("Stop everything!\r\n"); printf("Stop everything!\r\n");
break; break;
} }
return 0; return 0;
} }
StatusInfo GetStatus() { StatusInfo GetStatus() {
StatusInfo inf; StatusInfo inf;
switch (statusCountFlag) inf.status = status;
{ inf.progress = progress;
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;
}
return inf; return inf;
} }
@@ -109,12 +120,18 @@ const char* GetPreviewData() {
const char* GetDeviceInfo(DeviceInfo infoType) { const char* GetDeviceInfo(DeviceInfo infoType) {
switch (infoType) { switch (infoType) {
case MEAN_TEMPERATURE: case MEAN_TEMPERATURE:
return "28"; return "28";
case VERSION: case VERSION:
return "6.6.06"; return "6.6.06";
case DEV_OUTPATH: case DEV_OUTPATH:
return "path to store bin"; return output_path;
} }
return ""; return "";
} }
#ifdef _WIN32
void StopDevice(){
CloseHandle(e1);
}
#endif

View File

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