From 8f6ddc611937aaeedf0863f307ab249e1bf4e653 Mon Sep 17 00:00:00 2001 From: Krad Date: Wed, 11 May 2022 15:38:20 +0800 Subject: [PATCH] New ShimLib simulation logic (windows only). --- src/ShimLib/ShimLib.c | 115 ++++++++++++++++++++++++------------------ src/ShimLib/ShimLib.h | 5 ++ 2 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/ShimLib/ShimLib.c b/src/ShimLib/ShimLib.c index b555f5d..7ed4a24 100644 --- a/src/ShimLib/ShimLib.c +++ b/src/ShimLib/ShimLib.c @@ -1,23 +1,70 @@ #include #include #include "ShimLib.h" + +#include +#include +#include + 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; } @@ -109,12 +120,18 @@ const char* GetPreviewData() { const char* GetDeviceInfo(DeviceInfo infoType) { switch (infoType) { - case MEAN_TEMPERATURE: - return "28"; - case VERSION: - return "6.6.06"; - case DEV_OUTPATH: - return "path to store bin"; + case MEAN_TEMPERATURE: + return "28"; + case VERSION: + return "6.6.06"; + case DEV_OUTPATH: + return output_path; } return ""; } + +#ifdef _WIN32 +void StopDevice(){ + CloseHandle(e1); +} +#endif diff --git a/src/ShimLib/ShimLib.h b/src/ShimLib/ShimLib.h index 8956953..6435f11 100644 --- a/src/ShimLib/ShimLib.h +++ b/src/ShimLib/ShimLib.h @@ -46,6 +46,11 @@ extern const char *GetPreviewData(); extern const char *GetDeviceInfo(DeviceInfo infoType); +#ifdef _WIN32 +extern void StopDevice(); +#endif + + #ifdef __cplusplus }; #endif