Files
GUI/src/ShimLib/ShimLib.c

140 lines
2.6 KiB
C
Raw Normal View History

2021-12-07 15:15:05 +08:00
#include <stdio.h>
#include <stdlib.h>
#include "ShimLib.h"
#include <Windows.h>
#include <process.h>
#include <time.h>
2022-01-04 17:06:49 +08:00
typedef void(*error_cb)(const char* msg);
2021-12-07 15:15:05 +08:00
int statusCountFlag = 0;
error_cb innerCallback = NULL;
void ThreadFunc(void*);
HANDLE th;
HANDLE e1;
2022-01-04 17:06:49 +08:00
int InitLib(error_cb cb) {
innerCallback = cb;
2022-01-11 13:07:03 +08:00
innerCallback("11111");
e1 = CreateEvent(NULL, FALSE, FALSE, "e1");
th = _beginthread(ThreadFunc,0, NULL);
2022-01-04 17:06:49 +08:00
return 0;
2021-12-07 15:15:05 +08:00
}
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;
}
2022-05-12 09:04:02 +08:00
progress = (float)i * 0.1f;
2022-05-12 09:04:02 +08:00
if (i == 10){
WaitForSingleObject(e1, INFINITE);
}
Sleep(300);
}
status = READY;
}
}
2022-01-04 17:06:49 +08:00
int ScanControl(ScanAction actionType) {
2022-01-04 17:06:49 +08:00
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);
2022-01-04 17:06:49 +08:00
break;
case PREVIEW_SCAN:
statusCountFlag = 1;
printf("Do preview!\r\n");
break;
case STOP:
statusCountFlag = 0;
stop_flag = 1;
2022-05-12 09:04:02 +08:00
progress = 0.0f;
status = READY;
2022-01-04 17:06:49 +08:00
printf("Stop everything!\r\n");
break;
}
return 0;
2021-12-07 15:15:05 +08:00
}
2022-01-04 17:06:49 +08:00
StatusInfo GetStatus() {
StatusInfo inf;
inf.status = status;
inf.progress = progress;
2022-01-04 17:06:49 +08:00
return inf;
2021-12-07 15:15:05 +08:00
}
//result, 0 success, other false
2022-01-04 17:06:49 +08:00
int SetScanInfo(const char* jsonString, int empty) {
return 0;
2021-12-07 15:15:05 +08:00
}
int preivew_change_flag = 0;
const size_t Row = 140;
const size_t Col = 140;
#define BUFFER_SIZE Row * Col
2022-01-04 17:06:49 +08:00
const char* FRAME_FILE_PATH_1 = "./img1_v2.bin";
const char* FRAME_FILE_PATH_2 = "./pre_image.bin";
const char* GetPreviewData() {
FILE* file;
preivew_change_flag++;
preivew_change_flag = preivew_change_flag % 2;
// _sleep(2000);
if (file = fopen(preivew_change_flag ? FRAME_FILE_PATH_1 : FRAME_FILE_PATH_2, "rb")) {
unsigned char* buffer = malloc(sizeof(unsigned char) * BUFFER_SIZE);
fread(buffer, sizeof(unsigned char), BUFFER_SIZE, file);
fclose(file);
return buffer;
}
2021-12-07 15:15:05 +08:00
2022-01-04 17:06:49 +08:00
return NULL;
2021-12-07 15:15:05 +08:00
}
2022-01-04 17:06:49 +08:00
const char* GetDeviceInfo(DeviceInfo infoType) {
switch (infoType) {
case MEAN_TEMPERATURE:
return "28";
case VERSION:
return "6.6.06";
case DEV_OUTPATH:
return output_path;
2022-01-04 17:06:49 +08:00
}
return "";
2021-12-07 15:15:05 +08:00
}
#ifdef _WIN32
void StopDevice(){
CloseHandle(e1);
}
#endif