164 lines
3.4 KiB
C
164 lines
3.4 KiB
C
#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,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 int progress = 0;
|
|
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;
|
|
for (int i = 0; i <= 50; ++i) {
|
|
if (stop_flag > 0){
|
|
stop_flag = 0;
|
|
break;
|
|
}
|
|
|
|
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);
|
|
}
|
|
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;
|
|
status = SCANNING;
|
|
printf("Do preview!\r\n");
|
|
break;
|
|
case STOP:
|
|
statusCountFlag = 0;
|
|
stop_flag = 1;
|
|
progress = 0;
|
|
status = READY;
|
|
SetEvent(e2);
|
|
printf("Stop everything!\r\n");
|
|
break;
|
|
case SCAN_CONTINUE:
|
|
SetEvent(e2);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
StatusInfo GetStatus() {
|
|
StatusInfo inf;
|
|
inf.status = status;
|
|
inf.progress = progress;
|
|
return inf;
|
|
}
|
|
|
|
//result, 0 success, other false
|
|
int SetScanInfo(const char* jsonString, int empty) {
|
|
return 0;
|
|
}
|
|
|
|
int preivew_change_flag = 0;
|
|
|
|
const size_t Row = 140;
|
|
const size_t Col = 140;
|
|
|
|
#define BUFFER_SIZE Row * Col
|
|
|
|
const char* FRAME_FILE_PATH_1 = "./img1_v2.bin";
|
|
const char* FRAME_FILE_PATH_2 = "./pre_image.bin";
|
|
|
|
int previewCount = 0;
|
|
const char* GetPreviewData() {
|
|
previewCount++;
|
|
if (previewCount>3){
|
|
status = READY;
|
|
innerCallback("22222");
|
|
return NULL;
|
|
}
|
|
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;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
const char* GetDeviceInfo(DeviceInfo infoType) {
|
|
switch (infoType) {
|
|
case MEAN_TEMPERATURE:
|
|
return "28";
|
|
case VERSION:
|
|
return "6.6.06";
|
|
case DEV_OUTPATH:
|
|
return output_path;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
void StopDevice(){
|
|
CloseHandle(e1);
|
|
CloseHandle(e2);
|
|
}
|
|
#endif
|